As I've pointed out in a related question, I'd like to have some arrows pointing to parts of a source-code listing.

I know this is possible with the listings package, but is it possible with minted? That is, is there a way that I can insert a mark at a specific point inside the code minted is displaying?

  • I guess you can only try and find out – percusse Jan 14 '16 at 5:56
  • @percusse Well, it's more complicated than that, since minted is based on verbatim, you can't just do commands willy nilly, since they will print as text, rather than being interpreted as Latex commands. – jmite Jan 14 '16 at 6:24
  • See this one for example tex.stackexchange.com/questions/60155/… TikZ works in every mode – percusse Jan 14 '16 at 7:07
  • 1
    Doesn't that thread suggest the opposite and that it doesn't work? (Or that nobody there could figure it out, at least.) – cfr Jan 16 '16 at 3:08

Yes, it appears to work, you just need to specify an escape character (? here) to minted so you can insert the \tikzmark.

enter image description here



def f(x):
    y = x?\tikzmark{here}?2
return y

See this bit:
\begin{tikzpicture}[remember picture]
\draw[overlay, ->, line width=5pt, red] (0,0) -- (pic cs:here);
| improve this answer | |
  • I tried this and it didn't work for me. – Adam Miller Nov 13 '17 at 5:41
  • @AdamMiller "didn't work" isn't very informative:-) The above code makes the image shown, you need --shell-escape (for minted) and to run it twice (for tikzmark) If you got an error you could always ask a new question and show the error you got. – David Carlisle Nov 13 '17 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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