When not in math mode, \verb|_| and \_ both give underscores, but of a
different style. Let's call the style of the first the "verbatim" one and the
style of the second the "ordinary" one.
When in math mode, both \verb|_| and \_ give the ordinary underscore! How can I
get the verbatim underscore in math mode?
My first guess was $\mbox{\verb|_|}$ but that gives an error message.
Best wishes, --Jan (vdb...@wins.uia.ac.be)
Thinking on the same lines, $\hbox{\verb|_|}$ will work. The problem
with just \verb|_| is that \mathcode`_ = "8000, so when TeX comes to
typeset a _ in math mode, it uses its \active meaning. You could
always change the \mathcode to get around this problem. The reason
\mbox doesn't work is that it reads its argument before the inner
\verb gets a chance to change \catcodes. latex.tex defines:
\def\mbox#1{\leavevmode\hbox{#1}}
This might just as well be:
\def\mbox{\leavevmode\hbox}
which would be marginally more efficient and would avoid \catcode
problems like the above. (Well, the original definition allows you to
say, e.g., "\mbox X" instead of "\mbox{X}", but I don't know if
anybody uses this capability.)
,
Eamonn
"The future belongs to those who can smell it coming." -- RuPaul
Jan> I'm using LaTeX.
Jan> When not in math mode, \verb|_| and \_ both give underscores, but of a
Jan> different style. Let's call the style of the first the "verbatim" one and the
Jan> style of the second the "ordinary" one.
Jan> When in math mode, both \verb|_| and \_ give the ordinary underscore! How can I
Jan> get the verbatim underscore in math mode?
If you pick up Rainer Sch\"opf's verbatim.sty, Your first try would work:
$\verb|_|$ looks like \verb|_|
verbatim.sty is available from most places, at stuttgart it is
soft/tex/macros/latex/distribs/verbatim/*
Jan> My first guess was $\mbox{\verb|_|}$ but that gives an error message.
You can not use \verb inside the argument to a command.
If you dont want to use verbatim style you need to figure out how to
get the `_' character from the \tt font into a math formula.
Without going into details of font choices NFSS or not etc, one way
that will work is to go:
$\mbox{\tt\string_}$
David