Floats and equations have 2 LaTeX labels in pandoc 3.1.7+
jpcirrus opened this issue · 4 comments
In pandoc 3.1.7 the fix for jgm/pandoc#9022 means 2 labels are added to floats i.e.
\begin{equation}\phantomsection\label{eq:one}{
1 + 1 = 2
}\label{eq:one}\end{equation}
which causes compilation to terminate with an error raised by the amsmath
package.
And, here's what now happens to pandoc tables:
\phantomsection\label{tbl:table-02}
\begin{longtable}[]{@{}rlcl@{}}
\caption{\label{tbl:table-02}Demonstration of simple table syntax.}\tabularnewline
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule\noalign{}
\endfirsthead
\toprule\noalign{}
Right & Left & Center & Default \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
12 & 12 & 12 & 12 \\
123 & 123 & 123 & 123 \\
1 & 1 & 1 & 1 \\
\end{longtable}
And, a codelisting, where there is only one label, but \phantomsection
has been added:
\begin{codelisting}
\caption{Example Code Block}
\phantomsection\label{lst:one-bash}%
\begin{Shaded}
\begin{Highlighting}[]
\BuiltInTok{export} \VariableTok{ONE}\OperatorTok{=}\StringTok{\textquotesingle{}two\textquotesingle{}}
\end{Highlighting}
\end{Shaded}
\end{codelisting}
Here the addition of \phantomsection
causes links to navigate so that the caption is not displayed when the codelisting
float style has been changed from the default with:
\AtEndPreamble{\IfPackageLoadedTF{float}{% pandoc-crossref code listing (lol)
\ifdef{\KOMAClassName}{\floatstyle{komaabove}}{\floatstyle{plaintop}}
\restylefloat{codelisting}
\floatplacement{codelisting}{htbp}
}{}}
The issue with figures was fixed by jgm/pandoc@632e3c1
In pandoc 3.1.8 there are two changes required of pandoc-crossref
to prevent LaTeX compilation errors and log warnings:
- Equations: Don't add the
\label{ID}
. Permits compilation. - Tables: Delete/prevent the
\phantomsection\label{ID}
added by pandoc above thelongtable
environment (by removing the identifier?) to preserve the correct\cref
label name if the\label{ID}
added bypandoc-crossref
were removed. Removes log warnings about multiple labels.
Turns out, listings were also subtly broken by this. Anywho, I've pushed some fixes, will try to push a release later today or tomorrow, provided CI passes 🤞
Many thanks for this. Have just tested using the GitHub Actions Haskell CI #442 build for 5d308d1. All working great. Cheers.
Of interest, in my testing over the last few weeks I discovered that with longtable
if \label
is prefixed with \MakeLinkTarget{}
then the anchor is the same as with regular floats that respect the default hypcap=true
option of the caption
package (loaded by pandoc-crossref
). This macro has been included in the hyperref
package since release 7.00o
of 2022-05-15, and is documented in hyperref-linktarget.pdf
. Not sure if you would consider it worthwhile adding that, which I have been using in a lua filter run after pandoc-crossref
.
The release is live. As for \MakeLinkTarget{}
thing, I don't have the bandwidth to investigate it in any detail, so I've opted not to fit it into this release, but I've opened a new issue (#406).
I encourage you to comment on that issue with any additional context, i.e. what is the exact issue it's supposed to fix and how it does that. I'm afraid my LaTeX-fu is quite rusty, so I don't remember what hypcap
does, and it's the first time I've encountered MakeLinkTarget
.