summaryrefslogtreecommitdiffstats
path: root/doc/api/fixunder.sty
blob: b7ae58dbf3dee813516464211b8a961b26be2aee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% fixunder.sty,  31 May 1990, John T. Kohl
%
% The contents of this file are in the public domain.
%
%
% play games with _ to make it active and to provide a reasonable _
% character (from \tt in most cases), and a discretionary word-break point.

%
% Some \makeunder... macros for convenience in setting catcodes.
%
\def\makeunderactive{\catcode`\_=\active\relax}
\def\makeunderother{\catcode`\_=12\relax}
\def\makeunderletter{\catcode`\_=11\relax}
\def\makeundernormal{\catcode`\_=8\relax}
\makeunderother
\def\cctwlunder{_}

%
% The hair here is to allow things like \index to work reasonably with
% the new definition of underscore when the argument to index is part of
% a macro replacement and as such gets tokenized before \index is
% evaluated.
% [in the normal case at top-level, \index{foo_bar} works since \index
% does some hair to make _ into a reasonable character code, and \index
% does NOT use a macro expansion.  If you have something like
% \def\foo#1#2{\index{#1} bar #2}
% then \foo{baz_quux}{frobnitz} will result in baz_quux getting
% tokenized BEFORE \foo is expanded, so that the catcode hair in \index
% is to no avail.]
%
% \underrealfalse declares that you want to replace with the \tt _;
% \underrealtrue declares that you want to replace with \char95 (ASCII _).
%
% for things like \index which write things out to files, set
% \underrealfalse before evaluating the \index macro, and what actually
% gets written to the file is an _, rather than something like
% {\leavemode \kern... } (the typical definition of \_).
%
% the above example would then be
% \def\foo#1#2{\underrealfalse\index{#1}\underrealtrue bar #2}
%

\newif\ifunderreal
\underrealfalse
\makeunderactive
\def_{\ifunderreal\cctwlunder\else\leavevmode {\tt \cctwlunder}\discretionary{}{}{}\fi}
\let\_=_