@@ -54,6 +54,7 @@ data WriterState =
5454 WriterState { stInNote :: Bool -- true if we're in a note
5555 , stInQuote :: Bool -- true if in a blockquote
5656 , stInMinipage :: Bool -- true if in minipage
57+ , stInHeading :: Bool -- true if in a section heading
5758 , stNotes :: [Doc] -- notes in a minipage
5859 , stOLLevel :: Int -- level of ordered list nesting
5960 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
@@ -76,9 +77,9 @@ writeLaTeX :: WriterOptions -> Pandoc -> String
7677writeLaTeX options document =
7778 evalState (pandocToLaTeX options document) $
7879 WriterState { stInNote = False, stInQuote = False,
79− stInMinipage = False, stNotes = [],
80− stOLLevel = 1, stOptions = options,
81− stVerbInNote = False,
80+ stInMinipage = False, stInHeading = False,
81+ stNotes = [], stOLLevel = 1,
82+ stOptions = options, stVerbInNote = False,
8283 stTable = False, stStrikeout = False,
8384 stUrl = False, stGraphics = False,
8485 stLHS = False, stBook = writerChapters options,
@@ -179,7 +180,9 @@ pandocToLaTeX options (Pandoc meta blocks) = do
179180elementToLaTeX :: WriterOptions -> Element -> State WriterState Doc
180181elementToLaTeX _ (Blk block) = blockToLaTeX block
181182elementToLaTeX opts (Sec level _ (id',classes,_) title' elements) = do
183+ modify $ \s -> s{stInHeading = True}
182184 header' <- sectionHeader ("unnumbered" `elem` classes) id' level title'
185+ modify $ \s -> s{stInHeading = False}
183186 innerContents <- mapM (elementToLaTeX opts) elements
184187 return $ vsep (header' : innerContents)
185188
@@ -466,8 +469,11 @@ blockToLaTeX (DefinitionList lst) = do
466469 "\\end{description}"
467470blockToLaTeX HorizontalRule = return $
468471 "\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"
469−blockToLaTeX (Header level (id',classes,_) lst) =
470− sectionHeader ("unnumbered" `elem` classes) id' level lst
472+blockToLaTeX (Header level (id',classes,_) lst) = do
473+ modify $ \s -> s{stInHeading = True}
474+ hdr <- sectionHeader ("unnumbered" `elem` classes) id' level lst
475+ modify $ \s -> s{stInHeading = False}
476+ return hdr
471477blockToLaTeX (Table caption aligns widths heads rows) = do
472478 headers <- if all null heads
473479 then return empty
@@ -803,7 +809,10 @@ inlineToLaTeX (Image _ (source, _)) = do
803809 then source
804810 else unEscapeString source
805811 source'' <- stringToLaTeX URLString source'
806− return $ "\\includegraphics" <> braces (text source'')
812+ inHeading <- gets stInHeading
813+ return $
814+ (if inHeading then "\\protect\\includegraphics" else "\\includegraphics")
815+ <> braces (text source'')
807816inlineToLaTeX (Note contents) = do
808817 inMinipage <- gets stInMinipage
809818 modify (\s -> s{stInNote = True})