Skip to content

Commit aab5127

Browse files
committed
Allow multicols env in LaTeX reader
The multicols environment has a mandatory argument - number of columns. It is incorrectly parsed as plain string. Wrap multicols content into nested divs. Signed-off-by: Igor Pashev <pashev.igor@gmail.com>
1 parent de4fb05 commit aab5127

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Text/Pandoc/Readers/LaTeX.hs

+13
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,7 @@ environments = M.fromList
19131913
, ("abstract", mempty <$ (env "abstract" blocks >>= addMeta "abstract"))
19141914
, ("sloppypar", env "sloppypar" $ blocks)
19151915
, ("letter", env "letter" letterContents)
1916+
, ("multicols", env "multicols" multicols)
19161917
, ("minipage", env "minipage" $
19171918
skipopts *> spaces *> optional braced *> spaces *> blocks)
19181919
, ("figure", env "figure" $ skipopts *> figure)
@@ -2079,6 +2080,18 @@ letterContents = do
20792080
_ -> mempty
20802081
return $ addr <> bs -- sig added by \closing
20812082

2083+
multicols :: PandocMonad m => LP m Blocks
2084+
multicols = do
2085+
spaces
2086+
n <- fromMaybe 1 . safeRead . untokenize <$> braced
2087+
spaces
2088+
bs <- blocks
2089+
return $ divWith ("", ["columns"], []) $ cols n bs
2090+
where
2091+
cols :: Int -> Blocks -> Blocks
2092+
cols n = foldr1 (.) (replicate n $ divWith ("", ["column"], []))
2093+
2094+
20822095
figure :: PandocMonad m => LP m Blocks
20832096
figure = try $ do
20842097
resetCaption

test/command/latex-multicols.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# `\begin{multicols}`
2+
3+
```
4+
% pandoc -f latex -t native
5+
\begin{multicols}{2}
6+
Hello
7+
\end{multicols}
8+
^D
9+
[Div ("",["columns"],[])
10+
[Div ("",["column"],[])
11+
[Div ("",["column"],[])
12+
[Para [Str "Hello"]]]]]
13+
```
14+

0 commit comments

Comments
 (0)