Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.
share|improve this question
    
The answer of the linked question is similar to your problem: tex.stackexchange.com/questions/23744/… –  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 Answer 1

up vote 6 down vote accepted

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

share|improve this answer
    
This did the trick for me. Thank You! –  Alessandro Vermeulen Jan 16 '12 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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