LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

View:

 Message: [ First | Previous | Next | Last ] By Topic: [ First | Previous | Next | Last ] By Author: [ First | Previous | Next | Last ] Font: Proportional Font

Subject:

Suggestion: Safe font commands

From:

Date:

Mon, 22 Feb 1999 14:10:49 +0100

Content-Type:

text/plain

Parts/Attachments:

 text/plain (92 lines)
 It occured to me some while back that there is a need for some kind of "safe" font selection commands---where "safe" is to be interpreted as with the safe file commands \InputIfFileExists etcetera---in LaTeX. Safe font commands would provide the ability to test if a font is available before actually trying to typeset anything in it, and thus also the ability to take some alternative action should the font not be available. I know that this is more complicated with fonts than it is with input files, since there is in general no way of testing if there is a TFM file for the font in question short of actually trying to load the font (and I don't think that can be used in general since it results in a visible error message if the result of the test is false). One can however check if there is a font definition file which defines the font in question, so that is what I suggest the safe font commands should do. One example of how to use them is to make a command that typesets some symbol if that symbol is available and which typesets some fake of it otherwise. Assuming the existence of a safe font command \UseTextSymbolIFE (IFE=IfFontExists) with the syntax   \UseTextSymbolIFE{}{}{} which is like \UseTextSymbol{}{} if a font with encoding and the current family/series/shape exists, and like otherwise, one could do   \DeclareRobustCommand\euro{%      \UseTextSymbolIFE{TS1}{\texteuro}{EUR}%   } to get a \euro command that gives something understandable regardless of whether it is typeset on a site with or without a TS1 encoded symbol font. Another example occurs if one needs to write temperatures---then one needs a text minus and a text degree symbol (using math here can cause lots of problems due to the change to Computer Modern that would be the result in many installations). Like the euro symbol, both are available in TS1, but if that is not available then we get into trouble. A simple way out would be to use the declarations   \DeclareTextCommand{\textminus}{OT1}{%     \UseTextSymbolIFE{TS1}{\textminus}{\textendash}%   }   \DeclareTextCommand{\textminus}{T1}{%     \UseTextSymbolIFE{TS1}{\textminus}{\textendash}%   }   \DeclareTextCommand{\textdegree}{OT1}{%     \UseTextSymbolIFE{TS1}{\textdegree}{\char23 }%   }   \DeclareTextCommand{\textdegree}{T1}{%     \UseTextSymbolIFE{TS1}{\textdegree}{\char6 }%   } which fake the text minus and degree using the current font's endash and ring accent if a font with the real thing is not available. The fakes could probably be improved, but it should be clear what they are supposed to denote. It seems to me that much of the code needed to implement these commands already exists in the LaTeX kernel, in particular in \define@newfont and \try@load@fontshape, so it should not have to be that much work implementing them. (It should reside in the kernel, since one place one might want to use these commands are in the definitions in an encoding definition file, and such files cannot load a package (which would have been the alternative place to define these commands) because the fontenc package loads such files during option processing.) One thing that probably would have to be introduced however is some way of controlling how many font substitution steps (here I mean the ones caused by the \DeclareFontSubstitution declaration, not the ones due to using the sub size function in the font shape declaration) should be tried before the test returns false. Clearly the font selection approach of allowing substitution of shape, series, _and_ family is not what one wants (well, perhaps in very extreme cases), and the best default behaviour is most likely to not do any substitutions at all, but in some cases a shape substitution, or even a shape and series substitution is acceptable. Therefore it would be an advantage if some user level interface to controlling this (perhaps as an optional argument to the safe font commands) is provided. Like with safe file commands, it seems reasonable to have both commands that select the font (like the \UseTextSymbolIFE above) if it is available and commands that do merely perform the test. In addition to the former probably saving some typing, they can also provide some amount of enhancement of the test: If there is a font definition for some font, but the font still isn't there (i.e., the system is "incorrectly" set up), these commands still have a chance to resort to the alternative, so that the typeset document can still be acceptable. Lars Hellström