I write my document in other language, then I need to switch to English (switch font) when show code:


Then I face a problem when I try to put a special character into my defined command, like this:


Since I knew this would be fine within those command:

\lstinline{HEAD^^} ...or... \lstinline|HEAD^^|

So I want to undefined my command and use the original, but this seems not work:


How can I use \pretocmd with it?

  • 2
    \lstinline uses several steps in order not to absorb its argument too early and so to be able to print special characters, so defining \code with an argument defeats this special handling.
    – egreg
    Jul 15, 2014 at 23:16

1 Answer 1


Ok, I didn't find the answer to my question, but this workaround is just working:


This switch my language (and font) to English everywhere I call \lstinline and \begin{lstlisting} ... \end{lstlisting}, and switch back to my main language when the scope end. So I no longer need those \pretocmd or \BeforeBeginEnvironment anymore.

You must log in to answer this question.

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