@@ -967,7 +967,12 @@ inlineToLaTeX (Code (_,classes,_) str) = do
967967 let chr = case "!\"&'()*,-./:;?@_" \\ str of
968968 (c:_) -> c
969969 [] -> '!'
970− return $ text $ "\\lstinline" ++ listingsopt ++ [chr] ++ str ++ [chr]
970+ let str' = escapeStringUsing (backslashEscapes "\\{}%") str
971+ -- we always put lstinline in a dummy 'passthrough' command
972+ -- (defined in the default template) so that we don't have
973+ -- to change the way we escape characters depending on whether
974+ -- the lstinline is inside another command. See #1629:
975+ return $ text $ "\\passthrough{\\lstinline" ++ listingsopt ++ [chr] ++ str' ++ [chr] ++ "}"
971976 let rawCode = liftM (text . (\s -> "\\texttt{" ++ escapeSpaces s ++ "}"))
972977 $ stringToLaTeX CodeString str
973978 where escapeSpaces = concatMap