From fb14bd7a025b938588967b7adfe934e9ff6c122c Mon Sep 17 00:00:00 2001 From: Bastien Dumont Date: Sun, 7 Dec 2025 21:15:35 +0100 Subject: [PATCH] The span id is attached to the note whenever possible --- margin-notes/README.md | 3 +++ margin-notes/margin-notes.lua | 21 +++++++++++++++++---- margin-notes/sample.md | 1 + margin-notes/test/sample.native | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/margin-notes/README.md b/margin-notes/README.md index d4b45a1..4e11f3b 100644 --- a/margin-notes/README.md +++ b/margin-notes/README.md @@ -29,6 +29,7 @@ The preceding configuration can be applied to the following sample: [BibTeX]{.term lem=BibTeX def="A program designed to format bibliographical entries" + #bibtex } citations. Note that in LaTeX environments, the material between the begin and end tags will be interpreted as [raw LaTeX]{.term @@ -37,6 +38,8 @@ 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. + 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`: ``` yaml diff --git a/margin-notes/margin-notes.lua b/margin-notes/margin-notes.lua index 8d47bc2..68f88e1 100644 --- a/margin-notes/margin-notes.lua +++ b/margin-notes/margin-notes.lua @@ -491,13 +491,22 @@ end local i_invocation = 0 -local function wrap_in_raw_note_code(content, class_name) +local function wrap_in_raw_note_code(content, class_name, id) -- content is a List of Inlines (output of replace_placeholders) local margin_note = content if FORMAT == 'context' or FORMAT == 'latex' then local csname = config[class_name].csname or 'mrgnn' - insert_in_table(margin_note, 1, pandoc.RawInline(FORMAT, '\\' .. csname .. '{')) - insert_in_table(margin_note, pandoc.RawInline(FORMAT, '}')) + local before = '\\' .. csname + if id ~= '' and FORMAT == 'context' then + before = before .. '[' .. id .. ']' + end + before = before .. '{' + if id ~= '' and FORMAT == 'latex' then + before = before .. '\\label{' .. id .. '}' + end + local after = '}' + insert_in_table(margin_note, 1, pandoc.RawInline(FORMAT, before)) + insert_in_table(margin_note, pandoc.RawInline(FORMAT, after)) elseif FORMAT == 'openxml' then i_invocation = i_invocation + 1 local bookmark_id = 'mrgnn_' .. i_invocation @@ -531,11 +540,12 @@ local function render_margin_notes(span) local render_note = config[class_name].render.note local render_body = config[class_name].render.body local note_position = config[class_name].position + local note_id = span.identifier local margin_note = {} local body = {} if render_note then margin_note = wrap_in_raw_note_code( - render_note(span.content, span.attributes), class_name) + render_note(span.content, span.attributes), class_name, note_id) end if render_body then body = render_body(span.content, span.attributes) @@ -553,6 +563,9 @@ local function render_margin_notes(span) 'the margin-note class "' .. class_name '". ' .. 'Expected "before" or "after".') end + if FORMAT == 'context' or FORMAT == 'latex' then + span.identifier = '' -- The id is attached to the note. + end return span_with_note end end diff --git a/margin-notes/sample.md b/margin-notes/sample.md index d718332..b1cd535 100644 --- a/margin-notes/sample.md +++ b/margin-notes/sample.md @@ -14,6 +14,7 @@ mrgnn-define-renderings: [BibTeX]{.term lem=BibTeX def="A program designed to format bibliographical entries" + #bibtex } citations. Note that in LaTeX environments, the material between the begin and end tags will be interpreted as [raw LaTeX]{.term diff --git a/margin-notes/test/sample.native b/margin-notes/test/sample.native index 712299d..3f2f45c 100644 --- a/margin-notes/test/sample.native +++ b/margin-notes/test/sample.native @@ -14,7 +14,7 @@ , Str "include" , SoftBreak , Span - ( "" + ( "bibtex" , [ "term" ] , [ ( "lem" , "BibTeX" ) , ( "def"