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 was thinking how can I frame particular pieces of minted environment for beamer slides. I had a choice either to use overlays and split code across several blocks ( Beamer vs. Minted: overlays ) or just to draw some frame on top. I feel like the second should be a bit better though it would require some absolute coordinates for selection to roughly match code.

I've read Wrapping minted in a Tikz box with a command and it works just fine, however I'd like to be able to refer to each node by some unique name. For instance the following allows me to refer to a single minted block later as a.

\renewenvironment{minted@colorbg}[1]{%
  \noindent
  \begin{lrbox}{\minted@bgbox}
  \begin{minipage}{.8\linewidth}}
 {\end{minipage}
  \end{lrbox}%
  \tikz\node[text width=\linewidth,] (a) %mintedbox,
         {\usebox{\minted@bgbox}};
 }

%\newmint[jscode]{javascript}{}

\tikzstyle{every picture}+=[remember picture]

So I can have later something like

\begin{tikzpicture}[overlay]
        \draw (a.north west) rectangle ++(2cm,-1cm);
\end{tikzpicture}

I'd like it to be less hard-coded. Is it possible to pass a name into that \renewenvironment definition via somehow redefined minted or something?

If there are better alternatives to point into particular fragments of minted environment on beamer slides, I'd be interested.

share|improve this question
2  
You can create a new counter to unique the node. –  Marco Daniel Jan 28 '12 at 9:51
    
It kind of works. Would you mind sharing an idea if it is possible to utilize \label and if possible use different coordinate system of tikz such that I naturally use line numbers instead of cm in vertical direction? It would complete the way to put an emphasis on parted of minted block. –  mlt Feb 2 '12 at 3:59
    
Another question relates to coordinates calculation as using corners is not that exciting. I can use tikz calc library for that. However I wonder if the following can be less verbose to mark a couple of lines in the middle of minted block: \draw ($(minted1.north west)-(0cm,5cm)$) rectangle ++($(minted1.east) - (minted1.west) - (0cm,1cm)$); –  mlt Feb 2 '12 at 4:47
    
@MarcoDaniel Would you be willing to put up a small example? I think the OP forgot to ping you with @ character :) –  percusse Mar 31 '12 at 11:50
add comment

1 Answer

up vote 1 down vote accepted

In the example below I define a new counter. In this way it is possible to unique every node. The node-number can be printed by setting the command:

\showmintedcountertrue

In this case the node name will be printed in the right margin.

% !TEX program  = pdflatex -- shell-escape
\documentclass[12pt]{beamer}
\usepackage[]{minted}

\usepackage{tikz}
\makeatletter
\newcounter{mymintedcounter}
\newif\ifshowmintedcounter
\edef\minted@resetoptions{\minted@resetoptions\def\minted@opt@bgcolor{foo}}
\renewenvironment{minted@colorbg}[1]{%
  \noindent\stepcounter{mymintedcounter}%
  \begin{lrbox}{\minted@bgbox}
  \begin{minipage}{.8\linewidth}}
 {\end{minipage}
  \end{lrbox}%
  \tikz\node[text width=\linewidth] (a-\themymintedcounter) 
         {\usebox{\minted@bgbox}%
           \ifshowmintedcounter\hfill\rlap{\quad\themymintedcounter}\fi
         };
 }
\makeatletter

\tikzstyle{every picture}+=[remember picture]


%\showmintedcounterfalse
\showmintedcountertrue

\begin{document}
\begin{frame}[fragile]
\begin{minted}[]{javascript}
a=b;
\end{minted}
\begin{tikzpicture}[overlay]
        \draw (a-\themymintedcounter.north west) rectangle ++(2cm,-1cm);
\end{tikzpicture}
\end{frame}
\end{document}
share|improve this answer
add comment

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.