# How do I put the “\$_” string in a \section?

How do I put the "`\$_`" string in a `\section`?

When I try `\section{\$\_}` it gives me `Missing \$ inserted` error.

When I try `\section{\\$\_}` it gives me `Extra }, or forgotten \$.` error.

When I try `\section{\verb|\$_|}` it gives me `Argument of \@xtrplargoom has an extra }` error.

-
do you mean a real dollar sign, or the section sign? – barbara beeton Jan 13 '12 at 20:24
I mean the real dollar sign followed by an underscore. (Perl's `\$_` variable.) – Peteris Krumins Jan 13 '12 at 20:24
@ChristianLindig see my 3rd "when" case. """ When I try `\section{\verb|\$_|}` it gives me Argument of `\@xtrplargoom has an extra } error.` """ (I'm using `memoir` document class.) – Peteris Krumins Jan 13 '12 at 20:25
The second is correct and doesn't give errors. You may want to say `\texttt{\\$\_}`, but it's not relevant. – egreg Jan 13 '12 at 20:26
I can't explain it guys, but it started working by itself. Sorry about trouble! – Peteris Krumins Jan 13 '12 at 20:39

Not an answer, but an explanation:

• "When I try `\section{\$\_}` it gives me `Missing \$ inserted` error."

You are allowed math in `\section`, so `\section{This is \$x\$}` is no problem. In your case however, you don't have a closing `\$`. Sure, you may not want it, but that's what TeX sees and therefore expects.

• "When I try `\section{\\$\_}` it gives me `Extra }, or forgotten \$` error."

This works because escaping `\$` and `_` removes their math-context.

• "When I try `\section{\verb|\$_|}` it gives me `Argument of \@xtrplargoom has an extra }` error."

You cannot pass verbatim content as an argument to a macro. See Why doesn’t verbatim work within ...? The link includes ways of using verbatim content as arguments in a number of ways, if that's what you're really after.

When working with `hyperref`, you may also be interested in using `\texorpdfstring{<TeX string>}{<PDF string>}`. This is helpful if you have bookmarks (also associated with `\section` commands) that consist of a string containing ASCII characters.

And another question:

• Why is it that sometimes it could not work and then suddenly work?

Well, when you use `\section{<stuff>}`, LaTeX actually does `\section[<stuff>]{<stuff>}` (since the complete syntax of the optional argument is used, even though you don't specify it). Therefore, `<stuff>` makes its way into your `.aux` file, used for processing labels, references and other ToC-related things. If "bad things" go in there, it could be that it takes a "correct" compile to clear it (even though there will still be errors from reading the "bad" `.aux`), followed by another "correct" compile to be error-free. When in doubt, you could start fresh by deleting the `.aux` file before compiling.

-
+1 for the explanation about the aux file. I think that this is what happened to Peteris. – Bruno Le Floch Jan 14 '12 at 0:40

Okay, the `\section{\\$\_}` works this fine. I closed and opened the tex file and it started working by itself.

-