git.iko.soy/typeable/pandoc
on master help sign in
RST reader: add aligned environment when needed in math.

rst2latex.py uses an align* environment for math in `.. math::` blocks, so this math may contain line breaks. If it does, we put the math in an `aligned` environment to simulate rst2latex.py's behavior. Closes #4254.

commit615a99c2c20782daae5de38854025e2d40d85f29 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 14 Jan 2018, 15:10 (9 years ago) parentd9584d7
3 files changed+20−3
src/Text/Pandoc/Readers/RST.hs+7−2 test/command/4254.md+12 test/rst-reader.native+1−1
src/Text/Pandoc/Readers/RST.hs+7−2
@@ -972,11 +972,16 @@ extractCaption = do
972972 legend <- optional blanklines >> (mconcat <$> many block)
973973 return (capt,legend)
974974
975−-- divide string by blanklines
975+-- divide string by blanklines, and surround with
976+-- \begin{aligned}...\end{aligned} if needed.
976977toChunks :: String -> [String]
977978toChunks = dropWhile null
978− . map (trim . unlines)
979+ . map (addAligned . trim . unlines)
979980 . 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
980985
981986codeblock :: [String] -> Maybe String -> String -> String -> RSTParser m Blocks
982987codeblock 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
317317,Para [Math DisplayMath "E=mc^2"]
318318,Para [Math DisplayMath "E = mc^2"]
319319,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"]
321321,Para [Str "All",Space,Str "done."]
322322,Header 1 ("default-role",[],[]) [Str "Default-Role"]
323323,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."]