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

Latex: allow phantomsection in captions #10688

Merged
merged 1 commit into from
Mar 15, 2025

Conversation

etclub
Copy link
Contributor

@etclub etclub commented Mar 14, 2025

@jgm
Copy link
Owner

jgm commented Mar 15, 2025

If you want this PR to be considered, please explain in words what it is doing and why.
A link to a huge discussion isn't enough. The explanation should also go in the commit message.

@etclub
Copy link
Contributor Author

etclub commented Mar 15, 2025

If you want this PR to be considered, please explain in words what it is doing and why. A link to a huge discussion isn't enough. The explanation should also go in the commit message.

I find the following html

<table>
<caption>...<span id="test">test</span>...</caption>
...

would result in latex a \phantomsection in caption, which causes an error.
And the link above gives a solution.

@jgm
Copy link
Owner

jgm commented Mar 15, 2025

Complete example:

<table>
<caption>...<span id="test">test</span>...</caption>
<tr><td>A</td><td>b</td></tr>
</table>

gets converted to

\begin{longtable}[]{@{}ll@{}}
\caption{...\phantomsection\label{test}{test}...}\tabularnewline
\toprule\noalign{}
\endfirsthead
\endhead
\bottomrule\noalign{}
\endlastfoot
A & b \\
\end{longtable}

and compiling this produces the LaTeX error

! Undefined control sequence.
\Hy@MakeCurrentHref ...def \HyperLocalCurrentHref 
                                                  {#1}\@onelevel@sanitize \H...
l.65 ...n{...\phantomsection\label{test}{test}...}

Adding \protect before \phantomsection makes this error go away.

What isn't clear to me is whether there would be any drawbacks if we add \protect before \phantomsection in every context (not just inside a caption).

@jgm
Copy link
Owner

jgm commented Mar 15, 2025

It seems to work in my tests with \protect in every context, so I think we can do this.

@jgm jgm merged commit 915e367 into jgm:main Mar 15, 2025
0 of 14 checks passed
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

Successfully merging this pull request may close these issues.

2 participants