aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-04-28 12:03:59 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-04-28 12:03:59 +0200
commite76b6724144032c62c183f850fe05271aa245fb5 (patch)
tree31210756c8b7f6462e576d3adf75f0d230b18d31
parentc346a8a7bef5a59c779073c9299bd968ecad44c9 (diff)
downloadpandoc-e76b6724144032c62c183f850fe05271aa245fb5.tar.gz
LaTeX writer: don't use lstinline it \item[..].
If you do, the contents of item disappear or are misplaced. Use `\texttt` instead. Closes #645.
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs8
-rw-r--r--test/command/645.md12
2 files changed, 19 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 59d6030cf..f0767c17c 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -65,6 +65,7 @@ data WriterState =
, stInQuote :: Bool -- true if in a blockquote
, stInMinipage :: Bool -- true if in minipage
, stInHeading :: Bool -- true if in a section heading
+ , stInItem :: Bool -- true if in \item[..]
, stNotes :: [Doc] -- notes in a minipage
, stOLLevel :: Int -- level of ordered list nesting
, stOptions :: WriterOptions -- writer options, so they don't have to be parameter
@@ -90,6 +91,7 @@ startingState options = WriterState {
, stInQuote = False
, stInMinipage = False
, stInHeading = False
+ , stInItem = False
, stNotes = []
, stOLLevel = 1
, stOptions = options
@@ -777,7 +779,10 @@ listItemToLaTeX lst
defListItemToLaTeX :: PandocMonad m => ([Inline], [[Block]]) -> LW m Doc
defListItemToLaTeX (term, defs) = do
+ -- needed to turn off 'listings' because it breaks inside \item[...]:
+ modify $ \s -> s{stInItem = True}
term' <- inlineListToLaTeX term
+ modify $ \s -> s{stInItem = False}
-- put braces around term if it contains an internal link,
-- since otherwise we get bad bracket interactions: \item[\hyperref[..]
let isInternalLink (Link _ _ ('#':_,_)) = True
@@ -952,6 +957,7 @@ inlineToLaTeX (Cite cits lst) = do
inlineToLaTeX (Code (_,classes,_) str) = do
opts <- gets stOptions
inHeading <- gets stInHeading
+ inItem <- gets stInItem
let listingsCode = do
let listingsopt = case getListingsLanguage classes of
Just l -> "[language=" ++ mbBraced l ++ "]"
@@ -975,7 +981,7 @@ inlineToLaTeX (Code (_,classes,_) str) = do
Right h -> modify (\st -> st{ stHighlighting = True }) >>
return (text (T.unpack h))
case () of
- _ | writerListings opts && not inHeading -> listingsCode
+ _ | writerListings opts && not (inHeading || inItem) -> listingsCode
| isJust (writerHighlightStyle opts) && not (null classes)
-> highlightCode
| otherwise -> rawCode
diff --git a/test/command/645.md b/test/command/645.md
new file mode 100644
index 000000000..90b285bed
--- /dev/null
+++ b/test/command/645.md
@@ -0,0 +1,12 @@
+Don't use listings commands in \item[..] context:
+```
+% pandoc -t latex
+`--foo` **BAR**
+
+: Enables the foo feature with **BAR** as its flavour.
+^D
+\begin{description}
+\item[\texttt{-\/-foo} \textbf{BAR}]
+Enables the foo feature with \textbf{BAR} as its flavour.
+\end{description}
+```