-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Explain the problem.
Minimal reproducible example (boiled down from the "smallcaps headings" example in Typst's official docs) showing that heading show rules given text processing functions directly don't work in Pandoc:
bug.typ:
#show heading: smallcaps
= IntroductionRunning e.g. pandoc -o bug.md bug.typ on this yields:
unexpected Elt {eltName = Identifier "heading", eltPos = Just "bug.typ" (line 1, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "bug.typ" (line 1, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "Introduction"]))]}])),(Identifier "level",VInteger 1)]} or Elt {eltName = Identifier "smallcaps", eltPos = Just "bug.typ" (line 1, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "heading", eltPos = Just "bug.typ" (line 1, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Elt {eltName = Identifier "text", eltPos = Just "bug.typ" (line 1, column 2), eltFields = fromList [(Identifier "body",VContent (fromList [Txt "Introduction"]))]}])),(Identifier "level",VInteger 1)]}]))]}
expecting end of input
But it compiles fine with typst compile bug.typ (using Typst 0.13.1), producing a heading in small capitals as we wanted:
It's not limited to usage of smallcaps specifically but happens with most functions that operate on text. For some of them, there is no error and Pandoc appears to run fine, but then produces no actual heading in the output. For only one of them it works completely fine. Here are all the text functions grouped by into which of these categories they fall (all of them work fine when compiling with Typst itself, of course):
| ❌ Error | 0️⃣ No heading in output | ✔️ Works fine |
|---|---|---|
|
|
|
Pandoc version?
3.7.0.2, Debian Linux 12
Workaround
Until this is fixed, you can work around it by instead using a function for the show rule that reconstructs the heading from its fields while applying the transformation to the body only. Unfortunately, this causes infinite recursion when compiled with Typst itself, so you also have to use something like the "stop-recursion label trick" to make it work fine there, which will add pointless labels to your headings. E.g. for smallcaps (and only reconstructing the body and level - you might want to add more fields depending on your specific case):
#show heading: it => {
if it.has("label") and it.label == <heading-stop-recursion> {
it
} else [
#heading(level: it.level, smallcaps(it.body)) <heading-stop-recursion>
]
}
= Introduction