How to manually correct the format of bibliography (for ~60% styles)?

Typst still has a considerable gap from fully supporting CSL.

Can I correct the format of a certain bibliography entry by myself?

I am going to answer it myself. But if you have better solution, feel free to add. I will select the best solution as the answer tomorrow.

1 Like

Today I inspect modern-nju-thesis 0.4.0 – Typst Universe, and learn that bibliography becomes a grid.

As a result, show grid.cell.where(x: 1, y: cite-number - 1): … would rewrite the entry.

// Tested against typst v0.13.1
#show bibliography: it => {
  set grid(stroke: gray)
  show grid.cell.where(x: 1, y: 0): set text(red, weight: "bold")
  show grid.cell.where(x: 1, y: 0): "Whatever! just write what you want."
  it
}

#bibliography("ref.bib")

Usually, the style of the bibliography is checked only after the main text is completed, by which time the citation numbers have already been determined. So no need to hack further.

Besides, citegeist – Typst Universe is capable of parsing *.bib into dict. The package uses the wasm compiled from GitHub - typst/biblatex: A Rust crate for parsing and writing BibTeX and BibLaTeX files. (I haven’t used it before, however.)

1 Like

There is one thing to complicate it a little bit - whether bibliography uses a grid or not depends on the style used(!)

One example is the style apa which does not use a grid.

Bibliography test code
#set grid(stroke: 1pt + gray)
#bibliography(full: true, style: "apa", bytes(```
@misc{CitekeyMisc,
  title        = "Pluto: The 'Other' Red Planet",
  author       = "{NASA}",
  howpublished = "\url{https://www.nasa.gov/nh/pluto-the-other-red-planet}",
  year         = 2015,
  note         = "Accessed: 2018-12-06"
}
@book{CitekeyBook,
  author    = "Leonard Susskind and George Hrabovsky",
  title     = "Classical mechanics: the theoretical minimum",
  publisher = "Penguin Random House",
  address   = "New York, NY",
  year      = 2014
}
@article{CitekeyArticle,
  author   = "P. J. Cohen",
  title    = "The independence of the continuum hypothesis",
  journal  = "Proceedings of the National Academy of Sciences",
  year     = 1963,
  volume   = "50",
  number   = "6",
  pages    = "1143--1148",
}
@inbook{CitekeyInbook,
  author    = "Lisa A. Urry and Michael L. Cain and Steven A. Wasserman and Peter V. Minorsky and Jane B. Reece",
  title     = "Photosynthesis",
  booktitle = "Campbell Biology",
  year      = "2016",
  publisher = "Pearson",
  address   = "New York, NY",
  pages     = "187--221"
}
```.text))

(Included test code just because I wanted to have some inline bib example for a MWE, examples from Complete list of BibTeX entry types [with examples] - BibTeX.com )

1 Like

whether bibliography uses a grid or not depends on the style used(!)

Good catch. It looks like ~40% style don’t use grid.

Table of styles and whether they use grid
Style Use grid?
american-anthropological-association :white_check_mark:
american-chemical-society :white_check_mark:
american-geophysical-union :x:
american-institute-of-aeronautics-and-astronautics :white_check_mark:
american-institute-of-physics :x:
american-medical-association :white_check_mark:
american-meteorological-society :x:
american-physics-society :white_check_mark:
american-physiological-society :white_check_mark:
american-political-science-association :x:
american-psychological-association :x:
american-society-for-microbiology :white_check_mark:
american-society-of-civil-engineers :x:
american-society-of-mechanical-engineers :white_check_mark:
american-sociological-association :x:
angewandte-chemie :white_check_mark:
annual-reviews :white_check_mark:
annual-reviews-author-date :x:
associacao-brasileira-de-normas-tecnicas :x:
association-for-computing-machinery :white_check_mark:
biomed-central :x:
bristol-university-press :x:
british-medical-journal :white_check_mark:
cell :white_check_mark:
chicago-author-date :x:
chicago-fullnotes :x:
chicago-notes :x:
copernicus :x:
council-of-science-editors :white_check_mark:
council-of-science-editors-author-date :x:
current-opinion :white_check_mark:
deutsche-gesellschaft-für-psychologie :x:
deutsche-sprache :x:
elsevier-harvard :x:
elsevier-vancouver :white_check_mark:
elsevier-with-titles :white_check_mark:
frontiers :x:
future-medicine :white_check_mark:
future-science :white_check_mark:
gb-7714-2005-numeric :white_check_mark:
gb-7714-2015-author-date :x:
gb-7714-2015-note :white_check_mark:
gb-7714-2015-numeric :white_check_mark:
gost-r-705-2008-numeric :white_check_mark:
harvard-cite-them-right :x:
institute-of-electrical-and-electronics-engineers :white_check_mark:
institute-of-physics-numeric :white_check_mark:
iso-690-author-date :x:
iso-690-numeric :white_check_mark:
karger :white_check_mark:
mary-ann-liebert-vancouver :white_check_mark:
modern-humanities-research-association :x:
modern-language-association :x:
modern-language-association-8 :x:
multidisciplinary-digital-publishing-institute :white_check_mark:
nature :white_check_mark:
pensoft :x:
public-library-of-science :white_check_mark:
royal-society-of-chemistry :white_check_mark:
sage-vancouver :white_check_mark:
sist02 :white_check_mark:
spie :white_check_mark:
springer-basic :white_check_mark:
springer-basic-author-date :x:
springer-fachzeitschriften-medizin-psychologie :white_check_mark:
springer-humanities-author-date :x:
springer-lecture-notes-in-computer-science :white_check_mark:
springer-mathphys :white_check_mark:
springer-socpsych-author-date :x:
springer-vancouver :x:
taylor-and-francis-chicago-author-date :x:
taylor-and-francis-national-library-of-medicine :white_check_mark:
the-institution-of-engineering-and-technology :white_check_mark:
the-lancet :white_check_mark:
thieme :white_check_mark:
trends :white_check_mark:
turabian-author-date :x:
turabian-fullnote-8 :x:
vancouver :white_check_mark:
vancouver-superscript :white_check_mark:
Python script
from subprocess import run

# Copied from https://typst.app/docs/reference/model/bibliography/#parameters-style
STYLES = """
american-anthropological-association
american-chemical-society
american-geophysical-union
american-institute-of-aeronautics-and-astronautics
american-institute-of-physics
american-medical-association
american-meteorological-society
american-physics-society
american-physiological-society
american-political-science-association
american-psychological-association
american-society-for-microbiology
american-society-of-civil-engineers
american-society-of-mechanical-engineers
american-sociological-association
angewandte-chemie
annual-reviews
annual-reviews-author-date
associacao-brasileira-de-normas-tecnicas
association-for-computing-machinery
biomed-central
bristol-university-press
british-medical-journal
cell
chicago-author-date
chicago-fullnotes
chicago-notes
copernicus
council-of-science-editors
council-of-science-editors-author-date
current-opinion
deutsche-gesellschaft-für-psychologie
deutsche-sprache
elsevier-harvard
elsevier-vancouver
elsevier-with-titles
frontiers
future-medicine
future-science
gb-7714-2005-numeric
gb-7714-2015-author-date
gb-7714-2015-note
gb-7714-2015-numeric
gost-r-705-2008-numeric
harvard-cite-them-right
institute-of-electrical-and-electronics-engineers
institute-of-physics-numeric
iso-690-author-date
iso-690-numeric
karger
mary-ann-liebert-vancouver
modern-humanities-research-association
modern-language-association
modern-language-association-8
multidisciplinary-digital-publishing-institute
nature
pensoft
public-library-of-science
royal-society-of-chemistry
sage-vancouver
sist02
spie
springer-basic
springer-basic-author-date
springer-fachzeitschriften-medizin-psychologie
springer-humanities-author-date
springer-lecture-notes-in-computer-science
springer-mathphys
springer-socpsych-author-date
springer-vancouver
taylor-and-francis-chicago-author-date
taylor-and-francis-national-library-of-medicine
the-institution-of-engineering-and-technology
the-lancet
thieme
trends
turabian-author-date
turabian-fullnote-8
vancouver
vancouver-superscript
""".strip().splitlines()


def if_use_grid(style: str) -> bool:
    result = run(
        ["typst", "compile", "-", "-", "--format=svg", "--input", f"style={style}"],
        input=r"""
        #set grid(stroke: rgb("#caffee"))
        #bibliography(
          style: sys.inputs.at("style"),
          full: true,
          bytes(
                ```bib
                @misc{CitekeyMisc,
                title        = "Pluto: The 'Other' Red Planet",
                author       = "{NASA}",
                howpublished = "\url{https://www.nasa.gov/nh/pluto-the-other-red-planet}",
                year         = 2015,
                note         = "Accessed: 2018-12-06"
            }
            ```.text,
          ),
        )
        """,
        text=True,
        check=True,
        capture_output=True,
    )
    return 'stroke="#caffee"' in result.stdout


print("| Style | Use grid? |")
print("|--|:--:|")
for style in STYLES:
    use = if_use_grid(style)
    print(f"|{style}|{'✅' if use else '❌'}|")