Hi,
I want to use ${} in an lstlisting with xml-like code, but compiling gives "! Missing $ inserted." How I can I solve this ? I tried \${}, which clears the error on that place, but gives the error at \end{lstlisting}.
Thanks
Text Formatting ⇒ non-math use of $ in lstlisting
NEW: TikZ book now 40% off at Amazon.com for a short time.

- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
non-math use of $ in lstlisting
Can you prepare a minimal working example? This makes it much easier for us to test possible solutions.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Re: non-math use of $ in lstlisting
These are the last 3 lines of the listing, so in here is only 1 ${}. The complete listing has 4.
\begin{lstlisting}
<child link="hand_cam_\${whichside}"/>
<origin xyz="0.18 0.0 0.038" rpy="0.0 0.0 0.0"/>
</joint>
\end{lstlisting}
Due to the \$, the error is given at \end{listing}. With only $, the error is given at line with <child>.
Thanks.
\begin{lstlisting}
<child link="hand_cam_\${whichside}"/>
<origin xyz="0.18 0.0 0.038" rpy="0.0 0.0 0.0"/>
</joint>
\end{lstlisting}
Due to the \$, the error is given at \end{listing}. With only $, the error is given at line with <child>.
Thanks.
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
non-math use of $ in lstlisting
Please provide a proper minimal working example! If you do not know how to do that, follow the link.
Nevertheless, try out the following by clicking on open in writelatex
Nevertheless, try out the following by clicking on open in writelatex
Code: Select all
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
<child link="hand_cam_\${whichside}"/>
<child link="hand_cam_${whichside}"/>
\end{lstlisting}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Re: non-math use of $ in lstlisting
Ok, that apparently works. I checked the package that I use for the 4 listings I have so far, which is listings, not lstlistings. I checked http://en.wikibooks.org/wiki/LaTeX/Source_Code_Listings which basically does the same as I do. And I can't find the lstlistings package. So can you tell me where I may go wrong, apart from using another package ?
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
non-math use of $ in lstlisting
The package I am using is listings. And I already told you what to do to find the error: Prepare a minimal working example! The error you are describing does not come from the dollar sign. It is impossible for me or anybody else to tell what might be wrong without any code.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.