Text Formattingnon-math use of $ in lstlisting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
hvn
Posts: 13
Joined: Thu Feb 03, 2011 9:40 pm

non-math use of $ in lstlisting

Post by hvn »

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

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

Post by Johannes_B »

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.
hvn
Posts: 13
Joined: Thu Feb 03, 2011 9:40 pm

Re: non-math use of $ in lstlisting

Post by hvn »

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.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

non-math use of $ in lstlisting

Post by Johannes_B »

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

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.
hvn
Posts: 13
Joined: Thu Feb 03, 2011 9:40 pm

Re: non-math use of $ in lstlisting

Post by hvn »

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 ?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

non-math use of $ in lstlisting

Post by Johannes_B »

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.
Post Reply