From f3907ff28f55ea69d76734c35c59942ae841533e Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Sun, 7 Dec 2025 21:20:23 +0100 Subject: [PATCH] Typst support --- margin-notes/README.md | 8 +++++--- margin-notes/margin-notes.lua | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/margin-notes/README.md b/margin-notes/README.md index 4e11f3b..ee96098 100644 --- a/margin-notes/README.md +++ b/margin-notes/README.md @@ -1,6 +1,6 @@ # Marginal notes in Pandoc for semantically marked spans of text -`margin-notes` enables you to create unnumbered marginal notes from spans with user-defined class and properties. It currently only works with LaTeX, ConTeXt and, to a limited extent, DOCX (using tooltips instead of marginal notes) and ODT (using annotations). +`margin-notes` enables you to create unnumbered marginal notes from spans with user-defined class and properties. It currently only works with LaTeX, ConTeXt, Typst, and, to a limited extent, DOCX (using tooltips instead of marginal notes) and ODT (using annotations). ## Defining the renderings @@ -38,7 +38,7 @@ as [raw LaTeX]{.term }, not as Markdown. ``` -In LaTeX and ConTeXt, if the span has an identifier (like `#bibtex` above), it will be used as the label of the note. +In LaTeX, ConTeXt and Typst, if the span has an identifier (like `#bibtex` above), it will be used as the label of the note. For DOCX output, the note is set as the content of a tooltip attached to an asterisk following the body text. Since this does not always produce good results, notably because tooltips only display plain strings, DOCX output is deactivated by default. However, you can activate it for individual classes by setting the variables `docx-body-text` and `docx-note-text`: @@ -121,6 +121,8 @@ By default, in LaTeX and ConTeXt, all marginal notes are rendered by the macro ` alternative=serried] ``` +In Typst, the filter uses the `#note` command provided by [marginalia](https://typst.app/universe/package/marginalia). The package has to be loaded explicitly by the user. + However, you can associate different macros/commands with individual classes by setting the variable `csname`: ``` yaml @@ -131,7 +133,7 @@ mrgnn-define-renderings: csname: mrgnnTerm ``` -In that case, you will have to define `\mrgnnTerm` in your LaTeX or ConTeXt template or via `header-includes`. This macro takes one argument, which is the result of the processing of `note-text`. +In that case, you will have to define `\mrgnnTerm` in your LaTeX or ConTeXt template or via `header-includes`. This macro takes one argument, which is the result of the processing of `note-text`. In Typst, you will similarly have to define `#mrgnnTerm[note body]`. The position of the instructions about the marginal note in the output file can be set _via_ the variable `position`. They can be placed `after` (default) or `before` the in-text content. diff --git a/margin-notes/margin-notes.lua b/margin-notes/margin-notes.lua index 68f88e1..6dc13fb 100644 --- a/margin-notes/margin-notes.lua +++ b/margin-notes/margin-notes.lua @@ -507,6 +507,13 @@ local function wrap_in_raw_note_code(content, class_name, id) local after = '}' insert_in_table(margin_note, 1, pandoc.RawInline(FORMAT, before)) insert_in_table(margin_note, pandoc.RawInline(FORMAT, after)) + elseif FORMAT == 'typst' then + local cmd = config[class_name].csname or 'note' + insert_in_table(margin_note, 1, pandoc.RawInline(FORMAT, '#' .. cmd .. '[')) + insert_in_table(margin_note, pandoc.RawInline(FORMAT, ']')) + if id ~= '' then + insert_in_table(margin_note, pandoc.RawInline(FORMAT, '<' .. id .. '>')) + end elseif FORMAT == 'openxml' then i_invocation = i_invocation + 1 local bookmark_id = 'mrgnn_' .. i_invocation @@ -563,7 +570,7 @@ local function render_margin_notes(span) 'the margin-note class "' .. class_name '". ' .. 'Expected "before" or "after".') end - if FORMAT == 'context' or FORMAT == 'latex' then + if FORMAT == 'context' or FORMAT == 'latex' or FORMAT == 'typst' then span.identifier = '' -- The id is attached to the note. end return span_with_note