1

When I put some minted code inside a basic rectangular TikZ node as follows:

\documentclass{article}
\usepackage{tikz}
\usepackage{minted}

\begin{document}

\begin{tikzpicture}[] \noderectangle{ \begin{minted}{perl6} say grep {$_ %% 3},[...] +<< prompt.split(" ").reverse \end{minted} };

\end{tikzpicture}

\end{document}

The lualatex --shell-escape compiler gives the following error:


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.1 \begin{Verbatim}[commandchars=\{}]

When I searched for this particular problem, I've noticed that it's not even asked. Do I miss something very obvious, have no idea.

How to put a minted code inside a TikZ node ?

System: TeXLive 2020 on Mac OS X

  • 1
    Ther errors goes away if you install a text width but that will add vertical space at the top. Similarly, a minipage (almost the same) helps, too, and doesn't add vertical space. You will need to set a width, though. – Qrrbrbirlbel Jan 27 '23 at 13:23
  • If you only need one line without setting a width you are better off using \mintinline: \node{\mintinline{perl6}!say grep {$_ %% 3},[...] +<< prompt.split(" ").reverse!}; – Qrrbrbirlbel Jan 27 '23 at 13:31
  • (not all solutions are applicable, but the basic principle -- i.e. horizontal versus vertical mode -- is the same throughout, and most solutions applies.) – user202729 Jan 27 '23 at 13:56

1 Answers1

2

You can wrap it in a minipage like this

\documentclass[tikz, border=1cm]{standalone}
\usepackage{minted}
\begin{document}
\begin{tikzpicture}
\node {
\begin{minipage}{\textwidth}
\begin{minted}{perl6}
say grep {$_ %% 3},[...] +<< prompt.split(" ").reverse
\end{minted}
\end{minipage}
};
\end{tikzpicture}
\end{document}

One line of syntax highlighted code