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.
This commit is contained in:
John MacFarlane 2018-01-14 15:10:13 -08:00
parent d9584d73f9
commit 615a99c2c2
3 changed files with 20 additions and 3 deletions

View file

@ -972,11 +972,16 @@ extractCaption = do
legend <- optional blanklines >> (mconcat <$> many block)
return (capt,legend)
-- divide string by blanklines
-- divide string by blanklines, and surround with
-- \begin{aligned}...\end{aligned} if needed.
toChunks :: String -> [String]
toChunks = dropWhile null
. map (trim . unlines)
. map (addAligned . trim . unlines)
. splitBy (all (`elem` (" \t" :: String))) . lines
-- we put this in an aligned environment if it contains \\, see #4254
where addAligned s = if "\\\\" `isInfixOf` s
then "\\begin{aligned}\n" ++ s ++ "\n\\end{aligned}"
else s
codeblock :: [String] -> Maybe String -> String -> String -> RSTParser m Blocks
codeblock classes numberLines lang body =

12
test/command/4254.md Normal file
View file

@ -0,0 +1,12 @@
```
% pandoc -f rst -t latex
.. math::
x &= y\\
y &= z
^D
\[\begin{aligned}
x &= y\\
y &= z
\end{aligned}\]
```

View file

@ -317,7 +317,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
,Para [Math DisplayMath "E=mc^2"]
,Para [Math DisplayMath "E = mc^2"]
,Para [Math DisplayMath "E = mc^2",Math DisplayMath "\\alpha = \\beta"]
,Para [Math DisplayMath "E &= mc^2\\\\\nF &= \\pi E",Math DisplayMath "F &= \\gamma \\alpha^2"]
,Para [Math DisplayMath "\\begin{aligned}\nE &= mc^2\\\\\nF &= \\pi E\n\\end{aligned}",Math DisplayMath "F &= \\gamma \\alpha^2"]
,Para [Str "All",Space,Str "done."]
,Header 1 ("default-role",[],[]) [Str "Default-Role"]
,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."]