Add --parts command line option to LaTeX writer.

Add --parts command line argument.
This only effects LaTeX writer, and only for non-beamer output formats.
It changes the output levels so the top level is 'part', the next
'chapter' and then into sections.
This commit is contained in:
Oliver Matthews 2016-09-06 21:43:45 +02:00 committed by Albert Krewinkel
parent 4a2a7a21e5
commit 23fb52ef7d
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
4 changed files with 33 additions and 10 deletions

View file

@ -667,6 +667,11 @@ Options affecting specific writers
option is implied. If `beamer` is the output format, top-level option is implied. If `beamer` is the output format, top-level
headers will become `\part{..}`. headers will become `\part{..}`.
`--parts`
: Treat top-level headers as parts in LaTeX output. The second level
headers will be chapters, i.e. `--chapters` is implied. This does not
effect the `beamer` output format.
`-N`, `--number-sections` `-N`, `--number-sections`
: Number section headings in LaTeX, ConTeXt, HTML, or EPUB output. : Number section headings in LaTeX, ConTeXt, HTML, or EPUB output.

View file

@ -184,6 +184,7 @@ data Opt = Opt
, optHighlight :: Bool -- ^ Highlight source code , optHighlight :: Bool -- ^ Highlight source code
, optHighlightStyle :: Style -- ^ Style to use for highlighted code , optHighlightStyle :: Style -- ^ Style to use for highlighted code
, optChapters :: Bool -- ^ Use chapter for top-level sects , optChapters :: Bool -- ^ Use chapter for top-level sects
, optParts :: Bool -- ^ Use parts for top-level sects in latex
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
, optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt , optReferenceODT :: Maybe FilePath -- ^ Path of reference.odt
, optReferenceDocx :: Maybe FilePath -- ^ Path of reference.docx , optReferenceDocx :: Maybe FilePath -- ^ Path of reference.docx
@ -249,6 +250,7 @@ defaultOpts = Opt
, optHighlight = True , optHighlight = True
, optHighlightStyle = pygments , optHighlightStyle = pygments
, optChapters = False , optChapters = False
, optParts = False
, optHTMLMathMethod = PlainMath , optHTMLMathMethod = PlainMath
, optReferenceODT = Nothing , optReferenceODT = Nothing
, optReferenceDocx = Nothing , optReferenceDocx = Nothing
@ -609,6 +611,11 @@ options =
(\opt -> return opt { optChapters = True })) (\opt -> return opt { optChapters = True }))
"" -- "Use chapter for top-level sections in LaTeX, DocBook" "" -- "Use chapter for top-level sections in LaTeX, DocBook"
, Option "" ["parts"]
(NoArg
(\opt -> return opt { optParts = True }))
"" -- "Use part for top-level sections in LaTeX"
, Option "N" ["number-sections"] , Option "N" ["number-sections"]
(NoArg (NoArg
(\opt -> return opt { optNumberSections = True })) (\opt -> return opt { optNumberSections = True }))
@ -1124,6 +1131,7 @@ convertWithOpts opts args = do
, optHighlightStyle = highlightStyle , optHighlightStyle = highlightStyle
, optChapters = chapters , optChapters = chapters
, optHTMLMathMethod = mathMethod' , optHTMLMathMethod = mathMethod'
, optParts = parts
, optReferenceODT = referenceODT , optReferenceODT = referenceODT
, optReferenceDocx = referenceDocx , optReferenceDocx = referenceDocx
, optEpubStylesheet = epubStylesheet , optEpubStylesheet = epubStylesheet
@ -1387,6 +1395,7 @@ convertWithOpts opts args = do
writerHtml5 = html5, writerHtml5 = html5,
writerHtmlQTags = htmlQTags, writerHtmlQTags = htmlQTags,
writerChapters = chapters, writerChapters = chapters,
writerParts = parts,
writerListings = listings, writerListings = listings,
writerBeamer = False, writerBeamer = False,
writerSlideLevel = slideLevel, writerSlideLevel = slideLevel,

View file

@ -374,6 +374,7 @@ data WriterOptions = WriterOptions
, writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show , writerBeamer :: Bool -- ^ Produce beamer LaTeX slide show
, writerSlideLevel :: Maybe Int -- ^ Force header level of slides , writerSlideLevel :: Maybe Int -- ^ Force header level of slides
, writerChapters :: Bool -- ^ Use "chapter" for top-level sects , writerChapters :: Bool -- ^ Use "chapter" for top-level sects
, writerParts :: Bool -- ^ Use "part" for top-level sects in LaTeX
, writerListings :: Bool -- ^ Use listings package for code , writerListings :: Bool -- ^ Use listings package for code
, writerHighlight :: Bool -- ^ Highlight source code , writerHighlight :: Bool -- ^ Highlight source code
, writerHighlightStyle :: Style -- ^ Style to use for highlighting , writerHighlightStyle :: Style -- ^ Style to use for highlighting
@ -422,6 +423,7 @@ instance Default WriterOptions where
, writerBeamer = False , writerBeamer = False
, writerSlideLevel = Nothing , writerSlideLevel = Nothing
, writerChapters = False , writerChapters = False
, writerParts = False
, writerListings = False , writerListings = False
, writerHighlight = False , writerHighlight = False
, writerHighlightStyle = pygments , writerHighlightStyle = pygments

View file

@ -750,18 +750,25 @@ sectionHeader unnumbered ident level lst = do
<> braces (text plain)) <> braces (text plain))
book <- gets stBook book <- gets stBook
opts <- gets stOptions opts <- gets stOptions
let level' = if book || writerChapters opts then level - 1 else level let level' = case level of
1 | writerParts opts -> 0
| writerBeamer opts -> 0
| book || writerChapters opts -> 1
| otherwise -> 2
_ | writerParts opts -> level - 1
| book || writerChapters opts -> level
| otherwise -> level + 1
let sectionType = case level' of let sectionType = case level' of
0 | writerBeamer opts -> "part" 0 -> "part"
| otherwise -> "chapter" 1 -> "chapter"
1 -> "section" 2 -> "section"
2 -> "subsection" 3 -> "subsection"
3 -> "subsubsection" 4 -> "subsubsection"
4 -> "paragraph" 5 -> "paragraph"
5 -> "subparagraph" 6 -> "subparagraph"
_ -> "" _ -> ""
inQuote <- gets stInQuote inQuote <- gets stInQuote
let prefix = if inQuote && level' >= 4 let prefix = if inQuote && level' >= 5
then text "\\mbox{}%" then text "\\mbox{}%"
-- needed for \paragraph, \subparagraph in quote environment -- needed for \paragraph, \subparagraph in quote environment
-- see http://tex.stackexchange.com/questions/169830/ -- see http://tex.stackexchange.com/questions/169830/
@ -770,7 +777,7 @@ sectionHeader unnumbered ident level lst = do
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 let stuffing = star <> optional <> contents
stuffing' <- hypertarget ident $ text ('\\':sectionType) <> stuffing <> lab stuffing' <- hypertarget ident $ text ('\\':sectionType) <> stuffing <> lab
return $ if level' > 5 return $ if level' > 6
then txt then txt
else prefix $$ stuffing' else prefix $$ stuffing'
$$ if unnumbered $$ if unnumbered