git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Avoid problem with footnotes in unnumbered headers.
441a7aeJohn MacFarlane
src/Text/Pandoc/Writers/LaTeX.hs+7−6
@@ -498,14 +498,15 @@ sectionHeader unnumbered ref level lst = do
498 let noNote (Note _) = Str ""
498 let noNote (Note _) = Str ""
499 noNote x = x
499 noNote x = x
500 let lstNoNotes = walk noNote lst
500 let lstNoNotes = walk noNote lst
501+ txtNoNotes <- inlineListToLaTeX lstNoNotes
501 let star = if unnumbered then text "*" else empty
502 let star = if unnumbered then text "*" else empty
503+ -- footnotes in sections don't work (except for starred variants)
502− -- footnotes in sections don't work unless you specify an optional
504+ -- unless you specify an optional argument:
503− -- argument: \section[mysec]{mysec\footnote{blah}}
505+ -- \section[mysec]{mysec\footnote{blah}}
504− optional <- if lstNoNotes == lst
506+ optional <- if unnumbered || lstNoNotes == lst
505 then return empty
507 then return empty
506 else do
508 else do
507− res <- inlineListToLaTeX lstNoNotes
509+ return $ brackets txtNoNotes
508− return $ char '[' <> res <> char ']'
509 let stuffing = star <> optional <> braces txt
510 let stuffing = star <> optional <> braces txt
510 book <- gets stBook
511 book <- gets stBook
511 opts <- gets stOptions
512 opts <- gets stOptions
@@ -536,7 +537,7 @@ sectionHeader unnumbered ref level lst = do
536 $$ if unnumbered
537 $$ if unnumbered
537 then "\\addcontentsline{toc}" <>
538 then "\\addcontentsline{toc}" <>
538 braces (text sectionType) <>
539 braces (text sectionType) <>
539− braces txt
540+ braces txtNoNotes
540 else empty
541 else empty
541
542
542-- | Convert list of inline elements to LaTeX.
543-- | Convert list of inline elements to LaTeX.
tests/Tests/Writers/LaTeX.hs+6
@@ -36,4 +36,10 @@ tests = [ testGroup "code blocks"
36 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
36 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
37 "$\\sigma|_{\\{x\\}}$"
37 "$\\sigma|_{\\{x\\}}$"
38 ]
38 ]
39+ , testGroup "headers"
40+ [ "unnumbered header" =:
41+ headerWith ("foo",["unnumbered"],[]) 1
42+ (text "Header 1" <> note (plain $ text "note")) =?>
43+ "\\section*{Header 1\\footnote{note}}\\label{foo}\n\\addcontentsline{toc}{section}{Header 1}\n"
44+ ]
39 ]
45 ]