git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Protect graphics in headers.
1326a41Jesse Rosenthal
src/Text/Pandoc/Writers/LaTeX.hs+15−6
@@ -54,6 +54,7 @@ data WriterState =
54 WriterState { stInNote :: Bool -- true if we're in a note
54 WriterState { stInNote :: Bool -- true if we're in a note
55 , stInQuote :: Bool -- true if in a blockquote
55 , stInQuote :: Bool -- true if in a blockquote
56 , stInMinipage :: Bool -- true if in minipage
56 , stInMinipage :: Bool -- true if in minipage
57+ , stInHeading :: Bool -- true if in a section heading
57 , stNotes :: [Doc] -- notes in a minipage
58 , stNotes :: [Doc] -- notes in a minipage
58 , stOLLevel :: Int -- level of ordered list nesting
59 , stOLLevel :: Int -- level of ordered list nesting
59 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
60 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
@@ -76,9 +77,9 @@ writeLaTeX :: WriterOptions -> Pandoc -> String
76writeLaTeX options document =
77writeLaTeX options document =
77 evalState (pandocToLaTeX options document) $
78 evalState (pandocToLaTeX options document) $
78 WriterState { stInNote = False, stInQuote = False,
79 WriterState { stInNote = False, stInQuote = False,
79− stInMinipage = False, stNotes = [],
80+ stInMinipage = False, stInHeading = False,
80− stOLLevel = 1, stOptions = options,
81+ stNotes = [], stOLLevel = 1,
81− stVerbInNote = False,
82+ stOptions = options, stVerbInNote = False,
82 stTable = False, stStrikeout = False,
83 stTable = False, stStrikeout = False,
83 stUrl = False, stGraphics = False,
84 stUrl = False, stGraphics = False,
84 stLHS = False, stBook = writerChapters options,
85 stLHS = False, stBook = writerChapters options,
@@ -179,7 +180,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
179elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
180elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
180elementToLaTeX _ (Blk block) = blockToLaTeX block
181elementToLaTeX _ (Blk block) = blockToLaTeX block
181elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do
182elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do
183+ modify $ \s -> s{stInHeading = True}
182 header' <- sectionHeader ("unnumbered" `elem` classes) id' level title'
184 header' <- sectionHeader ("unnumbered" `elem` classes) id' level title'
185+ modify $ \s -> s{stInHeading = False}
183 innerContents <- mapM (elementToLaTeX opts) elements
186 innerContents <- mapM (elementToLaTeX opts) elements
184 return $ vsep (header' : innerContents)
187 return $ vsep (header' : innerContents)
185
188
@@ -466,8 +469,11 @@ blockToLaTeX (DefinitionList lst) = do
466 "\\end{description}"
469 "\\end{description}"
467blockToLaTeX HorizontalRule = return $
470blockToLaTeX HorizontalRule = return $
468 "\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"
471 "\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"
469−blockToLaTeX (Header level (id',classes,_) lst) =
472+blockToLaTeX (Header level (id',classes,_) lst) = do
473+ modify $ \s -> s{stInHeading = True}
470− sectionHeader ("unnumbered" `elem` classes) id' level lst
474+ hdr <- sectionHeader ("unnumbered" `elem` classes) id' level lst
475+ modify $ \s -> s{stInHeading = False}
476+ return hdr
471blockToLaTeX (Table caption aligns widths heads rows) = do
477blockToLaTeX (Table caption aligns widths heads rows) = do
472 headers <- if all null heads
478 headers <- if all null heads
473 then return empty
479 then return empty
@@ -803,7 +809,10 @@ inlineToLaTeX (Image _ (source, _)) = do
803 then source
809 then source
804 else unEscapeString source
810 else unEscapeString source
805 source'' <- stringToLaTeX URLString source'
811 source'' <- stringToLaTeX URLString source'
812+ inHeading <- gets stInHeading
813+ return $
814+ (if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
806− return $ "\\includegraphics" <> braces (text source'')
815+ <> braces (text source'')
807inlineToLaTeX (Note contents) = do
816inlineToLaTeX (Note contents) = do
808 inMinipage <- gets stInMinipage
817 inMinipage <- gets stInMinipage
809 modify (\s -> s{stInNote = True})
818 modify (\s -> s{stInNote = True})