Skip to content
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

multicols #375

Closed
emeth69 opened this issue Sep 21, 2023 · 7 comments
Closed

multicols #375

emeth69 opened this issue Sep 21, 2023 · 7 comments
Labels
discussion discussion requiring no code changes

Comments

@emeth69
Copy link

emeth69 commented Sep 21, 2023

Dear Minted Experts,
is there a way to have code formatted by minted in 2 or more columns side by side as the multicols=«number» option of the listings package? Or some workaround to have it implemented?

Thank you

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 21, 2023

\documentclass{article}
\usepackage{minted}
\usepackage{multicol}

\begin{document}
\begin{multicols}{2}
\begin{minted}[linenos]{tex}
\documentclass{article}
\usepackage{amsmath}

\begin{document}
content
\[
  a^2 + b^2 = c^2
\]
\end{document}
\end{minted}
\end{multicols}
\end{document}

image

@emeth69
Copy link
Author

emeth69 commented Sep 21, 2023

Yes but this doesn't work with \inputminted inside a tcolorbox, as in

\begin{tcolorbox}[%
         unbreakable, enhanced, colback={red}, colframe={yellow}, %
         sharp corners, boxrule=1pt, enhanced jigsaw, %
         opacityback=.50, boxsep=0pt, width=\textwidth, left=3pt, %
         right=3pt, top=3pt, bottom=2pt, arc=0pt, outer arc=0pt]
         \inputminted{python}{helloworld.py}%
      \end{tcolorbox}

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Sep 21, 2023

% !TeX TXS-program:compile = txs:///pdflatex/{%.tex} -shell-escape "%.tex"
\begin{filecontents}[noheader]{sample-doc.tex}
\documentclass{article}
\usepackage{amsmath}

\begin{document}
content
\[
  a^2 + b^2 = c^2
\]
\end{document}
\end{filecontents}

\documentclass{article}
\usepackage{minted}
\usepackage{multicol}
\usepackage{tcolorbox}

\tcbuselibrary{breakable, skins}

\begin{document}
\begin{tcolorbox}[
  unbreakable, enhanced, colback={red}, colframe={yellow},
  sharp corners, boxrule=1pt, enhanced jigsaw,
  % "opacityback=.50" changed to "opacityback=.20"
  opacityback=.20, boxsep=0pt, width=\textwidth, left=3pt,
  right=3pt, top=3pt, bottom=2pt, arc=0pt, outer arc=0pt,
  before upper=\begin{multicols}{2}, after upper={\end{multicols}} % <<< added
]
  \inputminted{tex}{sample-doc.tex}
\end{tcolorbox}
\end{document}

image

Here

\begin{tcolorbox}[before upper=\begin{multicols}{2}, after upper={\end{multicols}}]
  content
\end{tcolorbox}

is equivalent to

\begin{tcolorbox}
  \begin{multicols}{2}
    content
  \end{multicols}
\end{tcolorbox}

PS: Only environments that don't collect its content can be used this way (through options before upper and after upper).

@emeth69
Copy link
Author

emeth69 commented Sep 21, 2023

Great! This works. Thank you.

@goyalyashpal
Copy link

@emeth69 it seems this issue is solved for you, so, can you close this :)

@goyalyashpal
Copy link

Only environments that don't collect its content

can you explain this a bit more?

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Nov 23, 2023

@goyalyashpal It's hard to give a formal definition. For multicols env,

\begin{tcolorbox}[before upper=\begin{multicols}{2}, after upper={\end{multicols}}]
  content
\end{tcolorbox}

and

\begin{tcolorbox}
  \begin{multicols}{2}
    content
  \end{multicols}
\end{tcolorbox}

give the same output. But for some other environments, only the second form works and the first form may even fail to compile. Apart from verbatim-like envs, tcolorbox-based envs, amsmath multi-line display math envs, and several other commonly seen envs are in that list. See T-F-S/tcolorbox#250 for related discussions.

@gpoore gpoore added the discussion discussion requiring no code changes label Dec 3, 2023
@gpoore gpoore closed this as completed Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion discussion requiring no code changes
Projects
None yet
Development

No branches or pull requests

4 participants