aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-06-05 16:07:36 -0700
committerJohn MacFarlane <[email protected]>2023-06-05 16:07:36 -0700
commit2c8de4c12939d8f9c0df0950e1f16fdccb1d86e6 (patch)
tree0e1e22d4ddf71cb01574ec8cff697606198427dd
parent5539eecd0bac048494a551b3da17f33d9b11c069 (diff)
Typst writer: use `#footnote` for notes.
Closes #8893.
-rw-r--r--data/templates/default.typst10
-rw-r--r--src/Text/Pandoc/Writers/Typst.hs21
-rw-r--r--test/writer.typst47
3 files changed, 17 insertions, 61 deletions
diff --git a/data/templates/default.typst b/data/templates/default.typst
index 94a9c88fb..67cbaf4f1 100644
--- a/data/templates/default.typst
+++ b/data/templates/default.typst
@@ -82,16 +82,6 @@ $endif$
$body$
-$if(notes)$
-#v(1em)
-#block[
-#horizontalrule
-#set text(size: .88em)
-#v(3pt) // otherwise first note marker is swallowed, bug?
-
-$notes$
-]
-$endif$
$if(citations)$
$if(bibliographystyle)$
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs
index a3267f911..091911518 100644
--- a/src/Text/Pandoc/Writers/Typst.hs
+++ b/src/Text/Pandoc/Writers/Typst.hs
@@ -43,8 +43,7 @@ writeTypst :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeTypst options document =
evalStateT (pandocToTypst options document)
WriterState{ stOptions = options,
- stEscapeContext = NormalContext,
- stNotes = [] }
+ stEscapeContext = NormalContext }
data EscapeContext = NormalContext | TermContext
deriving (Show, Eq)
@@ -52,9 +51,7 @@ data EscapeContext = NormalContext | TermContext
data WriterState =
WriterState {
stOptions :: WriterOptions,
- stEscapeContext :: EscapeContext,
- stNotes :: [Doc Text]
- }
+ stEscapeContext :: EscapeContext }
type TW m = StateT WriterState m
@@ -69,14 +66,7 @@ pandocToTypst options (Pandoc meta blocks) = do
(fmap chomp . inlinesToTypst)
meta
main <- blocksToTypst blocks
- noteContents <- reverse <$> gets stNotes
- let notes = vsep $ zipWith
- (\(num :: Int) cont ->
- "#endnote" <> parens (brackets (text (show num))
- <> ", " <> brackets (chomp cont <> cr)))
- [1..] noteContents
let context = defField "body" main
- $ defField "notes" notes
$ defField "toc" (writerTableOfContents options)
$ (if isEnabled Ext_citations options
then defField "citations" True
@@ -291,12 +281,9 @@ inlineToTypst inline =
let height' = maybe mempty ((", height: " <>) . literal) $
lookup "height" kvs
return $ "#image(" <> doubleQuoted src <> width' <> height' <> ")"
- Note blocks -> do -- currently typst has no footnotes!
- -- TODO create endnotes with manual typesetting
+ Note blocks -> do
contents <- blocksToTypst blocks
- modify $ \st -> st{ stNotes = contents : stNotes st }
- num <- text . show . length <$> gets stNotes
- return $ "#super" <> brackets num
+ return $ "#footnote" <> brackets (chomp contents)
textstyle :: PandocMonad m => Doc Text -> [Inline] -> TW m (Doc Text)
textstyle s inlines = (s <>) . brackets <$> inlinesToTypst inlines
diff --git a/test/writer.typst b/test/writer.typst
index 37a17128b..77deb5e24 100644
--- a/test/writer.typst
+++ b/test/writer.typst
@@ -774,29 +774,9 @@ Here is a movie #image("movie.jpg") icon.
= Footnotes
<footnotes>
-Here is a footnote reference,#super[1] and another.#super[2] This should
-#emph[not] be a footnote reference, because it contains a space.\[^my note\]
-Here is an inline note.#super[3]
-
-#blockquote[
-Notes can go in quotes.#super[4]
-]
-
-+ And in list items.#super[5]
-
-This paragraph should not be part of the note, as it is not indented.
-
-#v(1em)
-#block[
-#horizontalrule
-#set text(size: .88em)
-#v(3pt) // otherwise first note marker is swallowed, bug?
-
-#endnote([1], [Here is the footnote. It can go anywhere after the footnote
-reference. It need not be placed at the end of the document.
-])
-
-#endnote([2], [Here’s the long note. This one contains multiple blocks.
+Here is a footnote reference,#footnote[Here is the footnote. It can go anywhere
+after the footnote reference. It need not be placed at the end of the document.]
+and another.#footnote[Here’s the long note. This one contains multiple blocks.
Subsequent blocks are indented to show that they belong to the footnote (as with
list items).
@@ -806,17 +786,16 @@ list items).
```
If you want, you can indent every line, but you can also be lazy and just indent
-the first line of each block.
-])
-
-#endnote([3], [This is #emph[easier] to type. Inline notes may contain
+the first line of each block.] This should #emph[not] be a footnote reference,
+because it contains a space.\[^my note\] Here is an inline note.#footnote[This
+is #emph[easier] to type. Inline notes may contain
#link("http://google.com")[links] and `]` verbatim characters, as well as
-\[bracketed text\].
-])
-
-#endnote([4], [In quote.
-])
+\[bracketed text\].]
-#endnote([5], [In list.
-])
+#blockquote[
+Notes can go in quotes.#footnote[In quote.]
]
+
++ And in list items.#footnote[In list.]
+
+This paragraph should not be part of the note, as it is not indented.