I am using the minted package for code highlighting in my thesis. My minted command looks like this:


And I used it like this

\caption{Syntax of function declaration}
    // My code is here

I would like to use subscripts and superscripts within the minted code (I use it also for psuedocode and grammar rules, that's why I want subscripts..)

I've tried this to set mathescape as described here Subscript and superscript in lstlisting? but \lstset gives me Undefined control sequence error (I guess I am not using listing package...?)

Thanks for your time.

  • Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}.
    – Bobyandbob
    Commented Jul 3, 2017 at 10:07
  • Welcome to TeX.SX! listings and minted are very different beasts.
    – egreg
    Commented Jul 3, 2017 at 10:08
  • @egreg updated my question to show that my minted is within a listing, but I guess its irrelevant
    – emanek
    Commented Jul 3, 2017 at 10:13
  • @Bobyandbob valid point, sorry, I wanted to keep the question short and avoid wall of text... my latex scaffolding is kind of long
    – emanek
    Commented Jul 3, 2017 at 10:13
  • @emanek Yes, it's not relevant, the listing environment is another thing, independent of the listings package.
    – egreg
    Commented Jul 3, 2017 at 10:17

1 Answer 1


The command \lstset is for listings, which is very different from minted.

You can use escapeinside:





... code@$_1$@ ... code@$^2$@ ... code@$_1^2$@ ...


Instead of @@ you can use a different character that's not used in the ps environments.

enter image description here

  • This solves my problem, thanks! Now, would it be possible for the subscripts to "inherit" the font style and color from the minted environment? My subscripts are long-ish words and the math-y cursive + monospace looks funny togehter...
    – emanek
    Commented Jul 3, 2017 at 10:39
  • 1
    @emanek You should be more detailed in your question. Please, add a “real world” minimal example of the code you intend to typeset.
    – egreg
    Commented Jul 3, 2017 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .