home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / text / tex / 15452 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  7.1 KB

  1. Path: sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!aukuni.ac.nz!cs18.cs.aukuni.ac.nz!jeremy
  2. Newsgroups: comp.text.tex
  3. Subject: Re: NFSS: How change mathcodes?
  4. Message-ID: <1993Jan26.111323.5096@cs.aukuni.ac.nz>
  5. From: jeremy@cs.aukuni.ac.nz (Jeremy Gibbons)
  6. Date: Tue, 26 Jan 1993 11:13:23 GMT
  7. References: <1993Jan20.161638.7096@uts.uni-c.dk>
  8. Organization: Computer Science Dept. University of Auckland
  9. Keywords: NFSS, mathcode
  10. Cc: jeremy@cs.aukuni.ac.nz
  11. Lines: 162
  12.  
  13. In <1993Jan20.161638.7096@uts.uni-c.dk> kubipdal@uts.uni-c.dk (Peter Dalg}rd) writes:
  14.  
  15. >b) Math alphabets do not seem to be defined unless there is reference 
  16. >    to them in a formula (??) As it is now, $X_i$ gives me an
  17. >    error that textfont 4 is undefined, but $X_i+\mathbf{z}$
  18. >    works. How do I enforce definition of the relevant fonts?
  19.  
  20. Maths fonts in nfss come in two categories: those that are used purely as
  21. alphabets, via macros succ as \mathbf, and those that are also (or purely)
  22. used via mathcodes and mathchardefs. The former can be demand loaded, but
  23. the latter have to be preloaded (because there is no obvious macro on which
  24. to stick a "demand loading" hook). Hence you have to define the fonts
  25. differently. 
  26.  
  27. Here is a reminder I wrote myself a while back, when I was trying to work
  28. out how it all worked.
  29.  
  30.  
  31.               --- Using new fonts in maths with the NFSS ---
  32.  
  33. Fonts used in maths fall into three categories: `symbol fonts', which are
  34. used only via \mathchardefs (such as the AMS font `msam', which contains
  35. only symbols), `character fonts', which are used only via `alphabet
  36. identifiers' (such as the Euler script font `eusm', in its usual usage,
  37. which contains only letters), and `mixed fonts', which used in both ways
  38. (such as the AMS font `msbm', which contains both symbols and blackboard
  39. bold letters).
  40.  
  41. Each font that you want to be able to use in maths mode---where symbols
  42. should get smaller in subscripts and so on---must be allocated one of TeX's
  43. 16 precious maths `groups', as they are called in the terminology of the
  44. NFSS. Maths groups are set aside by the macro \new@mathgroup, so we might
  45. say
  46.  
  47.    \new@mathgroup\msa@group
  48.  
  49. to set aside a group \msa@group. If you find you have run out of maths
  50. groups, you will have to decide which of the groups assigned by LaTeX you
  51. can do without. LaTeX traditionally sets up 11 groups:
  52.  
  53.            0  roman (cmr)
  54.            1  math italic (cmmi)
  55.            2  symbols (cmsy)
  56.            3  extensible characters (cmex)
  57.    \bffam  4  bold (cmbx)
  58.    \sffam  5  sans serif (cmss)
  59.    \ttfam  6  typewriter (cmtt)
  60.    \itfam  7  text italic (cmti)
  61.    \scfam  8  small caps (cmcsc)
  62.    \slfam  9  slanted (cmsl)
  63.    \lyfam  10 LaTeX symbols (lasy)
  64.  
  65. The first four of these shouldn't be changed, unless you really know what
  66. you're doing: TeX expects the first four groups to have certain properties.
  67. However, it is unlikely that you will want all of the rest for one
  68. document; if we decided that we never want typewriter text in maths mode,
  69. we could reuse family 6 for the msa symbols by saying
  70.  
  71.    \let\msa@group\ttfam
  72.  
  73. Be warned: macros expecting typewriter text in family 6 will probably
  74. produce msa symbols without generating any error messages!
  75.  
  76. Having chosen a maths group for a maths fonts, you need to tell TeX which
  77. fonts to use for that group. This is done in different ways, depending on
  78. whether the font is a symbol, character or mixed font.
  79.  
  80. The NFSS includes the concept of maths `versions'; this provides another
  81. dimension along which fonts can be varied. Standard LaTeX sets up two
  82. versions, `normal' and `bold'; these correspond to \unboldmath and
  83. \boldmath in the old font selection scheme. Versions can be switched
  84. mid-document, in which case all maths symbols also switch, from one version
  85. to another.
  86.  
  87. Symbol fonts should be assigned to groups using the \define@mathgroup
  88. macro. Suppose you want to use fonts from the `msa' family, `n' shape for
  89. the group \msa@group, using the `m' series for the `normal' version and the
  90. `b' series for the `bold' version; you should say
  91.  
  92.    \define@mathgroup\mv@normal\msa@group{msa}{m}{n}
  93.    \define@mathgroup\mv@bold\msa@group{msa}{b}{n}
  94.  
  95. (The control sequence \mv@normal is the internal sequence corresponding to
  96. the math version `normal'; this really should have been hidden, but Frank
  97. and Rainer have not separated out the style-designer's interface from the
  98. internal details.)
  99.  
  100. Most symbol fonts, though, including the msa fonts, come in only one
  101. version; in this case the same family/series/shape combination should be
  102. assigned for all versions:
  103.  
  104.    \define@mathgroup\mv@normal\msa@group{msa}{m}{n}
  105.    \define@mathgroup\mv@bold\msa@group{msa}{m}{n}
  106.  
  107. All that remains to be done is to define macros to access the symbols from
  108. such a font. The accepted way to do this is to temporarily define a control
  109. sequence returning the number of the maths group in hexadecimal:
  110.  
  111.    \edef\@tempa{\hexnumber@\msa@group}
  112.    \mathchardef\boxdot="2\@tempa00
  113.  
  114. That covers symbol fonts; character fonts are treated differently. They
  115. should be assigned to maths groups using the macro \define@mathalphabet.
  116. Suppose you want the macro \script to select the Euler script font, family
  117. `eus', series `m', shape `n', in the normal maths version, and suppose that
  118. Euler script has been assigned to group \eus@group; you should say
  119.  
  120.    \define@mathalphabet\mv@normal\script\eus@group{eus}{m}{n}
  121.  
  122. Actually, with this definition \script will have no effect and produce no
  123. warning when used in text mode; really it should check whether it is being
  124. used in maths mode:
  125.  
  126.    \def\script{\protect\pscript}
  127.    \def\pscript{\relax\protect\ifmmode\@script\else\nonmatherr@\script\fi}
  128.    \define@mathalphabet\mv@normal\@script\eus@group{eus}{m}{n}
  129.  
  130. Mixed fonts which are used both for symbols and for characters, such as the
  131. AMS symbol font `msb' which contains more symbols and blackboard bold
  132. letters, are slightly more complicated. You could just use *both*
  133. \define@mathgroup and \define@mathalphabet:
  134.  
  135.    \define@mathgroup\mv@normal\msb@group{msb}{m}{n}
  136.    \define@mathalphabet\mv@normal\bbold\msb@group{msb}{m}{n}
  137.  
  138. but this involves giving the family/series/shape information twice, with
  139. all the problems of duplication of information that that entails. A
  140. slightly more elegant solution is provided by \use@mathgroup:
  141.  
  142.    \edef\bbold{\noexpand\use@mathgroup
  143.       \expandafter\noexpand\csname =msb\endcsname\msb@group}
  144.  
  145. (The \noexpands and \expandafters are just hacks to get the effect that the
  146. definition 
  147.  
  148.    \def\bbold{\use@mathgroup\=msb\msb@group}
  149.  
  150. would have if `=' were a letter.)
  151.  
  152. Again, such a definition should check whether it is being used in maths
  153. mode, and hence should be protected:
  154.  
  155.    \def\bbold{\protect\pbbold}
  156.    \def\pbbold{\relax\protect\ifmmode\@bbold\else\nonmatherr@\bbold\fi}
  157.    \edef\@bbold{\noexpand\use@mathgroup
  158.       \expandafter\noexpand\csname =msb\endcsname\msb@group}
  159.  
  160. Here, \nonmatherr@ is a useful macro taken from amsfonts.sty:
  161.  
  162.    \@ifundefined{nonmatherr@}{
  163.      \def\nonmatherr@#1{\err@{\string#1\space allowed only in math mode}\@ehd}
  164.      \def\err@{\@latexerr}
  165.    }{}
  166.  
  167.  
  168. Jeremy
  169.  
  170. ---
  171. Jeremy Gibbons <jeremy@cs.aukuni.ac.nz>         tel: +64 9 373 7599
  172.    Department of Computer Science,              fax: +64 9 373 7453
  173.    University of Auckland, Private Bag 92019, Auckland, New Zealand.
  174.  
  175.