summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ltxmisc/underscore.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/ltxmisc/underscore.sty')
-rw-r--r--Master/texmf-dist/tex/latex/ltxmisc/underscore.sty116
1 files changed, 66 insertions, 50 deletions
diff --git a/Master/texmf-dist/tex/latex/ltxmisc/underscore.sty b/Master/texmf-dist/tex/latex/ltxmisc/underscore.sty
index a274b39e521..f0cfb895d19 100644
--- a/Master/texmf-dist/tex/latex/ltxmisc/underscore.sty
+++ b/Master/texmf-dist/tex/latex/ltxmisc/underscore.sty
@@ -1,13 +1,14 @@
-% underscore.sty 12-Oct-2001 Donald Arseneau asnd@triumf.ca
+% underscore.sty 21-Sep-2005 Donald Arseneau asnd@triumf.ca
% Make the "_" character print as "\textunderscore" in text.
-% Copyright 1998,2001 Donald Arseneau; Distribute freely if unchanged.
+% Copyright 1998,2001,2005,2006 Donald Arseneau;
+% License: LPPL version 1.2 or later.
% Instructions follow after the definitions.
-\ProvidesPackage{underscore}[2001/10/12]
+\ProvidesPackage{underscore}[2006/09/13]
\begingroup
\catcode`\_=\active
- \gdef_{% \relax % No relax gives a small vulnerability in alignments
+ \gdef _{% \relax % No relax gives a small vulnerability in alignments
\ifx\if@safe@actives\iftrue % must be outermost test!
\string_%
\else
@@ -18,13 +19,20 @@
\else \protect_%
\fi\fi
\fi}
+ \global\let\ActiveUnderscore=_
+ \gdef\normalUnderscoreDef{\let_\ActiveUnderscore}
\endgroup
% At begin: set catcode; fix \long \ttdefault so I can use it in comparisons;
+% reapply definition of active _ in output routine (\@firstofone to strip
+% away braces, so avoiding deeper nesting).
\AtBeginDocument{%
{\immediate\write\@auxout{\catcode\number\string`\_ \string\active}}%
\catcode\string`\_\string=\active
\edef\ttdefault{\ttdefault}%
+ \output=\expandafter\expandafter\expandafter
+ {\expandafter\expandafter\expandafter\normalUnderscoreDef
+ \expandafter\@firstofone\the\output}%
}
\newcommand{\BreakableUnderscore}{\leavevmode\nobreak\hskip\z@skip
@@ -34,6 +42,7 @@
\DeclareRobustCommand{\_}{%
\ifmmode \nfss@text{\textunderscore}\else \BreakableUnderscore \fi}
+
\let\usc@dischyph\@dischyph
\DeclareOption{nohyphen}{\def\usc@dischyph{\discretionary{}{}{}}}
\DeclareOption{strings}{\catcode`\_=\active}
@@ -50,6 +59,7 @@
\do\@input \do\@iinput \do\InputIfFileExists
\do\ref \do\pageref \do\newlabel
\do\bibitem \do\@bibitem \do\cite \do\nocite \do\bibcite
+ \do\Ginclude@graphics \do\@setckpt
}
% Macro to redefine a macro to pre-process its string argument
@@ -91,23 +101,24 @@
\endinput
-underscore.sty 12-Oct-2001 Donald Arseneau
+underscore.sty 13-Sep-2006 Donald Arseneau
Features:
~~~~~~~~~
-\_ prints an underscore so that the hyphenation of constituent words
-is not affected and hyphenation is permitted after the underscore.
-For example, "compound\_fracture" hyphenates as com- pound_- frac- ture.
+The "\_" command (which normally prints an underscore character or
+facsimile) is altered so that the hyphenation of constituent words
+is not affected, and hyphenation is permitted after the underscore.
+For example, "compound\_fracture" hyphenates as com- pound\_- frac- ture.
If you prefer the underscore to break without a hyphen (but still with
the same rules for explicit hyphen-breaks) then use the [nohyphen]
package option.
-A simple _ acts just like \_ in text mode, but makes a subscript in
-math mode: activation_energy $E_a$
+A simple "_" acts just like "\_" in text mode, but makes a subscript
+in math mode: activation_energy $E_a$
Both forms use an underscore character if the font encoding contains
one (e.g., "\usepackage[T1]{fontenc}" or typewriter fonts in any encoding),
-but they use a rule if the there is no proper character.
+but they use a rule if there is no proper character.
Deficiencies:
~~~~~~~~~~~~~
@@ -127,22 +138,23 @@ Option: [strings]
The default operation is quite simple and needs no customization; but
you must avoid using "_" in any place where LaTeX uses an argument as
a string of characters for some control function or as a name. These
-include the tags for \cite and \ref, file names for \input, \include,
-and \includegraphics, environment names, counter names, and placement
-parameters (like "[t]"). The problem with these contexts is that they
-are `moving arguments' but LaTeX does not `switch on' the \protect
-mechanism for them.
+include the tags for "\cite" and "\ref", file names for "\input",
+"\include", and "\includegraphics", environment names, counter names,
+and placement parameters (like "[t]"). The problem with these contexts
+is that they are `moving arguments' but LaTeX does not `switch on' the
+"\protect" mechanism for them.
If you need to use the underscore character in these places, the package
-option [strings] is provided to redefine commands taking a string argument
-so that the argument is protected (with \protect -> \string). The list
-of commands is given in "\UnderscoreCommands", with "\do" before each,
-covering \cite, \ref, \input, and their variants. Not included are many
-commands regarding font names, everything with counter names, environment
-names, page styles, and versions of \ref and \cite defined by external
-packages (e.g. \vref and \citeyear).
-
-You can add to the list of supported commands by defining \UnderscoreCommands
+option [strings] is provided to redefine commands that take such a string
+argument so that protection is applied (with "\protect" being "\string").
+The list of commands is given in "\UnderscoreCommands", with "\do" before
+each; plus several others covering "\input", "\includegraphics, "\cite",
+"\ref", and their variants. Not included are many commands regarding font
+names, everything with counter names, environment names, page styles, and
+versions of "\ref" and "\cite" defined by external packages (e.g., "\vref"
+and "\citeyear").
+
+You can add to the list of supported commands by defining "\UnderscoreCommands"
before loading this package; e.g.
\usepackage{chicago}
@@ -155,19 +167,17 @@ before loading this package; e.g.
Not all commands can be supported this way! Only commands that take a
string argument *first* can be protected. One optional argument before
-the string argument is also permitted, as exemplified by \cite: both
-\cite{tags} and \cite[text]{tags} are allowed. A command like
-\@addtoreset which takes two counter names as arguments could not
-be protected by adding it to \UnderscoreCommands.
+the string argument is also permitted, as exemplified by "\cite": both
+"\cite{tags}" and "\cite[text]{tags}" are allowed. A command like
+"\@addtoreset" which takes two counter names as arguments could not
+be protected by listing it in "\UnderscoreCommands".
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!! When you use the [strings] option, you must load this package !!
-!! last (or nearly last). !!
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+*When you use the [strings] option, you must load this package
+last* (or nearly last).
There are two reasons: 1) The redefinitions done for protection must come
after other packages define their customized versions of those commands.
-2) The [strings] option requires the _ character to be activated immediately
+2) The [strings] option requires the "_" character to be activated immediately
in order for the cite and ref tags to be read properly from the .aux file
as plain strings, and this catcode setting might disrupt other packages.
@@ -176,56 +186,62 @@ and will be a complete fix for most documents without the [strings] option.
Many add-on packages are compatible with babel, so they will get the
strings protection also. However, there are several commands that are
not covered by babel, but can easily be supported by the [strings] and
-\UnderscoreCommands mechanism. Beware that using both [strings] and babel
-may lead to conflicts, but does appear to work (load babel last).
+"\UnderscoreCommands" mechanism. Beware that using both [strings] and
+babel might lead to conflicts, but none are seen yet (load babel last).
Implementation Notes:
~~~~~~~~~~~~~~~~~~~~~
The first setting of "_" to be an active character is performed in a local
group so as to not interfere with other packages. The catcode setting
-is repeated with \AtBeginDocument so the definition is in effect for the
+is repeated with "\AtBeginDocument" so the definition is in effect for the
text. However, the catcode setting is repeated immediately when the
[strings] option is detected.
The definition of the active "_" is essentially:
+
\ifmmode \sb \else \BreakableUnderscore \fi
+
where "\sb" retains the normal subscript meaning of "_" and where
"\BreakableUnderscore" is essentially "\_". The rest of the definition
-handles the "\protect"ion without causing \relax to be inserted before
+handles the "\protect"ion without causing "\relax" to be inserted before
the character.
-\BreakableUnderscore uses "\nobreak\hskip\z@skip" to separate the
+"\BreakableUnderscore" uses "\nobreak\hskip\z@skip" to separate the
underscore from surrounding words, thus allowing TeX to hyphenate them,
but preventing free breaks around the underscore. Next, it checks the
current font family, and uses the underscore character from tt fonts or
-otherwise \textunderscore (which is a character or rule depending on
+otherwise "\textunderscore" (which is a character or rule depending on
the font encoding). After the underscore, it inserts a discretionary
hyphenation point as "\usc@dischyph", which is usually just "\-"
except that it still works in the tabbing environment, although it
will give "\discretionary{}{}{}" under the [nohyphen] option. After
that, another piece of non-breaking interword glue is inserted.
Ordinarily, the comparison "\ifx\f@family\ttdefault" will always fail
-because \ttdefault is `long' where \f@family is not (boooo hisss), but
-\ttdefault is redefined to be non-long by "\AtBeginDocument".
+because "\ttdefault" is `long' whereas "\f@family" is not (boooo hisss),
+but "\ttdefault" is redefined to be non-long by "\AtBeginDocument".
The "\_" command is then defined to use "\BreakableUnderscore".
If the [strings] option is not given, then that is all!
Under the [strings] option, the list of special commands is processed to:
-- retain the original command as \US_command (\US_ref)
-- redefine the command as \US@prot\US_command for ordinary commands
- (\ref -> \US@prot\US_ref) or as \US@protopt\US_command when an optional
- argument is possible (\bibitem -> \US@protopt\US_bibitem).
-- self-protecting commands (\cite) retain their self-protection.
+
+ - retain the original command as "\US_"*command* (e.g., "\US_ref")
+ - redefine the command as "\US@prot\US_command" for ordinary commands
+ ("\US@prot\US_ref") or as "\US@protopt\US_command" when an optional
+ argument is possible (e.g., "\US@protopt\US_bibitem").
+ - self-protecting commands ("\cite") retain their self-protection.
+
Diagnosing the state of the pre-existing command is done by painful
-contortions involving \meaning.
+contortions involving "\meaning".
-\US@prot and \US@protopt read the argument, process it with \protect
-enabled, then invoke the saved \US_command.
+"\US@prot" and "\US@protopt" read the argument, process it with
+"\protect" enabled, then invoke the saved "\US_command".
Modifications:
~~~~~~~~~~~~~~
+13-Sep-2006 Reassert my definition in the output routine (listings).
+21-Sep-2005 \includegraphics safe.
12-Oct-2001 Babel (safe@actives) compatibility and [nohyphen] option.
Test file integrity: ASCII 32-57, 58-126: !"#$%&'()*+,-./0123456789