Skip to content

Allow multicols env in LaTeX reader #6449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Text/Pandoc/Readers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ environments = M.fromList
, ("abstract", mempty <$ (env "abstract" blocks >>= addMeta "abstract"))
, ("sloppypar", env "sloppypar" $ blocks)
, ("letter", env "letter" letterContents)
, ("multicols", env "multicols" multicols)
, ("minipage", env "minipage" $
skipopts *> spaces *> optional braced *> spaces *> blocks)
, ("figure", env "figure" $ skipopts *> figure)
Expand Down Expand Up @@ -2079,6 +2080,18 @@ letterContents = do
_ -> mempty
return $ addr <> bs -- sig added by \closing

multicols :: PandocMonad m => LP m Blocks
multicols = do
spaces
n <- fromMaybe 1 . safeRead . untokenize <$> braced
spaces
bs <- blocks
return $ divWith ("", ["columns"], []) $ cols n bs
where
cols :: Int -> Blocks -> Blocks
cols n = foldr1 (.) (replicate n $ divWith ("", ["column"], []))


figure :: PandocMonad m => LP m Blocks
figure = try $ do
resetCaption
Expand Down
14 changes: 14 additions & 0 deletions test/command/latex-multicols.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# `\begin{multicols}`

```
% pandoc -f latex -t native
\begin{multicols}{2}
Hello
\end{multicols}
^D
[Div ("",["columns"],[])
[Div ("",["column"],[])
[Div ("",["column"],[])
[Para [Str "Hello"]]]]]
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may have misunderstood what I meant about two column Divs: the structure should be:

Div columns
[ Div column
, Div column ]

and not

Div columns
[ Div column
  [ Div column ...

Does that make more sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, what would be the content of the first div for example? Empty?

Div columns
[ Div column ""
, Div column "text foo hello"]

?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I need to understand better what you're trying to do.

The latex multicols environment creates columned text, but it computes where the column breaks go.
In order to duplicate this in pandoc we'd need pandoc to compute where a new column starts.
Is this something you're trying to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I am basically trying to ignore the number of columns in latex :)

\begin{multicols}{2} % <- here
% ...
\end{multicols}

There is nothing more we can do, I think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then maybe I led you astray in my advice to include the nested column divs.
Maybe it makes most sense simply to include an outer "columns" div, and then the content inside.