git.iko.soy/typeable/pandoc
on master help sign in
RST reader: add aligned environment when needed in math.
615a99cJohn MacFarlane
src/Text/Pandoc/Readers/RST.hs+7−2
@@ -972,11 +972,16 @@ extractCaption = do
972 legend <- optional blanklines >> (mconcat <$> many block)
972 legend <- optional blanklines >> (mconcat <$> many block)
973 return (capt,legend)
973 return (capt,legend)
974
974
975−-- divide string by blanklines
975+-- divide string by blanklines, and surround with
976+-- \begin{aligned}...\end{aligned} if needed.
976toChunks :: String -> [String]
977toChunks :: String -> [String]
977toChunks = dropWhile null
978toChunks = dropWhile null
978− . map (trim . unlines)
979+ . map (addAligned . trim . unlines)
979 . splitBy (all (`elem` (" \t" :: String))) . lines
980 . splitBy (all (`elem` (" \t" :: String))) . lines
981+ -- we put this in an aligned environment if it contains \\, see #4254
982+ where addAligned s = if "\\\\" `isInfixOf` s
983+ then "\\begin{aligned}\n" ++ s ++ "\n\\end{aligned}"
984+ else s
980
985
981codeblock :: [String] -> Maybe String -> String -> String -> RSTParser m Blocks
986codeblock :: [String] -> Maybe String -> String -> String -> RSTParser m Blocks
982codeblock classes numberLines lang body =
987codeblock classes numberLines lang body =
test/command/4254.mdnew file+12
@@ -0,0 +1,12 @@
1+```
2+% pandoc -f rst -t latex
3+.. math::
4+
5+ x &= y\\
6+ y &= z
7+^D
8+\[\begin{aligned}
9+x &= y\\
10+y &= z
11+\end{aligned}\]
12+```
test/rst-reader.native+1−1
@@ -317,7 +317,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
317,Para [Math DisplayMath "E=mc^2"]
317,Para [Math DisplayMath "E=mc^2"]
318,Para [Math DisplayMath "E = mc^2"]
318,Para [Math DisplayMath "E = mc^2"]
319,Para [Math DisplayMath "E = mc^2",Math DisplayMath "\\alpha = \\beta"]
319,Para [Math DisplayMath "E = mc^2",Math DisplayMath "\\alpha = \\beta"]
320−,Para [Math DisplayMath "E &= mc^2\\\\\nF &= \\pi E",Math DisplayMath "F &= \\gamma \\alpha^2"]
320+,Para [Math DisplayMath "\\begin{aligned}\nE &= mc^2\\\\\nF &= \\pi E\n\\end{aligned}",Math DisplayMath "F &= \\gamma \\alpha^2"]
321,Para [Str "All",Space,Str "done."]
321,Para [Str "All",Space,Str "done."]
322,Header 1 ("default-role",[],[]) [Str "Default-Role"]
322,Header 1 ("default-role",[],[]) [Str "Default-Role"]
323,Para [Str "Try",Space,Str "changing",Space,Str "the",Space,Str "default",Space,Str "role",Space,Str "to",Space,Str "a",Space,Str "few",Space,Str "different",Space,Str "things."]
323,Para [Str "Try",Space,Str "changing",Space,Str "the",Space,Str "default",Space,Str "role",Space,Str "to",Space,Str "a",Space,Str "few",Space,Str "different",Space,Str "things."]