Files
pandoc/test/command/1023.md
T
John MacFarlaneandClaude Opus 5.5 5bca190d12 LaTeX writer: fix hyperlinks for deferred footnotes.
Notes in tables, captions, and definition list terms are rendered
as a mark followed later by the note text. Previously we used
`\footnotemark{}` and `\footnotetext` with manual adjustments to
the footnote counter. But hyperref anchors each `\footnotetext` at
the destination of the most recent `\footnotemark`, so when there
were several such notes, all of the texts got the last mark's
anchor and the links for the other marks were broken (visibly so
with xelatex; pdflatex and lualatex silently substituted
page-level destinations).

We now emit `\pandocfootnotemark{n}` and `\pandocfootnotetext{n}{..}`,
where `n` is a unique id. These macros, defined in the default
template when the `deferred-notes` variable is set, save the
footnote mark and hyperref anchor at the mark and restore them
at the text. This removes the need for counter arithmetic, works
when the footnote counter is reset by chapter, and handles notes
nested inside deferred notes (whose texts are now emitted after
the text containing their marks). Since `\@footnotetext` is used
directly, verbatim content in such notes (`\VerbatimFootnotes`)
still works.

Users of custom LaTeX templates, or of LaTeX fragments produced
without `--standalone`, will need to include the definitions of
`\pandocfootnotemark` and `\pandocfootnotetext` from the default
template.

Closes #11936.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 20:13:38 -08:00

4.6 KiB

% pandoc -t latex
:  Here's the caption.
It may span multiple lines. {.float #ident latex-placement="ht"}

---------------------------------------------------------------
 Centered   Left             Right
  Header    Aligned        Aligned  Default aligned
----------  ---------  -----------  ---------------------------
   First    row               12.0  Example of a row that spans
                                    multiple lines.

   Second   row                5.0  Here's another one.  Note
                                    the blank line between rows.
---------------------------------------------------------------
^D
\begin{table}[ht]
\centering
\caption{Here's the caption. It may span multiple
lines.}\label{ident}\tabularnewline
\begin{tabular}{@{}
  >{\centering\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1667}}
  >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1528}}
  >{\raggedleft\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.1806}}
  >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.3889}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Centered Header
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Left Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedleft
Right Aligned
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Default aligned
\end{minipage} \\
\midrule\noalign{}
First & row & 12.0 & Example of a row that spans multiple lines. \\
Second & row & 5.0 & Here's another one. Note the blank line between
rows. \\
\bottomrule\noalign{}
\end{tabular}
\end{table}

% pandoc -t latex
: Simple table with no column headers {.float #ident}

-------     ------ ----------   -------
     12     12        12             12
    123     123       123           123
      1     1          1              1
-------     ------ ----------   -------
^D
\begin{table}[]
\centering
\caption{Simple table with no column
headers}\label{ident}\tabularnewline
\begin{tabular}{@{}rlcr@{}}
\toprule\noalign{}
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\
\bottomrule\noalign{}
\end{tabular}
\end{table}

% pandoc -t latex
+--------------------+---------------------+---------------+---------------+
| Name^[In English.] | Capital             | Population\   | Area\         |
|                    |                     | (in 2018)     | (in km^2^)    |
+:==================:+:====================+:==============+:==============+
| Denmark            | Copenhagen          | 5,809,502     | 43,094        |
+--------------------+---------------------+---------------+---------------+
| Finland            | Helsinki            | 5,537,364     | 338,145       |
+--------------------+---------------------+---------------+---------------+
| Iceland^[Brrr.]    | Reykjavik           | 343,518       | 103,000       |
+--------------------+---------------------+---------------+---------------+
| Norway             | Oslo                | 5,372,191     | 323,802       |
+--------------------+---------------------+---------------+---------------+
| Sweden             | Stockholm           | 10,313,447    | 450,295       |
+====================+=====================+===============+===============+
| Total              |                     | 27,376,022    | 1,258,336     |
+====================+=====================+===============+===============+

: States belonging to the *Nordics.* {#nordics source="wikipedia" .float}
^D
\begin{table}[]
\centering
\caption{States belonging to the
\emph{Nordics.}}\label{nordics}\tabularnewline
\begin{tabular}{@{}
  >{\centering\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2727}}
  >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2857}}
  >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2078}}
  >{\raggedright\arraybackslash}p{(\linewidth - 6\tabcolsep) * \real{0.2078}}@{}}
\toprule\noalign{}
\begin{minipage}[b]{\linewidth}\centering
Name\pandocfootnotemark{1}
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Capital
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Population\\
(in 2018)\strut
\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright
Area\\
(in km\textsuperscript{2})\strut
\end{minipage} \\
\midrule\noalign{}
Denmark & Copenhagen & 5,809,502 & 43,094 \\
Finland & Helsinki & 5,537,364 & 338,145 \\
Iceland\pandocfootnotemark{2} & Reykjavik & 343,518 & 103,000 \\
Norway & Oslo & 5,372,191 & 323,802 \\
Sweden & Stockholm & 10,313,447 & 450,295 \\
\midrule\noalign{}
Total & & 27,376,022 & 1,258,336 \\
\bottomrule\noalign{}
\end{tabular}
\end{table}
\pandocfootnotetext{1}{In English.}
\pandocfootnotetext{2}{Brrr.}