6

I'm familiar with the Defining a command for a minted environment question. In addition to defining the mint parameters I also want to wrap the minted code inside a Tikz box for its nice looks.

I've tried the following code which obviously doesn't work due to the command issue. But I can't find how combine it with the tools the minted library provides:

\newcommand{\jscode}[1]{
\begin{tikzpicture} \node [mintedbox] (box){ \begin{minipage}{\textwidth}
    \begin{minted}{javascript}#1\end{minted}
    \end{minipage}  }; \end{tikzpicture}
}

Perhaps superfluous but here is the error I get:

! Paragraph ended before \FV@BeginScanning was complete.
  • The answer of the linked question is similar to your problem: http://tex.stackexchange.com/questions/23744/verbatim-text-cant-be-shown-correctly-in-pdf/23746#23746 – Marco Daniel Jan 15 '12 at 15:40
  • I'm trying to figure out how. Those work with different environments. So indeed it is similar but the \newminted command doesn't provide in customisation/wrapping options similar to the two mentioned in your link. – Alessandro Vermeulen Jan 15 '12 at 16:03

1 Answers1

8

The problem with defining a command contains verbatim material is shown in the link.

Whatever I think the easiest method is to redefine the internal colorbg environment and set the bgcolor-option global.

Based on the redefinition you can use the command \newmint to define your \jscode

\documentclass[12pt]{article}
\usepackage[]{minted}

\usepackage{tikz}
\makeatletter

\edef\minted@resetoptions{\minted@resetoptions\def\minted@opt@bgcolor{foo}}
\tikzset{mintedbox/.style={draw=red,rectangle,fill=yellow!20}}
\renewenvironment{minted@colorbg}[1]{%
  \noindent
  \begin{lrbox}{\minted@bgbox}
  \begin{minipage}{.8\linewidth}}
 {\end{minipage}
  \end{lrbox}%
  \tikz\node[mintedbox,text width=\linewidth,] 
         {\usebox{\minted@bgbox}};
 }

\newmint[jscode]{javascript}{}
\begin{document}
\begin{minted}[]{javascript}
a=b;
\end{minted}

\jscode+foo+
\end{document}

enter image description here

Marco Daniel
  • 95,681