0

I created a new command to replace all references with a text:

\newcommand{\Version}{1.0}

This works well in my texts. However, it does not work in this case:

\begin{fullwidth} 
    \begin{lstlisting}[language=bash] 
        mv ~/Downloads/application_\Version.bin .. # comment
    \end{lstlisting} 
\end{fullwidth} endcode

How can I do this? The expected result should replace \Version with 1.0

4

To do this you have to "escape" the listings code back to LaTeX using an escapeinside option to listings, like this:

\lstset{escapeinside={|}{|}}

then code between || is parsed by latex. Since vertical bar is used a lot in bash, I used the delimiters from here:

\documentclass{article}

\usepackage{listings}

\lstset{escapeinside={(*@}{@*)}}% Text between (*@ and @*) will be parsed by LaTeX

\newcommand{\Version}{1.0}

\begin{document}

\begin{lstlisting}[language=bash] 
  mv ~/Downloads/application_(*@\Version@*).bin .. # comment
\end{lstlisting}

\end{document}

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.