git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Avoid problem with footnotes in unnumbered headers.

Closes #940. Added test case.

commit441a7aebf8c141612203d1cab0032f8c55e536ed authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 16 Aug 2013, 13:02 (13 years ago) parentab8c0dc
2 files changed+13−6
src/Text/Pandoc/Writers/LaTeX.hs+7−6 tests/Tests/Writers/LaTeX.hs+6
src/Text/Pandoc/Writers/LaTeX.hs+7−6
@@ -498,14 +498,15 @@ sectionHeader unnumbered ref level lst = do
498498 let noNote (Note _) = Str ""
499499 noNote x = x
500500 let lstNoNotes = walk noNote lst
501+ txtNoNotes <- inlineListToLaTeX lstNoNotes
501502 let star = if unnumbered then text "*" else empty
502− -- footnotes in sections don't work unless you specify an optional
503− -- argument: \section[mysec]{mysec\footnote{blah}}
504− optional <- if lstNoNotes == lst
503+ -- footnotes in sections don't work (except for starred variants)
504+ -- unless you specify an optional argument:
505+ -- \section[mysec]{mysec\footnote{blah}}
506+ optional <- if unnumbered || lstNoNotes == lst
505507 then return empty
506508 else do
507− res <- inlineListToLaTeX lstNoNotes
508− return $ char '[' <> res <> char ']'
509+ return $ brackets txtNoNotes
509510 let stuffing = star <> optional <> braces txt
510511 book <- gets stBook
511512 opts <- gets stOptions
@@ -536,7 +537,7 @@ sectionHeader unnumbered ref level lst = do
536537 $$ if unnumbered
537538 then "\\addcontentsline{toc}" <>
538539 braces (text sectionType) <>
539− braces txt
540+ braces txtNoNotes
540541 else empty
541542
542543-- | Convert list of inline elements to LaTeX.
tests/Tests/Writers/LaTeX.hs+6
@@ -36,4 +36,10 @@ tests = [ testGroup "code blocks"
3636 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
3737 "$\\sigma|_{\\{x\\}}$"
3838 ]
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+ ]
3945 ]