Skip to content

Commit

Permalink
LaTeX writer: Fix unnumbered headers when used with --top-level
Browse files Browse the repository at this point in the history
Fix interaction of top-level divisions `part` or `chapter` with
unnumbered headers when emitting LaTeX.  Headers are ensured to be
written using stared commands (like `\subsection*{}`).

Fixes: #3272
  • Loading branch information
tarleb committed Dec 4, 2016
1 parent 85e8afe commit bfa734c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Text/Pandoc/Writers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ sectionHeader unnumbered ident level lst = do
-- see http://tex.stackexchange.com/questions/169830/
else empty
lab <- labelFor ident
let star = if unnumbered && level < 4 then text "*" else empty
let star = if unnumbered && level' < 4 then text "*" else empty
let stuffing = star <> optional <> contents
stuffing' <- hypertarget ident $ text ('\\':sectionType) <> stuffing <> lab
return $ if level' > 5
Expand Down
22 changes: 22 additions & 0 deletions tests/Tests/Writers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,28 @@ tests = [ testGroup "code blocks"
, "\\subsection{header2}\n"
, "\\subsubsection{header3}"
]
, test (latexTopLevelDiv TopLevelPart)
"part top-level, section not in toc" $
( headerWith ("", ["unnumbered"], []) 1 (text "header1")
<> headerWith ("", ["unnumbered"], []) 2 (text "header2")
<> headerWith ("", ["unnumbered"], []) 3 (text "header3")
<> headerWith ("", ["unnumbered"], []) 4 (text "header4")
<> headerWith ("", ["unnumbered"], []) 5 (text "header5")
<> headerWith ("", ["unnumbered"], []) 6 (text "header6"))
=?>
unlines [ "\\part*{header1}"
, "\\addcontentsline{toc}{part}{header1}\n"
, "\\chapter*{header2}"
, "\\addcontentsline{toc}{chapter}{header2}\n"
, "\\section*{header3}"
, "\\addcontentsline{toc}{section}{header3}\n"
, "\\subsection*{header4}"
, "\\addcontentsline{toc}{subsection}{header4}\n"
, "\\subsubsection*{header5}"
, "\\addcontentsline{toc}{subsubsection}{header5}\n"
, "\\paragraph{header6}"
, "\\addcontentsline{toc}{paragraph}{header6}"
]
]
]
]

0 comments on commit bfa734c

Please sign in to comment.