tags:

views:

79

answers:

2

While writing in LaTeX, I happened to type something like "$ variable = test" as a text. However, LaTeX said something like: Missing $ ..

I tried putting \ before the $ and other math symbols, but it still messed up the shape of the text.

My question is: how can I instruct LaTeX that this whole paragraph or sentence, is pure text, and no math in it?

Also, away from this, when I try adding the symbol " | " it shows it as double underscore " __ ". How to solve this?

Thanks!

+3  A: 

You can use \textdollar{} to insert a text dollar. (Though \$ ought to work too; and I'm not sure why it doesn't for you.) And you can specify that something should be reproduced verbatim, and typeset in a tt font, by using \verb and the same character to surround it, e.g. \verb+|+ or \verb=$=.

The real issue here seems to be that you're typesetting some code in LaTeX: for this, use package listings, or one of the other packages for code listings.

ShreevatsaR
It is not only the dollar sign, but even the "^" sign. I tried listings, but I am not writing for any of the code languages supported, also I would like to have a more easier solution to use.Any other suggestions?
johnshaddad
Hmm? Listings supports code in any language; just put your code in \begin{lstlisting} … \end{lstlisting}. What could be easier? :-)
ShreevatsaR
I added "usepackage{verbatim}" to my Latex, and then used \verb+$+ but it said error: 1.34 \verb{+$+}The reason why I don't want listings is because there are a lot of places where I use these symbols/words. Eg. while I am speaking about something like if loops, I will need to include 3 words only with $ sign and other signs < or >, so I don't think putting that under \begin{lstlisting} \end{lstlisting} could be the easiest solution.. xD Also, I want it to be in the same line of my text, not on a sepearate paragraph.. any other suggestion?
johnshaddad
The reason is simply I tried the following: "To set this variable, try \begin{lstlisting} $ env | grep \end{lstlisting} and it should work."But it showed me error: Overfull \hbox (63.1068pt too wide) in paragraph at lines 81-82 [][][][][][]Then I tried making it:"To set this variable, try \begin{lstlisting}$ env | grep\end{lstlisting} and it should work."Then it worked, but it placed the code in a new line :S which is NOT what I want
johnshaddad
Yes, lstlisting is usually for code on a separate line, not "inline" code. You don't need package verbatim for `\verb`... from your error message, it looks like you put braces there by mistake? (`\verb` doesn't take braces; see [documentation](http://www.ipp.mpg.de/~dpc/LaTeX/ltx-342.html).) You can also try package [fancyvrb](http://mirror.ctan.org/macros/latex/contrib/fancyvrb/fancyvrb.pdf) if `\verb` doesn't work for you for some strange reason.
ShreevatsaR
+1  A: 

Besides the already mentioned and recommendable ways using the listings package or verb most special characters can be used by putting a backslash \ right before: \$, _, \% etc. If it doesn't for you, show a minimal example code.

The pipe symbol | is printed as wide dash in the default font encoding (OT1), other symbols don't work as well like < and >. But this can be fixed by switching to T1 encoding:

\usepackage[T1]{fontenc}

Those symbols will now be correctly printed. Perhaps visit:

Special LaTeX characters

Stefan
Thanks for the suggestion, Stefan. This solved my symbols problem :-)
johnshaddad