## LaTeX forum ⇒ Math & Science ⇒ How do I prevent latex from inserting unwanted dollar signs? Topic is solved

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm

### How do I prevent latex from inserting unwanted dollar signs?

The quoted code is supposed to represent instructions for using a calculator (MWE at the bottom). However, the latex compiler insists on inserting "$" in various places. For example, it puts a dollar sign prior to the text "x^3", then the output is an x raised to the third power, which would be great if the calculator had an x^3 button. But the calculator has a "x" button, a "^" button and a "3" button, which I want to be printed exactly as "x^3". On the other hand, there is an "x^2" button, so I do want that text to be interpreted as math. You can see how I put the dollar signs around that statement. How can I get the latex compiler to stop inserting unwanted$s?

You can enter the integral from line 2 into your calculator as\newline
\texttt{\textsc{[math] 9 2[$\pi$]1/6(x^3 [>] +3/x) [2nd] [$x^2$] 1/4(x [$x^2$] +x^-2 [>] ) [$x^2$],x,1/2,x}}

\documentclass[fleqn]{article}\usepackage{amsfonts,amsmath,amssymb,amsthm,nicefrac}\everymath{\displaystyle}\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip}\begin{document} Alternately, you can enter the integral from line 2 into your calculator as\newline\newline\texttt{\textsc{[math] 9 2[$\pi$]1/6(x^3 [>] +3/x) [2nd] [$x^2$] 1/4(x [$x^2$] +x^-2 [>] ) [$x^2$],x,1/2,x}} \end{document}

Tags:

Johannes_B
Site Moderator
Posts: 3790
Joined: Thu Nov 01, 2012 4:08 pm
Like the backslash, or the dollar sign, the circumflex (caret) is a symbol that has to be treated in a different way, if you want to print it.

\documentclass[fleqn]{article}\usepackage{amsfonts,amsmath,amssymb,amsthm,nicefrac}\everymath{\displaystyle}\setlength{\parindent}{0pt}\setlength{\parskip}{\baselineskip}\newcommand{\calcinput}[1]{\begingroup\ttfamily#1\endgroup}\begin{document} Alternately, you can enter the integral from line 2 into yourcalculator as%\newline%\newline%Oh, please don't do that \calcinput{\textsc{[math] 9 2[$\pi$]1/6(x\textasciicircum3 [>]	+3/x) [2nd] [x$^2$]%note the difference	1/4(x [$x^2$] +x\^{}-2 [>] )[$x^2$],x,1/2,x}} \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.

Singularity
Posts: 152
Joined: Sat Jan 22, 2011 9:55 pm
Thansk, Johannes. What exactly was the part that told Latex not to insert dollar signs?

I notice you treated the circumflex differently in two different spots. Once you explicitly said "\circumflex" and once you just escaped it with a slash. What's the difference? Were you just showing me two different ways to accomplish the same thing?

I had tried escaping it, but it didn't work. I think I did it wrong.

Thanks.

Johannes_B
Site Moderator
Posts: 3790
Joined: Thu Nov 01, 2012 4:08 pm
What told LaTeX not to get into math mode? Both are text commands.

Both ways are exactly the same
\DeclareTextCommandDefault{\textasciicircum}{\^{}}

As you can see, it really escaping the char, but it is a placing the diacritic over an non-existing letter (the empty argument). I bet you forgot that pair of empty braces and suddenly the minus sign got a caret. At least this is what happended to me when i tried the first time ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

cgnieder
Site Moderator
Posts: 1988
Joined: Sat Apr 16, 2011 7:27 pm
Singularity wrote:What exactly was the part that told Latex not to insert dollar signs?

This minimal example
\documentclass{article}\begin{document}^\end{document}

gives in the log
! Missing $inserted.<inserted text>$l.3 ^ I've inserted a begin-math/end-math symbol since I thinkyou left one out. Proceed, with fingers crossed.

In standard settings the character ^ has category code 7 (math superscript) which makes usage of ^ only allowed in math mode. If (La)TeX finds it in another mode it switches to math mode trying to fix the supposed error in the code.

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim