0

I'm trying to have a lstlisting inside a longlisting, with some bash code. The bash code however ruins the word count function. The listing code is here:

\begin{longlisting}
    \centering
    \begin{lstlisting}[language=bash]
sudo apt update && sudo apt install curl gnupg2 lsb-release
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key  -o /usr/share/keyrings/ros-archive-keyring.gpg

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
\end{lstlisting}
\end{longlisting}

The word count function is from this tutorial

If I run it with backslash before the $, then it works, but not without

1
  • Welcome to TeX.SE!
    – Mensch
    Commented Dec 7, 2021 at 21:36

1 Answer 1

1

The root cause is that TeXcount encounters $ and interprets it to open a math group which needs another $ to be ended. This is presumably because TeXcount has not applied any parsing rules to lstlisting or longlisting.

TeXcount has a rule for the lstlisting environment defined as part of the listings package, but this is only applied if TeXcount encounters \usepackage{listings}.

You can alternatively specify the rule for handling lstlisting by including the comment

%TC:envir lstlisting [] xall

somewhere before first use. This specifies that it takes no required arguments (possibly optional arguments), and the content is completely excluded including symbols such as $ that normally need to be balanced.

1
  • This worked. Thank you very much
    – jonas
    Commented Dec 7, 2021 at 22:39

You must log in to answer this question.

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