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?

Victor
  • 367

1 Answers1

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}