git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Use mbox to get proper behavior inside `\sout`.

Closes #5529.

commit3febd81cbcadf7d36fd4686a5d323b31c44adf3a authorJohn MacFarlane <jgm@berkeley.edu> dateMon 10 Jun 2019, 15:02 (7 years ago) parent59529e4
3 files changed+17−7
src/Text/Pandoc/Writers/LaTeX.hs+6−6 test/Tests/Writers/LaTeX.hs+1−1 test/command/5529.md+10
src/Text/Pandoc/Writers/LaTeX.hs+6−6
@@ -1131,7 +1131,9 @@ inlineToLaTeX (Strong lst) =
11311131inlineToLaTeX (Strikeout lst) = do
11321132 -- we need to protect VERB in an mbox or we get an error
11331133 -- see #1294
1134− contents <- inlineListToLaTeX $ protectCode lst
1134+ -- with regular texttt we don't get an error, but we get
1135+ -- incorrect results if there is a space, see #5529
1136+ contents <- inlineListToLaTeX $ walk (concatMap protectCode) lst
11351137 modify $ \s -> s{ stStrikeout = True }
11361138 return $ inCmd "sout" contents
11371139inlineToLaTeX (Superscript lst) =
@@ -1336,12 +1338,10 @@ handleMathComment s =
13361338 '%':_ -> s ++ "\n"
13371339 _ -> s
13381340
1339−protectCode :: [Inline] -> [Inline]
1340−protectCode [] = []
1341−protectCode (x@(Code ("",[],[]) _) : xs) = x : protectCode xs
1342−protectCode (x@(Code _ _) : xs) = ltx "\\mbox{" : x : ltx "}" : xs
1341+protectCode :: Inline -> [Inline]
1342+protectCode x@(Code _ _) = [ltx "\\mbox{" , x , ltx "}"]
13431343 where ltx = RawInline (Format "latex")
1344−protectCode (x : xs) = x : protectCode xs
1344+protectCode x = [x]
13451345
13461346setEmptyLine :: PandocMonad m => Bool -> LW m ()
13471347setEmptyLine b = modify $ \st -> st{ stEmptyLine = b }
test/Tests/Writers/LaTeX.hs+1−1
@@ -81,7 +81,7 @@ tests = [ testGroup "code blocks"
8181 , "struck out and not highlighted" =:
8282 strikeout (code "foo" <> space
8383 <> str "bar") =?>
84− "\\sout{\\texttt{foo} bar}"
84+ "\\sout{\\mbox{\\texttt{foo}} bar}"
8585 , "single quotes" =:
8686 code "dog's" =?> "\\texttt{dog\\textquotesingle{}s}"
8787 , "backtick" =:
test/command/5529.mdnew file+10
@@ -0,0 +1,10 @@
1+```
2+% pandoc -t latex
3+~~`hello world`~~
4+
5+~~_`hello world`_~~
6+^D
7+\sout{\mbox{\texttt{hello\ world}}}
8+
9+\sout{\emph{\mbox{\texttt{hello\ world}}}}
10+```