% \iffalse meta-comment % % Copyright 1994 the LaTeX3 project and the individual authors. % All rights reserved. For further copyright information see the file % legal.txt, and any other copyright indicated in this file. % % This file is part of the LaTeX2e system. % ---------------------------------------- % % This system is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. % % % IMPORTANT NOTICE: % % For error reports in case of UNCHANGED versions see bugs.txt. % % Please do not request updates from us directly. Distribution is % done through Mail-Servers and TeX organizations. % % You are not allowed to change this file. % % You are allowed to distribute this file under the condition that % it is distributed together with all files mentioned in manifest.txt. % % If you receive only some of these files from someone, complain! % % You are NOT ALLOWED to distribute this file alone. You are NOT % ALLOWED to take money for the distribution or use of either this % file or a changed version, except for a nominal charge for copying % etc. % \fi % \iffalse %% File: ltfntcmd %% %<*driver> % \fi \ProvidesFile{ltfntcmd.dtx} [1994/05/25 v3.3j LaTeX Kernel (Font commands)] % \iffalse \documentclass{ltxdoc} \GetFileInfo{ltfntcmd.dtx} \title{\filename} \date{\filedate} \author{Frank Mittelbach, Chris Rowley} \begin{document} \maketitle \DocInput{\filename} \end{document} % % \fi % % \CheckSum{218} %% \CharacterTable %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z %% Digits \0\1\2\3\4\5\6\7\8\9 %% Exclamation \! Double quote \" Hash (number) \# %% Dollar \$ Percent \% Ampersand \& %% Acute accent \' Left paren \( Right paren \) %% Asterisk \* Plus \+ Comma \, %% Minus \- Point \. Solidus \/ %% Colon \: Semicolon \; Less than \< %% Equals \= Greater than \> Question mark \? %% Commercial at \@ Left bracket \[ Backslash \\ %% Right bracket \] Circumflex \^ Underscore \_ %% Grave accent \` Left brace \{ Vertical bar \| %% Right brace \} Tilde \~} % % \iffalse % Copyright (C) 1994-1994 Frank Mittelbach and Chris Rowley % all rights reserved. % \fi % % \changes{v2.0b}{1993/05/05}{Removed all LaTeX related cmds} % \changes{v3.0a}{1993/12/11}{Complete reworking of all text commands, % using just one creator function} % \changes{v3.0a}{1993/12/11}{newfontswitch command corrected and % changed} % \changes{v3.0a}{1993/12/11}{newcommands replaced by defs} % \changes{v3.0a}{1993/12/11}{italic correction now put in front of % penalty before glue} % \changes{v3.0b}{1993/12/19}{\cmd{\@pdef} comand added} % \changes{v3.0b}{1993/12/19}{Other tidying} % \changes{v3.0b}{1993/12/19}{Made \cmd{\@newfontswitch} produce an % error if command already exists, and added \cmd{\@renewfontswitch}, % ASAJ} % \changes{v3.0b}{1993/12/19}{Untidying added, so this is now a % TEMPORARY version.} % \changes{v3.0b}{1993/12/19}{Some more tidying done} % \changes{v3.1b}{1994/01/31}{\cmd{\@normalsize} no longer defined} % \changes{v3.2a}{1994/03/15}{Adapted to mass formatting} % \changes{v3.2a}{1994/03/15}{Removed defs of short-forms and all % sizes except \cmd\normalize} % \changes{v3.2a}{1994/03/15}{Removed \cmd{\@renewfontswitch}} % \changes{v3.2a}{1994/03/15}{Changed \cmd\/ to \cmd{\@@italiccorr}} % \changes{v3.2b}{1994/04/14}{Macros renamed to non-private forms, JB} % \changes{v3.3a}{1994/04/20}{New implementation of \cmd\nocorr} % \changes{v3.3a}{1994/04/20}{Documentation up-dated} % \changes{v3.3b}{1994/04/30}{Documentation up-dated and tidied} % \changes{v3.3b}{1994/04/30}{Title changed} % \changes{v3.3b}{1994/04/30}{Prefix frag@ changed to frag in % \cmd{\@protecteddef}} % \changes{v3.3b}{1994/04/30}{Warning changed to info message in % \cmd{\@protecteddef}} % \changes{v3.3c}{1994/05/05}{Corrected \cmd{\@fontswitch}} % \changes{v3.3d}{1994/05/08}{Removed \cmd{\@undefinedfonterror}} % \changes{v3.3f}{1994/05/09}{Replaced all \cmd\next by % \cmd\@let@token and undo change 3.3e} % \changes{v3.3g}{1994/05/13}{Replaced \cmd\@protecteddef by % \cmd\DeclareRobustCommand} % \changes{v3.3h}{1993/05/20}{Use new error commands} % \changes{v3.3i}{1993/05/24}{Tidying and typos fixed} % \changes{v3.3j}{1993/05/25}{Insertion of \cs{afterggroup}s to % implement \cs{nocorr} moved to the end of the group} % % \title{The \texttt{fontcmds} file, providing % NFSS2 font commands} % \author{Frank Mittelbach \and Chris Rowley} % % \def \ie {i.e.~} % \def \eg {e.g.~} % % \def \dst {{\normalfont\scshape docstrip}} % \def \NFSS {\textsf{NFSS}} % % \maketitle % % \begin{abstract} % The commands defined in this file \texttt{fontcmds} are % part of the kernel code for \LaTeXe/NFSS2. % % It is also meant to serve as documentation for package writers since % it demonstrates how to define high-level font changing commands % using a small number of creator functions. % \end{abstract} % % \section{Introduction} % % Font changes such as |\bfseries|, |\sffamily|, etc.\ are % declarations; this means that their scope is delimited by the % grouping structure, either by the next |\end| of some environment or % by explicitly using a group, e.g., writing something like % |{\bfseries...}| in the source. If you make the mistake of writing % |\bfseries{...}| (thinking of |\bfseries| as a command with one % argument) then the result is rather striking. % % Font declarations are an artifact of the \TeX{} system and for % several reasons it is better to avoid them on the user level % whenever possible. In \LaTeX3 they will probably all be % replaced by environments and by font commands taking one argument. % % This file defines a creator function for such declarative font % switches. This function creates commands which can be used in % both math and text. % % This file also defines a number of high-level commands (all % starting with |\text..|) that have one argument and typeset this % argument in the requested way. Thus these commands are for % typesetting short pieces of text in a specific family, series or % shape. These are all produced as examples of the use of a creator % function which is itself also defined in this file. % % Table~\ref{tab:fontcmds} shows all these high-level commands in % action. A further advantage of using these commands is that they % automatically take care of any necessary italic correction on either % side of their argument. % \begin{table}[t] % \begin{center} % \begin{tabular}{lll} % \textit{Command} & \textit{Corresponds to }& \textit{Action} \\[4pt] % |\textrm{..}| & |\rmfamily| & % Typeset argument in roman family \\ % |\textsf{..}| & |\sffamily| & % Typeset argument in \textsf{sans serif} family \\ % |\texttt{..}| & |\ttfamily| & % Typeset argument in \texttt{typewriter} family % \\[2pt] % |\textmd{..}| & |\mdseries| & % Typeset argument in medium series \\ % |\textbf{..}| & |\bfseries| & % Typeset argument in \textbf{bold} series \\[2pt] % |\textup{..}| & |\upshape| & % Typeset argument in normal shape \\ % |\textit{..}| & |\itshape| & % Typeset argument in \textit{italic} shape \\ % |\textsl{..}| & |\slshape| & % Typeset argument in \textsl{slanted} shape \\ % |\textsc{..}| & |\scshape| & % Typeset argument in \textsc{small caps} shape % \\[2pt] % |\emph{..}| & |\em| & % Typeset argument \emph{emphasized} % \end{tabular} % \end{center} % \caption{Font-change commands with arguments} % \label{tab:fontcmds} % \begin{quote} % The font change commands provided with the package % \texttt{fontcmds} all start with |\text..| to emphasize that they % are for use in normal text and to be easily memorable. They % automatically take care of any necessary italic correction on either % side of the argument. % \end{quote} % \end{table} % % Thus, when using such commands, one does not have to worry about % forgetting the italic correction when changing fonts. Only in very % few situations is this additional space wrong but, for example, most % typographers recommend omitting the italic correction if a small % punctuation character, like a comma, directly follows the font % change. Since the amount of correction required is partly a matter % of taste, you can define in what situations the italic correction % should be suppressed. This is done by puttiing the characters that % should cancel a preceding italic correction in the list % |\nocorrlist|.\footnote{Any package that changes the % \texttt{\string\catcode} of a character inside % \texttt{\string\nocorrlist} must then explicitly reset the list. % Otherwise the changed character will no longer be recognized % by the suppression algorithm.} % The default definition for this list is produced by the following. % \begin{verbatim} % \newcommand \nocorrlist {,.} % \end{verbatim} % It is best to declare the most often used characters first, because % this will make the processing slightly faster. For example, % \begin{verbatim} % \emph{When using the \NFSS{} high-level commands, % the \emph{proper} use of italic corrections is % automatically taken care of}. Only % \emph{sometimes} one has to help \LaTeX{} by % adding a \verb=\nocorr= command. % \end{verbatim} % which results in: % \begin{quote} % \emph{When using the \NFSS{} high-level commands, % the \emph{proper} use of italic corrections is % automatically taken care of}. Only % \emph{sometimes} one has to help \LaTeX{} by % adding a \verb=\nocorr= command. % \end{quote} % % In contrast, the use of the declaration forms is often more % appropriate when you define your own commands or environments. % \begin{verbatim} % \newenvironment{bfitemize}{\begin{itemize}\normalfont\bfseries} % {\end{itemize}} % \begin{bfitemize} % \item This environment produces boldface items. % \item It is defined in terms of \LaTeX's % \texttt{itemize} environment and NFSS % declarations. % \end{bfitemize} % \end{verbatim} % This gives: % \begin{quote} % \newenvironment{bfitemize} % {\begin{itemize}\normalfont\bfseries} % {\end{itemize}} % \begin{bfitemize} % \item This environment produces boldface items. % \item It is defined in terms of \LaTeX's % \texttt{itemize} environment and NFSS % declarations. % \end{bfitemize} % \end{quote} % % In addition to global customization of when to insert the italic % correction, it is of course sometimes necessary to explicitly insert % one with |\/|. % % It is also possible to suppress the italic correction % in individual instances. For this, the command |\nocorr| is provided. % % The |\nocorr| must appear as the first or last token inside the % braces of the argument of the |\text...| commands, at that end of % the text where you wish to suppress the italic correction. % % % It is worth pointing out here that inserting a |\/| in places where % it can have no function (\ie anywhere except immediately after a % slanted letter) is not an error---it will just be silently ignored. % Unfortunately this is not true if the redefinition of |\/| in {\tt % amstex.sty} is used as this version can cause space to be removed % immediately before the |\/|. % % \StopEventually{} % % % \section{The implementation} % % % \begin{macro}{\DeclareTextFontCommand} % \changes{v3.0a}{1993/12/11}{Macro changed} % \changes{v3.2b}{1994/04/14}{Macro renamed from \cmd{\@newtextcmd}} % This is the creator function for |\text..| commands. % It gives a warning if |\foo| or |\fragfoo| is already defined. % \changes{v3.0b}{1993/12/19}{Corrected and tidied} % % In math mode it simply puts the font declaration and text into a % box (possibly an automagically sized one). % % Otherwise it first scans the text to see where |\nocorr| occurs % within it. This sets the |\check@ic| commands to do what is % necessary concerning the italic correction at both ends. % % Note that it is necessary to put in the |\aftergroup\maybe@ic| at % the end of the group so that it comes after any other aftergroup % tokens and immediately before the following tokens. % It is also necessary to remove the |\fi| from the token list before % the group ends; this is done by adding an |\expandafter| just % before the closing brace. % \changes{v3.3j}{1993/05/25}{Insertion of \cs{aftergroup}s moved} % \changes{v3.3j}{1993/05/25}{\cs{expandafter} inserted} % \begin{macrocode} %<*2ekernel> \def \DeclareTextFontCommand #1#2{% \DeclareRobustCommand#1[1]{% \ifmmode \nfss@text{#2 ##1}% \else \leavevmode {\check@nocorr{##1}% #2\check@icl ##1\check@icr \expandafter}% \fi }% } % \end{macrocode} % \end{macro} % % \begin{macro}{\textrm} % \begin{macro}{\textsf} % \begin{macro}{\texttt} % \begin{macro}{\textnormal} % Now we define the |\text|\meta{family} commands in terms of the % above; |\texttt| does not look very nice! % \begin{macrocode} \DeclareTextFontCommand{\textrm}{\rmfamily} \DeclareTextFontCommand{\textsf}{\sffamily} \DeclareTextFontCommand{\texttt}{\ttfamily} \DeclareTextFontCommand{\textnormal}{\normalfont} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\textbf} % \begin{macro}{\textmd} % For the series attribute: % \begin{macrocode} \DeclareTextFontCommand{\textbf}{\bfseries} \DeclareTextFontCommand{\textmd}{\mdseries} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\textit} % \begin{macro}{\textsl} % \begin{macro}{\textsc} % \begin{macro}{\textup} % \changes{v3.0a}{1993/12/11}{Macros changed} % And for the shapes: % \begin{macrocode} \DeclareTextFontCommand{\textit}{\itshape} \DeclareTextFontCommand{\textsl}{\slshape} \DeclareTextFontCommand{\textsc}{\scshape} \DeclareTextFontCommand{\textup}{\upshape} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\emph} % \changes{v3.0a}{1993/12/11}{Macro changed} % Finally we have the |\em| font change declaration of \LaTeX. The % corresponding definition with argument is % \begin{macrocode} \DeclareTextFontCommand{\emph}{\em} % \end{macrocode} % \end{macro} % % \begin{macro}{\nocorr} % This is just a label, so it does nothing; it should also be % unexpandable. % \begin{macrocode} \let \nocorr \relax % \end{macrocode} % \end{macro} % % \begin{macro}{\check@nocorr} % \begin{macro}{\check@nocorr@} % \changes{v3.3a}{1994/04/20}{Macros added} % \begin{macro}{\check@icl} % \begin{macro}{\check@icr} % \changes{v3.3j}{1994/05/25}{Macros added} % \changes{v3.3i}{1993/05/25}{Insertion of \cs{aftergroup}s moved % and defaults set up for efficiency} % This checks for a |\nocorr| as the first token in its argument % and also for one in any other position not protected within % braces (the latter is treated as if it were at the end of the % argument). % \begin{macrocode} \def \check@nocorr #1{\check@nocorr@ #1\nocorr\@nil} \def \check@nocorr@ #1#2\nocorr#3\@nil {% % \end{macrocode} % The two checks are initialised here to their values in % the normal case. % \begin{macrocode} \let \check@icl \maybe@ic \def \check@icr {\aftergroup \maybe@ic}% \def \@tempa {\nocorr}% \def \@tempb {#1}% \def \@tempc {#3}% \ifx \@tempa \@tempb \ifx \@tempc \@empty % \end{macrocode} % In this case there is a |\nocorr| at the start but not at the % end, so |\check@icl| should be empty. % \begin{macrocode} \let \check@icl \@empty \else % \end{macrocode} % Otherwise there is a |\nocorr| both at the start and % elsewhere, so no italic corrections should be added. % \begin{macrocode} \let \check@icl \@empty \let \check@icr \@empty \fi \else \ifx \@tempc \@empty % \end{macrocode} % In this case there is no |\nocorr| anywhere, so we need to check % for an italic corection at both the beginning and the end. % \begin{macrocode} \else % \end{macrocode} % In this case there is no |\nocorr| at the start but there is one % elsewhere, so no |\aftergroup| is needed. % \begin{macrocode} \let \check@icr \@empty \fi \fi } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\maybe@ic} % \changes{v3.0a}{1993/12/11}{Macro name changed} % \begin{macro}{\maybe@ic@} % \changes{v3.0a}{1993/12/11}{Macro and name changed} % \task{CAR}{Make this more efficient by checking for non-characters % first and using \cs{if} test?} % These macros implement the italic correction. % \begin{macrocode} \def \maybe@ic {\futurelet\@let@token\maybe@ic@} \def \maybe@ic@ {% % \end{macrocode} % We first check to see if the current font is also sloped. % (But do not forget the message Rainer sent about an upright font % with non-zero slope!) % \begin{macrocode} \ifdim \fontdimen\@ne\font>\z@ \else \@tempswatrue % \end{macrocode} % It would be possible, but probably not worthwhile, to continue the % forward scan beyond any closing braces. % % \changes{v3.3a}{1994/04/20}{\cmd\nocorr etc removed from list of % tokens to check, leaving only punctuation characters} % \begin{macrocode} \expandafter\@tfor\expandafter\@tempa\expandafter:\expandafter=% \nocorrlist % \end{macrocode} % We have to hide the |\@let@token| in the macro |\test@next| rather % than testing it directly in the loop since it might be |\let| % to a |\fi| or |\else|, which would result in chaos. % \changes{v2.1a}{1993/11/24}{Use \cmd{\test@next}} % \begin{macrocode} \do \test@next % \end{macrocode} % Frank thinks that the next bit it is inefficient if done after % the second change. Chris thinks that most all of this is % inefficient for the commonest cases: but that is the price of a % cleverer algorithm. It is certainly needed to deal with the use % of |\nolinebreak|. % % \begin{macrocode} \if@tempswa \sw@slant \fi \fi } % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\test@next} % \changes{v2.1a}{1993/11/24}{Macro added} % The next token in the input stream is stored in |\@let@token| via a % |\let|, the current token from |\nocorrlist| is stored via |\def| % in |\@tempa|. To compare them we have to fiddle around a bit. % % If the only things to check were characters then this could be % done via an |\if| thus their catcodes would not matter; but this % will not work whilst |\futurelet| is used above. % \begin{macrocode} \def \test@next {% \expandafter\let\expandafter\@tempb\expandafter=\@tempa\relax \ifx\@tempb\@let@token % \end{macrocode} % If they are the same we jump out of the loop. % \begin{macrocode} \@tempswafalse \let\@nextwhile\@fornoop \expandafter\@gobblefour \fi } % \end{macrocode} % \end{macro} % % \begin{macro}{\sw@slant} % \changes{v3.0a}{1993/12/11}{Macro changed} % \begin{macro}{\fix@penalty} % \changes{v3.0a}{1993/12/11}{Macro added} % The definition of the mysterious |\sw@slant| command is as follows. % \begin{macrocode} \def \sw@slant {% % \end{macrocode} % It is surely correct to put in an italic correction when there % is no skip. If the last thing on the list is actually a zero % skip (including things whose dimension part is zero, such as % |\hfill|), or anything other than a sloped character, then the % italic correction will have no effect. % % In order to work correctly with unbreakable spaces from |~| % (and other common forms of line-breaking control) we also move % back across a penalty before the glue. % \begin{macrocode} \ifdim \lastskip=\z@ \fix@penalty \else \skip@ \lastskip \unskip \fix@penalty \hskip \skip@ \fi } % \end{macrocode} % The above code means: ``If there is a non-zero space just before % the current position (|\ifdim...|) save the amount of that space % (|\skip@\lastskip|), remove it (|\unskip|), then do a similar % thing if there is a penalty just before the skip, % and finally put the space back in.'' % % Since zero glue cannot be distinguished in this context from no % glue, we dare not put in an |\hskip| in this case as this may % produce an unwanted breakpoint. This is not satisfactory. % % The penalty before the glue is handled similarly, with the same % caveats concerning the zero case. Is this the first recorded % use of |\unpenalty| in standard \LaTeX{} code? % \begin{macrocode} \def \fix@penalty {% \ifnum \lastpenalty=\z@ \@@italiccorr \else \count@ \lastpenalty \unpenalty \@@italiccorr \penalty \count@ \fi } % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\nocorrlist} % This holds the list of characters that should prevent italic % correction. They should be ordered by decreasing frequency of % use. If any such character is made active later on one needs % to redefine the list so that the active character becomes part % of it. % \changes{v3.1a}{1994/01/27}{Only ., used as default for cm fonts} % \begin{macrocode} \def \nocorrlist {,.} % \end{macrocode} % \end{macro} % % % \begin{macro}{\nfss@text} % This command will by default behave like a \LaTeX{} |\mbox| but % may be redefined by packages such as |amstext.sty| to be a bit % cleverer. % \begin{macrocode} \ifx \nfss@text\undefined \def \nfss@text {\leavevmode\hbox} \fi % \end{macrocode} % \end{macro} % % % \begin{macro}{\DeclareOldFontCommand} % \changes{v3.2b}{1994/04/14}{Renamed from \cmd{\@newfontswitch}} % This is the function used to create declarative font-changing % commands that can also be used to change alphabets in math-mode. % % Usage: |\DeclareOldFontCommand \fn{|\meta{font-change decls}|}| % \meta{math-alphabet} % % Here |\fn| is the font-declaration command being defined, % \meta{font-change decls} is the declaration it will expand to in % text-mode, and \meta{math-alphabet} is the (single) math alphabet % specifier which is to be used in math-mode. % % It does not care whether the command being defined already % exists but it does give a warning if it redefines anything. % % Here are some typical examples of its use in conjunction with % more basic NFSS2 font commands. % \begin{verbatim} % \DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm} % \DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf} % \DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt} % \end{verbatim} % % \changes{v3.0b}{1993/12/19}{Corrected and tidied} % \begin{macrocode} \def \DeclareOldFontCommand #1#2#3{% \DeclareRobustCommand #1{\@fontswitch {#2}{#3}}% } % \end{macrocode} % \end{macro} % % \begin{macro}{\@fontswitch} % \begin{macro}{\@@math@egroup} % \begin{macro}{\@@math@egroup} % These two commands actually do the necessary tests and % declarative \mbox{font-} or alphabet-changing. % % \changes{v3.3c}{1994/05/05}{Corrected \cmd{\@fontswitch} and added % saved versions} % \begin{macrocode} \def \@fontswitch #1#2{% \ifmmode \let \math@bgroup \relax \def \math@egroup {\let \math@bgroup \@@math@bgroup \let \math@egroup \@@math@egroup}% #2% \else #1% \fi } \let \@@math@bgroup \math@bgroup \let \@@math@egroup \math@egroup % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \changes{v2.1b}{1993/12/08}{Macros \cmd\rm, \cmd\bf and \cmd\sf moved % to classes.dtx} % % These commands are available only in the preamble. % \begin{macrocode} \@onlypreamble \DeclareTextFontCommand \@onlypreamble \DeclareOldFontCommand % \end{macrocode} % % \section{Initialization} % \changes{v3.0b}{1993/12/19}{Added by ASAJ.} % \changes{v3.0b}{1993/12/19}{Wording changes by CAR.} % % \begin{macro}{\normalsize} % \changes{v3.3d}{1994/05/08}{Removed \cmd{\@undefinedfonterror}} % This is defined to produce an error. % \begin{macrocode} \def\normalsize{% \@latex@error {The font size command \noexpand\normalsize is not defined: there is probably something wrong with the class file}\@eha } % % \end{macrocode} % \end{macro} % % \Finale \endinput