git.iko.soy/typeable/pandoc
on master help sign in
Fix definition lists with internal links in terms (closes #1032).
e63aafdJohn MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+8−1
@@ -513,8 +513,15 @@ listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
513defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
513defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
514defListItemToLaTeX (term, defs) = do
514defListItemToLaTeX (term, defs) = do
515 term' <- inlineListToLaTeX term
515 term' <- inlineListToLaTeX term
516+ -- put braces around term if it contains an internal link,
517+ -- since otherwise we get bad bracket interactions: \item[\hyperref[..]
518+ let isInternalLink (Link _ ('#':_,_)) = True
519+ isInternalLink _ = False
520+ let term'' = if any isInternalLink term
521+ then braces term'
522+ else term'
516 def' <- liftM vsep $ mapM blockListToLaTeX defs
523 def' <- liftM vsep $ mapM blockListToLaTeX defs
517− return $ "\\item" <> brackets term' $$ def'
524+ return $ "\\item" <> brackets term'' $$ def'
518
525
519-- | Craft the section header, inserting the secton reference, if supplied.
526-- | Craft the section header, inserting the secton reference, if supplied.
520sectionHeader :: Bool -- True for unnumbered
527sectionHeader :: Bool -- True for unnumbered
tests/Tests/Writers/LaTeX.hs+5
@@ -39,6 +39,11 @@ tests = [ testGroup "code blocks"
39 , test latexListing "no identifier" $ codeBlock "hi" =?>
39 , test latexListing "no identifier" $ codeBlock "hi" =?>
40 ("\\begin{lstlisting}\nhi\n\\end{lstlisting}" :: String)
40 ("\\begin{lstlisting}\nhi\n\\end{lstlisting}" :: String)
41 ]
41 ]
42+ , testGroup "definition lists"
43+ [ "with internal link" =: definitionList [(link "#go" "" (str "testing"),
44+ [plain (text "hi there")])] =?>
45+ "\\begin{description}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item[{\\hyperref[go]{testing}}]\nhi there\n\\end{description}"
46+ ]
42 , testGroup "math"
47 , testGroup "math"
43 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
48 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
44 "$\\sigma|_{\\{x\\}}$"
49 "$\\sigma|_{\\{x\\}}$"