You can do even better: say
\usepackage[T1]{fontenc}
\catcode`\_=12
in your preamble and you'll be allowed to use the underscore as a printable character anywhere (requires a T1-encoded font, so the first line). For subscripts you can then use \sb
.
A command for temporary escaping the underscore can be the following:
\makeatletter
\newcommand{\escapeus}{\begingroup\@makeother\_\@escapeus}
\newcommand*{\@escapeus}[1]{#1\endgroup}
\makeatother
that, however, will not be usable in the argument of any command, because of the change in the category code (still requires a T1-encoded font).
If T1-encoded fonts are not available, something more complicated is needed:
\makeatletter
\newcommand{\escapeus}{\begingroup\@activeus\@escapeus}
\newcommand*{\@escapeus}[1]{#1\endgroup}
\begingroup\lccode`\~=`\_\relax
\lowercase{\endgroup\def\@activeus{\catcode`\_=\active \let~\_}}
\makeatother
Again, the \escapeus
command cannot be used as the argument of another command. If you really need it there's a way:
\makeatletter
\DeclareRobustCommand*{\escapeus}[1]{%
\begingroup\@activeus\scantokens{#1\endinput}\endgroup}
\begingroup\lccode`\~=`\_\relax
\lowercase{\endgroup\def\@activeus{\catcode`\_=\active \let~\_}}
\makeatother
strings
option (it worked fine for me in a quick test). Wrapping words with underscores in an\esc_underscore
command is not really more convenient or readable than manually escaping the underscores. Perhaps ask a new question about the[strings]underscore
issue including a minimal example that reproduces your problemstrings
option}seems to work just fine for me, so not exactly sure what the problemunderscore
package, which doesn't work for fuenfundachtzig, so it's not really a duplicate.