1

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

\newminted[ps]{js}{frame=lines,style=manni,fontfamily=courier,linenos=true}

And I used it like this

\begin{listing}[H]
\caption{Syntax of function declaration}
    \begin{ps}
    // My code is here
    \end{ps}
\end{listing}

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.

5
  • 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
    Jul 3, 2017 at 10:07
  • Welcome to TeX.SX! listings and minted are very different beasts.
    – egreg
    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
    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
    Jul 3, 2017 at 10:13
  • @emanek Yes, it's not relevant, the listing environment is another thing, independent of the listings package.
    – egreg
    Jul 3, 2017 at 10:17

1 Answer 1

1

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

You can use escapeinside:

\documentclass{article}

\usepackage{minted}

\newminted[ps]{js}{
  frame=lines,
  style=manni,
  fontfamily=courier,
  linenos=true,
  escapeinside=@@,
}

\begin{document}

\begin{ps}
... code@$_1$@ ... code@$^2$@ ... code@$_1^2$@ ...
\end{ps}

\end{document}

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

enter image description here

2
  • 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
    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
    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 .