1

Note: Similar question to beamer-columns-environment-in-article-document, but the answer (just use minipage directly) isn't suitable in my use-case.

Basically, I'm generating LaTeX from markdown via pandoc (quarto, specifically), and I would like to use a columns layout to place text and a figure side-by-side (not necessarily equal width). The standard answer is to use minipages,

\begin{minipage}[t]{.6\textwidth}
\vspace{0pt}
Lorem ipsum dolor sit amet consectetur adipiscing elit morbi, vivamus erat himenaeos litora cras magnis blandit leo, etiam turpis lectus nullam feugiat porttitor dis. Non ultricies mus turpis in habitant auctor euismod duis scelerisque porttitor, mattis metus nisl risus leo curabitur laoreet eget varius. Etiam sed tortor nulla quis vehicula sodales non convallis aliquam phasellus, ut facilisis sociis molestie vel sagittis eu luctus.
  \begin{enumerate}
    \item firstly
    \item secondly
    \item thirdly
    \item quarto
  \end{enumerate}
\end{minipage}
\hfill
\begin{minipage}[t]{.3\textwidth}
\vspace{0pt}
\includegraphics{dummy.png}
this is a picture
\end{minipage}

screenshot

and that works fine, but within the minipage environment one cannot use markdown, as pandoc detects it as raw latex and passes it to the output without processing what's inside.

What would be much nicer would be a syntactic sugar such as the one provided by Beamer's \columns{} environment, which could be directly mapped in pandoc (/quarto) as:


:::: {.columns}

::: {.column width="60%"} Lorem ipsum dolor sit amet consectetur adipiscing elit morbi, vivamus erat himenaeos litora cras magnis blandit leo, etiam turpis lectus nullam feugiat porttitor dis. Non ultricies mus turpis in habitant auctor euismod duis scelerisque porttitor, mattis metus nisl risus leo curabitur laoreet eget varius. Etiam sed tortor nulla quis vehicula sodales non convallis aliquam phasellus, ut facilisis sociis molestie vel sagittis eu luctus.

  1. firstly
  2. secondly
  3. thirdly
  4. quarto

::: ::: {.column width="10%"} ::: ::: {.column width="30%"} :::

::::

with the additional advantage that the exact same syntax would work for other output (beamer, but also HTML, Word, etc.)

Unfortunately, I'm unable to understand, let alone extract, the relevant macro definition in Beamer. It looks full of beamer-specific variables, and I wouldn't know how to start extracting it, for use in other LaTeX classes.

Is there a more standalone columns-like environment in another package? Or could someone show me how to go about writing one (say for the article class)? It's a bit beyond my basic abilities to define new environments.

  • Just two buzzwords which might (or might not) help you: multicol package, wrapfig package. – Οὖτις Mar 25 '23 at 08:05
  • wrapfig doesn't like enum or itemize etc., and multicol is for equal-width cols, AFAIK – user14020101 Mar 25 '23 at 08:12
  • I think you could copy the pandoc filters which translate :::: {.columns} to beamer columns to other pandoc templates and modify them to use minipages. You'll probably reach more users familiar with this if you would ask on stackoverflow instead of a latex site – samcarter_is_at_topanswers.xyz Mar 25 '23 at 10:47
  • Understanding the beamer column code or porting it to other classes won't help you any further because the normal quarto templates don't know the :::: {.columns} filter, that's specific to the presentation template. – samcarter_is_at_topanswers.xyz Mar 25 '23 at 10:58
  • I asked here for the latex side of things; on the pandoc+quarto side, there's already a filter that parses the ::: columns syntax and outputs the corresponding code for different output formats (Html, beamer, Word, etc.), so it should be easy to add this new output. In fact, the latex-environment extension gets 95% of the way there, unfortunately it adds a line break between the minipages :/ – user14020101 Mar 25 '23 at 19:55

1 Answers1

1

To answer the TeX aspect of your question:

You can use a beamer-like columns environment in other classes like this:

\documentclass{article}

\usepackage{graphicx} \usepackage{beamerarticle}

\makeatletter \mode<article>{\renewenvironment<>{beamer@columnenv}[2][]{ \begin{minipage}[t]{#2}\vspace{0pt}}{\end{minipage}} \let\endcolumn\endbeamer@columnenv} \makeatother

\begin{document}

\begin{columns} \begin{column}{.6\textwidth} Lorem ipsum dolor sit amet consectetur adipiscing elit morbi, vivamus erat himenaeos litora cras magnis blandit leo, etiam turpis lectus nullam feugiat porttitor dis. Non ultricies mus turpis in habitant auctor euismod duis scelerisque porttitor, mattis metus nisl risus leo curabitur laoreet eget varius. Etiam sed tortor nulla quis vehicula sodales non convallis aliquam phasellus, ut facilisis sociis molestie vel sagittis eu luctus. \begin{enumerate} \item firstly \item secondly \item thirdly \item quarto \end{enumerate} \end{column}% \begin{column}{.4\textwidth} \includegraphics[width=\textwidth]{example-image-duck} this is a picture \end{column}% \end{columns}

\end{document}

enter image description here

  • Thanks, that's very helpful. I don't really understand the part inside \makeatletter, could you please explain what it's doing and why it is necessary? I'm hoping that the solution might eventually make its way into quarto, and understanding what's being added to the LaTeX template is going to be important. Out of curiosity, how hard would it be to make a standalone column+columns environment, not importing the whole lot of beamer macros? – user14020101 Mar 25 '23 at 19:50
  • @user14020101 It won't help you in any way whatsoever to define a columns environment in latex. As said in comments, the quarto template for normal classes does not have the same ::: {.columns} filter as the template for presentations. You should focus on creating such a filter for the quarto template you use. This new filter can then use normal minipages. It is not necessary nor helpful for your problem to have a latex columns environment. – samcarter_is_at_topanswers.xyz Mar 25 '23 at 19:55
  • I agree in principle, but in practice I suspect the quarto developers prefer to code in Lua than in Latex, and so having the equivalent of the Beamer macros available makes it trivial to support other LaTeX classes, since the ::: columns syntax is already part of the specification (integrated into the quarto ecosystem). – user14020101 Mar 25 '23 at 19:58
  • For other classes, a potential ::: columns filter should simply use minipages, no need to code anything in latex. – samcarter_is_at_topanswers.xyz Mar 25 '23 at 20:00
  • Somehow the minipage layout seems to be already implemented in quarto, with the layout keyword but not with the columns keyword. So presumably it will be easy to adapt the code. – user14020101 Mar 25 '23 at 23:14