Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floats and equations have 2 LaTeX labels in pandoc 3.1.7+ #402

Closed
jpcirrus opened this issue Sep 1, 2023 · 4 comments
Closed

Floats and equations have 2 LaTeX labels in pandoc 3.1.7+ #402

jpcirrus opened this issue Sep 1, 2023 · 4 comments

Comments

@jpcirrus
Copy link

jpcirrus commented Sep 1, 2023

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

@jpcirrus jpcirrus changed the title codelisting has 2 LaTeX labels in pandoc 3.1.7 Floats have 2 LaTeX labels in pandoc 3.1.7 Sep 1, 2023
@jpcirrus jpcirrus changed the title Floats have 2 LaTeX labels in pandoc 3.1.7 Floats and equations have 2 LaTeX labels in pandoc 3.1.7 Sep 1, 2023
@jpcirrus jpcirrus changed the title Floats and equations have 2 LaTeX labels in pandoc 3.1.7 Floats and equations have 2 LaTeX labels in pandoc 3.1.7+ Sep 22, 2023
@jpcirrus
Copy link
Author

jpcirrus commented Sep 22, 2023

In pandoc 3.1.8 there are two changes required of pandoc-crossref to prevent LaTeX compilation errors and log warnings:

  1. Equations: Don't add the \label{ID}. Permits compilation.
  2. Tables: Delete/prevent the \phantomsection\label{ID} added by pandoc above the longtable environment (by removing the identifier?) to preserve the correct \cref label name if the \label{ID} added by pandoc-crossref were removed. Removes log warnings about multiple labels.

@lierdakil
Copy link
Owner

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 🤞

@jpcirrus
Copy link
Author

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.

@lierdakil
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants