From 6864f3e35f0ea59b884859c223e2438e86140b93 Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Tue, 23 Dec 2025 13:10:13 +0100 Subject: [PATCH] text-crossrefs: add a rule for notes in Typst and provide a way to disable --- text-crossrefs/README.md | 8 ++++++++ text-crossrefs/text-crossrefs.lua | 27 ++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/text-crossrefs/README.md b/text-crossrefs/README.md index cf17b65..1143807 100644 --- a/text-crossrefs/README.md +++ b/text-crossrefs/README.md @@ -140,6 +140,11 @@ in addition to those that the filter already inserts: #set page(supplement: []) ``` +The filter also adds a show rule for `#ref` that prints the footnote reference number +in normal script (by default, Typst handles it as a footnote anchor). +If you wish to provide your own rules instead, +you can set the metadata variable `tcrf-typst-adaptations` to `false`. + In the default mode, you can also (ab)use the `note` reference type to refer to a heading, figure or equation by its number, for the `note` reference type is mapped to the `normal` form in Typst, which is common to all these elements: @@ -372,6 +377,9 @@ In this case, the metadata fields [specific to TeX](#tex-options) will be taken Otherwise, _text-crossrefs_ will only output native `#ref` commands. In this case, the metadata fields [specific to DOCX and ODT](#docx-odt-options) will be used. +_text-crossrefs_ [adds two rules to `header-includes`](#typst) +to make `#ref` print only the reference numbers without formatting: +if you prefer to define your own rules, set `tcrf-typst-alter-ref` to false. # Compatibility with other filters diff --git a/text-crossrefs/text-crossrefs.lua b/text-crossrefs/text-crossrefs.lua index 082db03..ae1dead 100644 --- a/text-crossrefs/text-crossrefs.lua +++ b/text-crossrefs/text-crossrefs.lua @@ -92,6 +92,7 @@ local config = { filelabel_ref_separator = '::', range_delim_crossrefenum = ' to ', typst_crossrefenum = false, + typst_alter_ref = true, additional_types = {} } @@ -180,13 +181,29 @@ local function configure(metadata) end end -local function remove_prefixes_typst(metadata) - if TYPST_VARIANT:get() == 'ref' then - local label_macro_def = '\n#set page(supplement: [])\n' +local function typst_adaptations(metadata) + if TYPST_VARIANT:get() == 'ref' and config.typst_alter_ref then + local adaptations = [[ +// Suppress the “page ” prefix added by Typst by default. +#set page(supplement: []) + +// Format the reference to the footnote in normal script and hyperlink it. +// Adapted from https://github.com/typst/typst/issues/2054#issuecomment-2468251637 +#show ref: it => { + let el = it.element + if el != none and el.func() == footnote { + let loc = el.location() + let f_number = numbering(el.numbering, ..counter(footnote).at(loc)) + link(loc, [#f_number]) + } else { + it + } +} +]] if not metadata['header-includes'] then metadata['header-includes'] = pandoc.MetaBlocks(pandoc.RawBlock('typst', '')) end - metadata['header-includes']:insert(pandoc.RawBlock('typst', label_macro_def)) + metadata['header-includes']:insert(pandoc.RawBlock('typst', adaptations)) end return metadata end @@ -711,7 +728,7 @@ end return { { Meta = configure }, { Meta = support_footnote_label_ConTeXt }, - { Meta = remove_prefixes_typst }, + { Meta = typst_adaptations }, { Note = set_notelabels }, { Note = map_spans_to_notelabels }, { Span = control_label_placement },