[Python-checkins] python/dist/src/Doc/texinputs underscore.sty, NONE, howto.cls,, manual.cls,, python.sty,,

jhylton@users.sourceforge.net jhylton at users.sourceforge.net
Sun Oct 16 07:24:32 CEST 2005

Update of /cvsroot/python/python/dist/src/Doc/texinputs
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27718/Doc/texinputs

Modified Files:
      Tag: ast-branch
	howto.cls manual.cls python.sty 
Added Files:
      Tag: ast-branch
Log Message:
Merge head to branch (for the last time)

--- NEW FILE: underscore.sty ---
% underscore.sty     12-Oct-2001   Donald Arseneau   asnd at triumf.ca
% Make the "_" character print as "\textunderscore" in text.
% Copyright 1998,2001 Donald Arseneau;  Distribute freely if unchanged.
% Instructions follow after the definitions.


 \gdef_{% \relax % No relax gives a small vulnerability in alignments
   \ifx\if at safe@actives\iftrue % must be outermost test!
      \ifx\protect\@typeset at protect
         \ifmmode \sb \else \BreakableUnderscore \fi
         \ifx\protect\@unexpandable at protect \noexpand_%
         \else \protect_%

% At begin: set catcode; fix \long \ttdefault so I can use it in comparisons; 
  {\immediate\write\@auxout{\catcode\number\string`\_ \string\active}}%

\newcommand{\BreakableUnderscore}{\leavevmode\nobreak\hskip\z at skip
 \ifx\f at family\ttdefault \string_\else \textunderscore\fi
 \usc at dischyph\nobreak\hskip\z at skip}

  \ifmmode \nfss at text{\textunderscore}\else \BreakableUnderscore \fi}

\let\usc at dischyph\@dischyph
\DeclareOption{nohyphen}{\def\usc at dischyph{\discretionary{}{}{}}}

\ifnum\catcode`\_=\active\else \endinput \fi

%%%%%%%%   Redefine commands that use character strings   %%%%%%%%

  \do\include \do\includeonly
  \do\@input \do\@iinput \do\InputIfFileExists
  \do\ref \do\pageref \do\newlabel
  \do\bibitem \do\@bibitem \do\cite \do\nocite \do\bibcite

% Macro to redefine a macro to pre-process its string argument
% with \protect -> \string.
\def\do#1{% Avoid double processing if user includes command twice!
   \edef\@tempb{\meaning#1}% Check if macro is just a protection shell...
   \ifx\@tempb\@tempc % just a shell: hook into the protected inner command
       \csname \expandafter\@gobble\string#1 \expandafter\endcsname
   \else % Check if macro takes an optional argument
     \edef\@tempc{\noexpand\@tempd \csname
     \if \expandafter\@tempa\@tempb \relax 12\@tempa % then no optional arg
       \@tempc #1\US at prot
     \else  % There is optional arg
       \@tempc #1\US at protopt


\def\US at prot#1#2{\let\@@protect\protect \let\protect\string
  \edef\US at temp##1{##1{#2}}\restore at protect\US at temp#1}
\def\US at protopt#1{\@ifnextchar[{\US at protarg#1}{\US at prot#1}}
\def\US at protarg #1[#2]{\US at prot{{#1[#2]}}}

\let\do\relax \let\@tempd\relax  % un-do



underscore.sty    12-Oct-2001  Donald Arseneau

\_ 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.
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$

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.

The skips and penalties ruin any kerning with the underscore character
(when a character is used).  However, there doesn't seem to be much, if
any, such kerning in the ec fonts, and there is never any kerning with
a rule.

You must avoid "_" in file names and in cite or ref tags, or you must use 
the babel package, with its active-character controls, or you must give 
the [strings] option, which attempts to redefine several commands (and 
may not work perfectly).  Even without the [strings] option or babel, you 
can use occasional underscores like: "\include{file\string_name}".

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.

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
before loading this package; e.g.

   \newcommand{\UnderscoreCommands}{%   (\cite already done)
     \do\citeNP \do\citeA \do\citeANP \do\citeN \do\shortcite
     \do\shortciteNP \do\shortciteA \do\shortciteANP \do\shortciteN
     \do\citeyear \do\citeyearNP

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.

!! 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
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.

The babel package implements a protection mechanism for many commands,
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).

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
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
the character.

\BreakableUnderscore uses "\nobreak\hskip\z at 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
the font encoding).  After the underscore, it inserts a discretionary
hyphenation point as "\usc at 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 at family\ttdefault" will always fail 
because \ttdefault is `long' where \f at 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 at prot\US_command for ordinary commands
  (\ref -> \US at prot\US_ref) or as \US at protopt\US_command when an optional
  argument is possible (\bibitem -> \US at 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.

\US at prot and \US at protopt read the argument, process it with \protect
enabled, then invoke the saved \US_command.

12-Oct-2001  Babel (safe at actives) compatibility and [nohyphen] option.

Test file integrity:  ASCII 32-57, 58-126:  !"#$%&'()*+,-./0123456789

Index: howto.cls
RCS file: /cvsroot/python/python/dist/src/Doc/texinputs/howto.cls,v
retrieving revision
retrieving revision
diff -u -d -r1.13.2.1 -r1.13.2.2
--- howto.cls	7 Jan 2005 06:57:36 -0000
+++ howto.cls	16 Oct 2005 05:23:58 -0000
@@ -50,7 +50,8 @@
   \py at doHorizontalRule
-  \@ifundefined{pdfinfo}{}{{
+  \ifpdf
+    \begingroup
     % This \def is required to deal with multi-line authors; it
     % changes \\ to ', ' (comma-space), making it pass muster for
     % generating document info in the PDF file.
@@ -59,7 +60,8 @@
       /Author (\@author)
       /Title (\@title)
-  }}
+    \endgroup
+  \fi
     {\rm\Huge\py at HeaderFamily \@title} \par
     {\em\large\py at HeaderFamily \py at release\releaseinfo} \par

Index: manual.cls
RCS file: /cvsroot/python/python/dist/src/Doc/texinputs/manual.cls,v
retrieving revision
retrieving revision
diff -u -d -r1.18.2.1 -r1.18.2.2
--- manual.cls	7 Jan 2005 06:57:36 -0000
+++ manual.cls	16 Oct 2005 05:23:58 -0000
@@ -64,7 +64,8 @@
     \py at doHorizontalRule%
-    \@ifundefined{pdfinfo}{}{{
+    \ifpdf
+      \begingroup
       % This \def is required to deal with multi-line authors; it
       % changes \\ to ', ' (comma-space), making it pass muster for
       % generating document info in the PDF file.
@@ -73,7 +74,8 @@
         /Author (\@author)
         /Title (\@title)
-    }}
+      \endgroup
+    \fi
       {\rm\Huge\py at HeaderFamily \@title \par}%
       {\em\LARGE\py at HeaderFamily \py at release\releaseinfo \par}

Index: python.sty
RCS file: /cvsroot/python/python/dist/src/Doc/texinputs/python.sty,v
retrieving revision
retrieving revision
diff -u -d -r1.96.2.2 -r1.96.2.3
--- python.sty	7 Jan 2005 06:57:36 -0000
+++ python.sty	16 Oct 2005 05:23:58 -0000
@@ -7,6 +7,7 @@
              [1998/01/11 LaTeX package (Python markup)]
 % Uncomment these two lines to ignore the paper size and make the page 
 % size more like a typical published manual.
@@ -541,28 +542,6 @@
                                     {\reset at font\normalsize\py at HeaderFamily}}
-% This gets the underscores closer to the right width; the only change
-% from standard LaTeX is the width specified.
-  \leavevmode \kern.06em\vbox{\hrule\@width.55em}}
-% Underscore hack (only act like subscript operator if in math mode)
-% The following is due to Mark Wooding (the old version didn't work with
-% Latex 2e.
-  \ifmmode_\else\textunderscore\fi%
-  \AtBeginDocument{\catcode`\_\active\def_{\hackscore{}}}%
 % Now for a lot of semantically-loaded environments that do a ton of magical
 % things to get the right formatting and index entries for the stuff in
 % Python modules and C API.
@@ -1202,7 +1181,7 @@
-% \seelink{url}{link text}
+% \seelink{url}{link text}{why it's interesting}
 \newcommand{\py at seelink}[3]{%

More information about the Python-checkins mailing list