+ Parse `\pandocfootnotemark{n}` and `\pandocfootnotetext{n}{..}`,
as produced by the LaTeX writer for notes in tables, captions,
etc. Marks and texts are matched by id.
+ Resolve footnote marks inside resolved footnote texts, so that
nested notes are not lost.
+ Track `\addtocounter{footnote}{n}`, so that `\footnotemark` and
`\footnotetext` with counter adjustments (as produced by earlier
versions of pandoc) are matched correctly. Previously all
of the texts were assigned to the last mark.
+ Ignore definitions of `\pandocbounded`, `\pandocfootnotemark`,
and `\pandocfootnotetext` (e.g. from pandoc's template), which
the reader handles directly. Previously these definitions were
expanded, producing garbage and losing content.
See #11936.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.4 KiB
3.4 KiB
Footnotes in tables are deferred. Each \pandocfootnotetext must
be matched to its \pandocfootnotemark, and the text of a nested
note must come after the text containing its mark.
% pandoc -f native -t latex
[ Table
( "" , [] , [] )
(Caption Nothing [])
[ ( AlignDefault , ColWidthDefault )
, ( AlignDefault , ColWidthDefault )
]
(TableHead
( "" , [] , [] )
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "A" ] ]
, Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "B" ] ]
]
])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain
[ Str "x"
, Note
[ Para
[ Str "outer"
, Space
, Note [ Para [ Str "inner note" ] ]
]
]
]
]
, Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Plain [ Str "y" , Note [ Para [ Str "second" ] ] ] ]
]
]
]
(TableFoot ( "" , [] , [] ) [])
]
^D
{\def\LTcaptype{none} % do not increment counter
\begin{longtable}[]{@{}ll@{}}
\toprule\noalign{}
A & B \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
x\pandocfootnotemark{2} & y\pandocfootnotemark{3} \\
\end{longtable}
}
\pandocfootnotetext{2}{outer \pandocfootnotemark{1}}
\pandocfootnotetext{1}{inner note}
\pandocfootnotetext{3}{second}
The LaTeX reader handles this output, ignoring the definitions of the macros from the template:
% pandoc -f latex -t markdown
\makeatletter
\protected\def\pandocfootnotemark#1{\footnotemark{}%
\expandafter\xdef\csname pandoc@fn@#1\endcsname{%
\noexpand\pandoc@fnrestore
{\unexpanded\expandafter{\@thefnmark}}%
{\ifdefined\Hy@footnote@currentHref
\unexpanded\expandafter{\Hy@footnote@currentHref}\fi}}}
\def\pandoc@fnrestore#1#2{%
\gdef\@thefnmark{#1}%
\ifdefined\Hy@footnote@currentHref\gdef\Hy@footnote@currentHref{#2}\fi}
\newcommand\pandocfootnotetext[1]{%
\csname pandoc@fn@#1\endcsname\@footnotetext}
\makeatother
\begin{tabular}{ll}
x\pandocfootnotemark{2} & y\pandocfootnotemark{3} \\
\end{tabular}
\pandocfootnotetext{2}{outer \pandocfootnotemark{1}}
\pandocfootnotetext{1}{inner note}
\pandocfootnotetext{3}{second}
^D
------- -------
x[^1] y[^2]
------- -------
[^1]: outer [^3]
[^2]: second
[^3]: inner note
It also handles adjustments to the footnote counter with
\footnotemark and \footnotetext, as in output from
earlier versions of pandoc:
% pandoc -f latex -t markdown
\begin{tabular}{ll}
x\footnotemark{} & y\footnotemark{} \\
\end{tabular}
\addtocounter{footnote}{-1}
\footnotetext{first}
\addtocounter{footnote}{1}
\footnotetext{second}
^D
------- -------
x[^1] y[^2]
------- -------
[^1]: first
[^2]: second