0

I was reading the documentation of minted and found out I could use mdframed to create a frame around my code listings using:

\surroundwithmdframed{minted}

However, I now need to create listings from source files using \inputminted which is not an environment.

How do I use mdframed with \inputminted please?

1

The approach with mdframed is only mentioned as an alternative. Minted itself already has an option to draw frames:

\documentclass{article}

\usepackage{minted}

\begin{document}

\inputminted[frame=single]{python}{test.py}

\end{document}

enter image description here

If you insist on mdframed:

\documentclass{article}

\usepackage{minted}
\usepackage{mdframed}

\begin{document}

\begin{mdframed}
\inputminted{python}{test.py}
\end{mdframed}

\end{document}

or a new macro:

\documentclass{article}

\usepackage{minted}
\usepackage{mdframed}

\newcommand{\inputframedminted}[2]{%
\begin{mdframed}
\inputminted{#1}{#2}
\end{mdframed}
}

\begin{document}

\inputframedminted{python}{test.py}

\end{document}

renaming the command:

\documentclass{article}

\usepackage{minted}
\usepackage{mdframed}

\let\inputmintedorg\inputminted
\renewcommand{\inputminted}[2]{%
\begin{mdframed}
\inputmintedorg{#1}{#2}
\end{mdframed}
}

\begin{document}

\inputminted{python}{test.py}

\end{document}
  • So it is no way to automatically use mdframed whenever an \inputminted command appears? – Victor Aug 13 at 11:46
  • @Victor A new macro can make this automatic – user194021 Aug 13 at 11:52
  • Ok that's what I thought of doing but I couldn't figure it out by myself. Is there a way to renew the command but with the same name? – Victor Aug 13 at 11:58
  • 2
    @Victor Yes with \renewcommand – user194021 Aug 13 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.