Article View: comp.text.tex
Article #171An extremely robust way to define fonts
From: Anil Trivedi
Date: Mon, 02 Nov 1992 14:36
Date: Mon, 02 Nov 1992 14:36
167 lines
7389 bytes
7389 bytes
----------------------------------------------------------------------------
[Modified version of a previous article; includes important clarification.]
----------------------------------------------------------------------------
You have just written a great paper or a macro-package to be distributed
all over the world. However, some people may not have the fonts you are
using. When TeX gets stuck, are they going to struggle to find the needed
font(s), or edit your file(s) to use what they do have, or just toss your
work aside? :-)
Here is a macro which defines fonts in a VERY robust manner (I have taken
a lot from comp.text.tex, and it is time to put a little in): It can seek
what you think would be the best, but it can live with the worst. It goes
to heroic lengths to adjust to any contingency.
It is guided by these considerations:
1. WHAT WOULD BE THE BEST: Although one tends to use scaled 10pt fonts,
human vision requires small type to be wider and such scaled-up fonts
appear fat. It is best to find the closest designed size before scaling.
If you want 20pt san-serif, magnify cmss17, not cmss10.
2. WHAT COULD BE THE WORST: They may not have cmss17. Heck, they may
not even have CM fonts. For that matter, they may not have ANY san-serif
fonts, CM or AM! What would you like to do?!?
3. WHAT WOULD BE THE MOST EFFICIENT: If you are defining a great number
of fonts, then you have to minimize unnecessary loops and think smart.
If an installation has amr10 for \tenrm, don't go on testing for all the
great CM fonts you love. Also, don't use the test loops yourself; you
know what you have, just use it, why test each time?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Macro \setfont. Usage:
%% \setfont\myfont={f1}{f2}{f3}{f4}{f5}{\desperate}
%% sets \myfont to f1 if available, otherwise to f2, otherwise to f3,
%% otherwise to f4, otherwise to f5, in that order of preference.
%% If all fails, in utter desperation, we def \myfont to be \desperate.
%%
%% f1, f2, f3 should be the most desired CM choices;
%% f4 should be an AM font;
%% f5 should call Plain names like \fontname\tenrm when available
%% \desperate should be something very standard.
%% (The hook \everysetfont is executed everytime)
%% (Dynamically set switch \oldfontstrue will skip f1,f2,f3.)
%% (User-definable switch \localprocessingtrue just uses f1 and exits.)
%%
%% By Anil Trivedi; thanks to Don Hosek for the font-presence test.
%% Please send any comments to trivedi@yukawa.uchicago.edu
%%
%
\catcode `@=11 % for compactness
\def\g@f{\global\font}
\def\f@n{\fontname}
\def\m@{ scaled \magstep}
\def\m@hf{ scaled \magstephalf}
% ^ this space required
%
\newif\iflocalprocessing
%\localprocessingtrue % will choose f1
%
\newif\ifoldfonts
\edef\tenrmname{\fontname\tenrm}
{\def\\#1{\catcode`#1=12 }\\a\\m\\r\\1\\0\gdef\AMRTEN{amr10}}
\ifx\tenrmname\AMRTEN\oldfontstrue\fi
%
\def\everysetfont{\relax} % redefine if desired
%
\def\setfont#1=#2#3#4#5#6#7{%1%
\iflocalprocessing
\g@f#1=#2% % just the first choice!
\else%
\ifoldfonts% % AM fonts:
\batchmode\g@f#1=#5\errorstopmode% % skip 1st/2nd/3rd choices
\else%
\batchmode\g@f#1=#2\errorstopmode% % Try 1st choice
\ifx#1\nullfont%
\batchmode\g@f#1=#3\errorstopmode % Try 2nd choice
\ifx#1\nullfont%
\batchmode\g@f#1=#4\errorstopmode % Try 3rd choice
\ifx#1\nullfont%
\batchmode\g@f#1=#5\errorstopmode % Try 4th choice
\fi\fi\fi
\fi%
\ifx#1\nullfont%
\batchmode\g@f#1=#6\errorstopmode% % Try 5th choice
\fi
\ifx#1\nullfont%
\message{#1\def'ed to #7(desperate choice!)}
\gdef#1{#7}% % desperate choice
\else%
\message{#1set as \f@n#1}%
\fi%
\everysetfont % hook
\fi%
}%1%
%%
%% Examples:
%
\setfont\seventeenrm={cmr17}{cmr12\m@2}{cmr10\m@3}{amr10\m@3}{\f@n\tenrm\m@3}
{\seventeenss}
%
% First four choices are obvious. By the fifth, we are mildly desperate:
% what kind of TeX *do* they have, has some system manager renamed all the
% fonts after himself? :-) No matter; we try to access *their* \tenrm and
% scale it up. When that fails, it is utter desperation. Better to find
% some font than to leave the text blank. I'd try san-serifs (\seventeenss
% should be defined of course); your call may well be different.
%
% (This was an example, not a recommendation.)
%
% Dont forget to set \catcode `@=12 at the end!
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Like most hooks, \everysetfont is mostly useless but sometimes can be
convenient: Notice for example that \setfont leaves TeX in \errorstopmode.
Therefore, if you had wanted to run a job in \batchmode, then you can
prevent \setfont from thwarting your intentions by changing the definition
of \everysetfont to \batchmode. Etc.
What to choose for \desperate? Well, it depends on which side of 10pt
you are! For example, for 9pt fonts, I would just pick the corresponding
10pt construction:
\setfont\nineit={cmti9}{}{}{amti9}{}{\tenit}
However, in \seventeenrm above we had already tried 10pt fonts before
acknowledging desperation. So \seventeenss was a reasonable choice.
In general I would suggest using roman and italic (the fonts you would
think we are most assured of finding) as desperation choices for all
text fonts; what you do for these two is up to you then!
Happy TeXing,
--Anil Trivedi
PS:
You can do similar things with special fonts you like but are not sure if
everybody has them. For example, "rsfs" is great script font, much nicer
than TeX's \cal to my eyes at least, but you never know who has it and
who doesn't. Hence, try the following code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Use \scr as you would \cal
%% \scr=rsfs (Ralph Smith's Formal Script font ) *if* that font is found,
%% \scr=\cal otherwise.
%%
\newfam\scrfam
\batchmode\font\scrfont=rsfs10\errorstopmode % see if it's there
\ifx\scrfont\nullfont % rsfs10 not found...
\def\scr{\cal} % set \scr=\cal
\else % rsfs10 exists
\global\font\twelvescr=rsfs10 scaled\magstep1
\global\font\eightscr=rsfs7 scaled\magstep1 % load it!
\global\font\sixscr=rsfs5 scaled\magstep1
\skewchar\twelvescr='177\skewchar\eightscr='177\skewchar\sixscr='177
\textfont\scrfam=\twelvescr\scriptfont\scrfam=\eightscr
\scriptscriptfont\scrfam=\sixscr
\def\scr{\fam\scrfam}
\fi
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Technical Details
Message-ID:
<1992Nov2.143612.4432@midway.uchicago.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!yukawa.uchicago.edu!trivediShow Full Headers
Complete Article Headers
Newsgroups: comp.text.tex Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uchinews!yukawa.uchicago.edu!trivedi From: trivedi@yukawa.uchicago.edu (Anil Trivedi) Subject: An extremely robust way to define fonts Message-ID: <1992Nov2.143612.4432@midway.uchicago.edu> Sender: news@uchinews.uchicago.edu (News System) Organization: Enrico Fermi Institute, University of Chicago Date: Mon, 2 Nov 1992 14:36:12 GMT Lines: 167