jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.72k stars 3.33k forks source link

Citations do not work with Typst writer #8763

Closed benjamineskola closed 1 year ago

benjamineskola commented 1 year ago

Explain the problem. I'm trying to generate a PDF, including citations, using as minimal a change as possible from pdf-engine: latex to pdf-engine: typst. When simply changing the engine to typst failed, I tried changing the final output format to typst so I could see the output and try to make sense of the issue.

Firstly, an absolute path to the bibliography fails. If I generate with pandoc -s --bibliography "/Users/ben/Documents/Study/bibliography.yaml" … then I get a typst file containing the following:

…
#bibliography("/Users/ben/Documents/Study/bibliography.yaml")

When I tried processing this the error was as follows:

$ typst TMA04.typ
error: file not found (searched at Users/ben/Documents/Study/bibliography.yaml)
    ┌─ TMA04.typ:135:14
    │
135 │ #bibliography("/Users/ben/Documents/Study/bibliography.yaml")
    │               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note the lack of leading / in the error message: Typst seems to be stripping this and treating it as a relative path.

Passing a relative path to Pandoc (e.g. pandoc -s --bibliography=../bibliography.yaml …) seems to work — at least, it finds the bibliography file.

However this then produces the second error:

$ typst TMA04.typ
error: unknown bibliography format
    ┌─ TMA04.typ:135:14
    │
135 │ #bibliography("../bibliography.yaml")
    │               ^^^^^^^^^^^^^^^^^^^^^^

My expectation was that a citeproc yaml file would be processed by pandoc to generate the output (as with the other output formats, which as far as I know don't support citeproc). However it seems that the typst writer needs the yaml file to be in a different format (typst-specific?).

I don't know if the right thing to do is to alter Pandoc's behaviour or just to document it — I can completely understand if it's a limitation of the output format.

Pandoc version? pandoc 3.1.2 on macOS 13.3

jgm commented 1 year ago

My expectation was that a citeproc yaml file would be processed by pandoc to generate the output (as with the other output formats, which as far as I know don't support citeproc).

This is correct, if you specify --citeproc on the command line. Did you? Even if you did, I think there may be a bug; pandoc should not be passing through the bibliography to the template in this case.

jgm commented 1 year ago

With the commit I pushed, this should work: use --citeproc -t typst-citations (the latter disables native typst citations and will omit #bibliography in the template).

benjamineskola commented 1 year ago

This is correct, if you specify --citeproc on the command line. Did you?

Sorry for being unclear: I specify citeproc etc in a defaults file and left this out of my examples — the setup certainly works for me for other output formats.

Thanks for the quick response, that seems to fix it for me!

iandol commented 10 months ago

--citeproc -t typst-citations

@jgm -- this is not documented in the manual AFAICT? The extensions citations section in the manual seems a bit arbitrary for org / docx, would you want this added there or just above https://pandoc.org/MANUAL.html#other-relevant-metadata-fields in a paragraph after mentioning LaTeX?

jgm commented 10 months ago

I'm really not sure. That section only talks about the effect on readers, and in typst's case, citations always work in the reader regardless of the extension. The extension only affects the writer.

iandol commented 10 months ago

Thanks John, I suppose anywhere in the docs is better than nowhere; I only found the citations extension applied to typst by digging into issues on GitHub (here and at quarto); by the way they have a simple switch:

https://quarto.org/docs/prerelease/1.4/typst.html#bibliography

When citeproc: true then they switch to citeproc and use typst-citations under-the-hood to disable typst system. This seems cleaner and would be easier to document…

iandol commented 10 months ago

I made a pull request to add this info to the Options > --citeproc section...