douglis@cs.vu.nl (Fred Douglis) (01/17/91)
I'm editing a document that includes a fair number of underscores. If I include "foo_bar" then LaTeX complains that I left out the $ for math mode. But "foo\_bar" gets awfully monotonous. Can anyone tell me what magic might be necessary to redefine "_" to have its normal meaning? (A "normal_underscore.sty" file would be ideal. :-) -- ============================================================================= Fred Douglis, Vrije Universiteit, douglis@cs.vu.nl +31 20 548-5777 =============================================================================
marcel@cs.caltech.edu (Marcel van der Goot) (01/17/91)
In <8763@star.cs.vu.nl> Fred Douglis (douglis@cs.vu.nl) asks > Can anyone tell me what magic might be necessary to redefine "_" to > have its normal meaning? If you always want to use an _ as just an _, you can say \catcode`\_=13 \let_=\_ (actually, the second line is not necessary, it is already done in plain.tex --- not documented in the TeXbook) If you also want to write subscripts now and then, you can make " into a subscript character by saying \catcode`\"=13 Then you can write $x"0$. It disables other usage of " though. A slightly more sophisticated solution is to forget the above and instead write \catcode`\_=13 {\catcode`*=8 \gdef_{\ifmmode\let\next=*\else\let\next=\_\fi\next} } This makes _ into a normal underscore when used in normal text, but when you use it in mathmode it is still the underscore character. So you can write some_identifier $= x_0$ but not $$some_identifier = x_0$$ Which solution is most suitable depends on your application. Marcel van der Goot marcel@vlsi.cs.caltech.edu
eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (01/17/91)
douglis@cs.vu.nl (Fred Douglis) writes: >I'm editing a document that includes a fair number of underscores. If I >include "foo_bar" then LaTeX complains that I left out the $ for math >mode. But "foo\_bar" gets awfully monotonous. Can anyone tell me what >magic might be necessary to redefine "_" to have its normal meaning? >(A "normal_underscore.sty" file would be ideal. :-) In fact you don't want to make _ nonspecial (really you don't, let me convince you), but special in another way. \catcode`\_=12 makes the underscore normal. Try it, and see that it doesn't do what you want, unless you're in typewriter mode. Reason is that there is no underscore in TeX's roman font. \catcode`\_=13 \def_{\_} will do what you want: the underscore now becomes by itself a macro that xpands in to the \_ command. And now you're in trouble if you wnat to do mathematics, so: \everymath{\catcode`\_=8 } \everydisplay=\everymath Victor.
eijkhout@s41.csrd.uiuc.edu (Victor Eijkhout) (01/17/91)
marcel@cs.caltech.edu (Marcel van der Goot) writes: >In <8763@star.cs.vu.nl> Fred Douglis (douglis@cs.vu.nl) asks >> Can anyone tell me what magic might be necessary to redefine "_" to >> have its normal meaning? >If you always want to use an _ as just an _, you can say > \catcode`\_=13 > \let_=\_ That's a tad better than what I suggested. >If you also want to write subscripts now and then, you can make " into >a subscript character by saying > \catcode`\"=13 The 13 should be 8. > Marcel van der Goot > marcel@vlsi.cs.caltech.edu Netherlands rule! Victor.