git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: don't use lstinline it \item[..].

If you do, the contents of item disappear or are misplaced. Use `\texttt` instead. Closes #645.

commite76b6724144032c62c183f850fe05271aa245fb5 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 28 Apr 2017, 12:03 (9 years ago) parentc346a8a
2 files changed+19−1
src/Text/Pandoc/Writers/LaTeX.hs+7−1 test/command/645.md+12
src/Text/Pandoc/Writers/LaTeX.hs+7−1
@@ -65,6 +65,7 @@ data WriterState =
6565 , stInQuote :: Bool -- true if in a blockquote
6666 , stInMinipage :: Bool -- true if in minipage
6767 , stInHeading :: Bool -- true if in a section heading
68+ , stInItem :: Bool -- true if in \item[..]
6869 , stNotes :: [Doc] -- notes in a minipage
6970 , stOLLevel :: Int -- level of ordered list nesting
7071 , stOptions :: WriterOptions -- writer options, so they don't have to be parameter
@@ -90,6 +91,7 @@ startingState options = WriterState {
9091 , stInQuote = False
9192 , stInMinipage = False
9293 , stInHeading = False
94+ , stInItem = False
9395 , stNotes = []
9496 , stOLLevel = 1
9597 , stOptions = options
@@ -777,7 +779,10 @@ listItemToLaTeX lst
777779
778780defListItemToLaTeX :: PandocMonad m => ([Inline], [[Block]]) -> LW m Doc
779781defListItemToLaTeX (term, defs) = do
782+ -- needed to turn off 'listings' because it breaks inside \item[...]:
783+ modify $ \s -> s{stInItem = True}
780784 term' <- inlineListToLaTeX term
785+ modify $ \s -> s{stInItem = False}
781786 -- put braces around term if it contains an internal link,
782787 -- since otherwise we get bad bracket interactions: \item[\hyperref[..]
783788 let isInternalLink (Link _ _ ('#':_,_)) = True
@@ -952,6 +957,7 @@ inlineToLaTeX (Cite cits lst) = do
952957inlineToLaTeX (Code (_,classes,_) str) = do
953958 opts <- gets stOptions
954959 inHeading <- gets stInHeading
960+ inItem <- gets stInItem
955961 let listingsCode = do
956962 let listingsopt = case getListingsLanguage classes of
957963 Just l -> "[language=" ++ mbBraced l ++ "]"
@@ -975,7 +981,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do
975981 Right h -> modify (\st -> st{ stHighlighting = True }) >>
976982 return (text (T.unpack h))
977983 case () of
978− _ | writerListings opts && not inHeading -> listingsCode
984+ _ | writerListings opts && not (inHeading || inItem) -> listingsCode
979985 | isJust (writerHighlightStyle opts) && not (null classes)
980986 -> highlightCode
981987 | otherwise -> rawCode
test/command/645.mdnew file+12
@@ -0,0 +1,12 @@
1+Don't use listings commands in \item[..] context:
2+```
3+% pandoc -t latex
4+`--foo` **BAR**
5+
6+: Enables the foo feature with **BAR** as its flavour.
7+^D
8+\begin{description}
9+\item[\texttt{-\/-foo} \textbf{BAR}]
10+Enables the foo feature with \textbf{BAR} as its flavour.
11+\end{description}
12+```