Skip to content

add support for forced par-like bibliography entries - #27

Open
Andrew15-5 wants to merge 2 commits into
ensko:mainfrom
Andrew15-5:par-like
Open

add support for forced par-like bibliography entries#27
Andrew15-5 wants to merge 2 commits into
ensko:mainfrom
Andrew15-5:par-like

Conversation

@Andrew15-5

@Andrew15-5 Andrew15-5 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor

Closes #26.

I tried this with #import "@preview/alexandria:0.2.1": *, and it works perfectly.

/// generally, you'll need to ultimately render all references, or you'll get unresolved citations.
///
/// -> content
#let render-bibliography(
  /// The bibliography data
  /// -> dict
  bib,
  /// The title of the bibliography. Note that `auto` is currently not supported.
  /// -> none | content | auto
  title: auto,
  /// the way each entry is laid out. Default is `auto`, i.e., defined by the CSL style.
  /// To use grid-based `(prefix, body)` row per entry, use `false`.
  /// To use paragraph-based entries, use `true`.
  /// -> bool | auto
  par-like: auto,
) = {
  assert.ne(title, auto, message: "automatic title is not yet supported")

  if title != none {
    [= #title]
  }

  set par(hanging-indent: 1.5em) if bib.hanging-indent

  if bib.references.any(e => e.prefix != none) and par-like in (auto, false) {
    grid(
      columns: 2,
      // rows: (),
      column-gutter: 0.65em,
      // row-gutter: 13.2pt,
      row-gutter: par.spacing,
      // fill: none,
      // align: auto,
      // stroke: (:),
      // inset: (:),
      ..for e in bib.references {
        (
          {
            [#metadata(none)#label(bib.prefix + e.key)]
            if e.prefix != none {
              hayagriva.render(e.prefix)
            }
          },
          hayagriva.render(e.reference),
        )
      },
    )
  } else if bib.references.any(e => e.prefix != none) {
    let gutter = v(par.spacing, weak: true)
    for (i, e) in bib.references.enumerate() {
      if i != 0 { gutter }
      if e.prefix != none { hayagriva.render(e.prefix) + [~] }
      [#metadata(none)#label(bib.prefix + e.key)]
      hayagriva.render(e.reference)
    }
  } else {
    let gutter = v(par.spacing, weak: true)
    for (i, e) in bib.references.enumerate() {
      if i != 0 { gutter }
      [#metadata(none)#label(bib.prefix + e.key)]
      hayagriva.render(e.reference)
    }
  }
}


#context {
  pagebreak()
  set heading(numbering: none)
  let (references, ..rest) = get-bibliography("x-")
  render-bibliography(
    par-like: true,
    title: bibliography.title,
    (references: references, ..rest),
  )
}
image

@Andrew15-5 Andrew15-5 changed the title add support to forced par-like bibliography entries add support for forced par-like bibliography entries Nov 28, 2025
@Andrew15-5

Andrew15-5 commented Nov 28, 2025

Copy link
Copy Markdown
Contributor Author

Instead of

#let bibliography(sources, full: auto, style: auto, title: auto) = context {
  let read = state("__report-read").get()
  assert(
    read != none,
    message: "Apply template with `read: path => read(path)` argument",
  )
  let full = if full == auto { std.bibliography.full } else { full }
  let style = if style == auto { std.bibliography.style } else { style }
  let title = if title == auto { std.bibliography.title } else { title }
  let sources = sources
  show std.bibliography: none
  if type(sources) != array { sources = (sources,) }
  load-bibliography(sources, full: full, style: style)
  pagebreak()
  sources.map(path => pdf.attach(path, bytes(read(path)))).join()
  sources = sources.map(read).map(bytes)
  std.bibliography(sources, full: full, style: style, title: title)
  context {
    heading(numbering: none, title)
    let (references, ..rest) = get-bibliography("x-")
    let bib = (references: references, ..rest)
    let gutter = v(par.spacing, weak: true)
    for (i, e) in bib.references.enumerate() {
      if i != 0 { gutter }
      if e.prefix != none { hayagriva.render(e.prefix) + [~] }
      [#metadata(none)#label(bib.prefix + e.key)]
      hayagriva.render(e.reference)
    }
  }
}

I can do

#let bibliography(sources, full: auto, style: auto, title: auto) = context {
  let read = state("__report-read").get()
  assert(
    read != none,
    message: "Apply template with `read: path => read(path)` argument",
  )
  let full = if full == auto { std.bibliography.full } else { full }
  let style = if style == auto { std.bibliography.style } else { style }
  let title = if title == auto { std.bibliography.title } else { title }
  let sources = sources
  show std.bibliography: none
  if type(sources) != array { sources = (sources,) }
  load-bibliography(sources, full: full, style: style)
  pagebreak()
  sources.map(path => pdf.attach(path, bytes(read(path)))).join()
  sources = sources.map(read).map(bytes)
  std.bibliography(sources, full: full, style: style, title: title)
  set heading(numbering: none)
  context {
    let (references, ..rest) = get-bibliography("x-")
    render-bibliography(
      title: title,
      par-like: true,
      (references: references, ..rest),
    )
  }
}

I guess, if I also can add this to the main function, then it would be even better:

#let bibliography(sources, full: auto, style: auto, title: auto) = context {
  let read = state("__report-read").get()
  assert(
    read != none,
    message: "Apply template with `read: path => read(path)` argument",
  )
  let full = if full == auto { std.bibliography.full } else { full }
  let style = if style == auto { std.bibliography.style } else { style }
  let title = if title == auto { std.bibliography.title } else { title }
  let sources = sources
  show std.bibliography: none
  if type(sources) != array { sources = (sources,) }
  pagebreak()
  sources.map(path => pdf.attach(path, bytes(read(path)))).join()
  sources = sources.map(read).map(bytes)
  std.bibliography(sources, full: full, style: style, title: title)
  set heading(numbering: none)
  bibliographyx(sources, full: full, style: style, title: title, par-like: true)
}

And eventually, maybe even this:

#let bibliography(sources, full: auto, style: auto, title: auto) = context {
  let full = if full == auto { std.bibliography.full } else { full }
  let style = if style == auto { std.bibliography.style } else { style }
  let title = if title == auto { std.bibliography.title } else { title }
  pagebreak()
  if type(sources) != array { pdf.attach(sources) } else {
    sources.map(pdf.attach).join()
  }
  show std.bibliography: none
  std.bibliography(sources, full: full, style: style, title: title)
  set heading(numbering: none)
  bibliographyx(sources, full: full, style: style, title: title, par-like: true)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to force bibliography entries to become paragraphs instead of grid

1 participant