diff options
-rw-r--r-- | data/templates/default.beamer | 1 | ||||
-rw-r--r-- | data/templates/default.latex | 1 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 7 | ||||
-rw-r--r-- | test/command/1629.md | 10 | ||||
-rw-r--r-- | test/command/3422.md | 2 | ||||
-rw-r--r-- | test/lhs-test.latex+lhs | 1 |
6 files changed, 20 insertions, 2 deletions
diff --git a/data/templates/default.beamer b/data/templates/default.beamer index 4f2cae89a..fb02cb058 100644 --- a/data/templates/default.beamer +++ b/data/templates/default.beamer @@ -125,6 +125,7 @@ $if(verbatim-in-note)$ $endif$ $if(listings)$ \usepackage{listings} +\newcommand{\passthrough}[1]{#1} $endif$ $if(lhs)$ \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} diff --git a/data/templates/default.latex b/data/templates/default.latex index 030ab90f1..899a00aea 100644 --- a/data/templates/default.latex +++ b/data/templates/default.latex @@ -129,6 +129,7 @@ $endfor$ $endif$ $if(listings)$ \usepackage{listings} +\newcommand{\passthrough}[1]{#1} $endif$ $if(lhs)$ \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index f0767c17c..000f4f8fb 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -967,7 +967,12 @@ inlineToLaTeX (Code (_,classes,_) str) = do let chr = case "!\"&'()*,-./:;?@_" \\ str of (c:_) -> c [] -> '!' - return $ text $ "\\lstinline" ++ listingsopt ++ [chr] ++ str ++ [chr] + let str' = escapeStringUsing (backslashEscapes "\\{}%") str + -- we always put lstinline in a dummy 'passthrough' command + -- (defined in the default template) so that we don't have + -- to change the way we escape characters depending on whether + -- the lstinline is inside another command. See #1629: + return $ text $ "\\passthrough{\\lstinline" ++ listingsopt ++ [chr] ++ str' ++ [chr] ++ "}" let rawCode = liftM (text . (\s -> "\\texttt{" ++ escapeSpaces s ++ "}")) $ stringToLaTeX CodeString str where escapeSpaces = concatMap diff --git a/test/command/1629.md b/test/command/1629.md new file mode 100644 index 000000000..34d529b0d --- /dev/null +++ b/test/command/1629.md @@ -0,0 +1,10 @@ +``` +% pandoc -t latex --listings +bla bla `a % b` + +*bla bla `a % b`* +^D +bla bla \passthrough{\lstinline!a \% b!} + +\emph{bla bla \passthrough{\lstinline!a \% b!}} +``` diff --git a/test/command/3422.md b/test/command/3422.md index a010320e9..19f1f4462 100644 --- a/test/command/3422.md +++ b/test/command/3422.md @@ -4,6 +4,6 @@ See #3422 % pandoc -t latex --listings `int main(int argc, const char *argv[]);`{.c} ^D -\lstinline[language=C]!int main(int argc, const char *argv[]);! +\passthrough{\lstinline[language=C]!int main(int argc, const char *argv[]);!} ``` diff --git a/test/lhs-test.latex+lhs b/test/lhs-test.latex+lhs index 3509cb4a6..b0a58ac78 100644 --- a/test/lhs-test.latex+lhs +++ b/test/lhs-test.latex+lhs @@ -24,6 +24,7 @@ breaklinks=true} \urlstyle{same} % don't use monospace font for urls \usepackage{listings} +\newcommand{\passthrough}[1]{#1} \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} \IfFileExists{parskip.sty}{% \usepackage{parskip} |