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.

Is there a way to stress/emphasize a line (or part of it for that matter) in minted code?

The listings package has the moredelim-option for that purpose.

share|improve this question
    
This is possible by the correct setting of pygmentize. The package minted doesn't format the code that the task of pygmentize. –  Marco Daniel Apr 17 '12 at 12:27
    
Ok thanks, i've found the option hl_lines for pygmentize. Is there a way to pass this to pygmentize when starting a code block? –  sschober Apr 17 '12 at 12:37
    
Not really. You can create your own new key. –  Marco Daniel Apr 17 '12 at 12:46
    
Could you elaborate a little, i don't know what you're suggesting. What do you mean by "key"? –  sschober Apr 17 '12 at 12:51
    
Pygmentize doesn’t support the hl_lines option for the LaTeX formatter, and by extension, neither does minted, sorry. It wouldn’t help either to include this key in minted – Pygments would just ignore it. –  Konrad Rudolph Apr 17 '12 at 13:04

1 Answer 1

up vote 3 down vote accepted

As Konrad Rudolph pointed out you can't expand pygmentize with the option \hl_lines.

Pygmentize doesn’t support the hl_lines option for the LaTeX formatter, and by extension, neither does minted, sorry.

I have another suggestion. You can use tikz to emphasize special lines.

Here the code:

\documentclass[letterpaper, 10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{minted}
\usepackage{tikz}
\usepackage{hyperref}
\def\theFancyVerbLine{%
  \rmfamily\tiny\arabic{FancyVerbLine}%
  {\tikz[remember picture,overlay]\node(minted-\arabic{FancyVerbLine}){};}%
}

\begin{document}

\begin{minted}[linenos]{bash}
#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd -P "$( dirname "$SOURCE" )" && pwd )"
java -jar "$DIR/arara.jar" $*
\end{minted}

\tikz[remember picture,overlay]\draw[fill=yellow,opacity=0.2] ([yshift=-0.05cm,xshift=0.3cm]minted-2) rectangle ([yshift=0.35cm,xshift=5.5cm]minted-2);

\end{document}

enter image description here

share|improve this answer
    
Hey, i like this idea! A little syntactic sugar in form of a generic command might be convenient. I defined a new command, which takes a single argument and interprets that as the lineno. Just need a way to figure out the width... –  sschober Apr 17 '12 at 15:10
    
@sschober: This is related to fancyvrb. The environment of the code is provided by this package. –  Marco Daniel Apr 17 '12 at 16:09
1  
Yay, arara! Thanks Marco! :) –  Paulo Cereda Apr 17 '12 at 22:08
    
@Marco: Thx, I'll look into fancyvrb then... –  sschober Apr 18 '12 at 10:25

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.