diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-11-22 23:24:55 -0500 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-11-22 23:24:55 -0500 |
| commit | a2a0f73eb816917839eeffad9e487394ebd88443 (patch) | |
| tree | 33814c81d4596645ecd18fa254b5a31aabd059c6 | |
| parent | 49e64c1451b9933a025d059f7dae287788c7d1cc (diff) | |
LaTeX writer: handle identifiers inside heading contents.
`\phantomsection` can't be used in this case, so we need `\hypertarget`.
Closes #9209.
| -rw-r--r-- | src/Text/Pandoc/Writers/LaTeX/Util.hs | 10 | ||||
| -rw-r--r-- | test/command/9209.md | 6 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX/Util.hs b/src/Text/Pandoc/Writers/LaTeX/Util.hs index 8dcec54dd..86b95795c 100644 --- a/src/Text/Pandoc/Writers/LaTeX/Util.hs +++ b/src/Text/Pandoc/Writers/LaTeX/Util.hs @@ -260,8 +260,14 @@ wrapDiv (_,classes,kvs) t = do hypertarget :: PandocMonad m => Text -> LW m (Doc Text) hypertarget "" = return mempty hypertarget ident = do - label <- labelFor ident - return $ text "\\phantomsection" <> label + inHeading <- gets stInHeading + if inHeading + then do -- see #9209 (these cases should be rare) + ref <- literal <$> toLabel ident + return $ text "\\protect\\hypertarget" <> braces ref <> "{}" + else do + label <- labelFor ident + return $ text "\\phantomsection" <> label labelFor :: PandocMonad m => Text -> LW m (Doc Text) labelFor "" = return empty diff --git a/test/command/9209.md b/test/command/9209.md new file mode 100644 index 000000000..3cdac7f17 --- /dev/null +++ b/test/command/9209.md @@ -0,0 +1,6 @@ +``` +% pandoc -t latex +## [Section]{#Section3} +^D +\subsection{\texorpdfstring{\protect\hypertarget{Section3}{}{Section}}{Section}}\label{section} +``` |
