3

How do I print a $ inside \tt?

I tried escaping with a backslash, but didn't work.

\tt{\$}

throws an error.

! Argument of \OT1\^ has an extra }

Update

Sorry, the issue was not with $, but with ^ in the next line.

Used \textasciitilde and everything worked fine.

ATOzTOA
  • 627

2 Answers2

6

First of all, I would advise you to use \texttt instead of \tt. See Does it matter if I use \textit or \it, \bfseries or \bf, etc. \texttt is the LaTeX equivalent of the Plain TeX \tt. If in Plain TeX, you write {\tt \$} and it should work. You have to enclose \tt in braces {} to make the typewriter type effect local to the text inside braces. In LaTeX, you write \texttt{\$} instead.

hpesoj626
  • 17,282
6

\tt is a switch, not a commmand with argument. Also it is obsolete. Nevertheless it works fine, and your problem is somewhere else. Make a complete example instead of sending code snippets.

\documentclass{article}
%not necessary but better
\usepackage[T1]{fontenc}
\begin{document}
\ttfamily \$
\tt \$ %obsolete command
\verb+$+
\texttt{\$}
\end{document}
Ulrike Fischer
  • 327,261