LaTeX notes: NFSS that little thing _latex

Source: Internet
Author: User
Tags reserved


Zero

I do not write "LaTeX notes (a): NFSS that Thing", so that you hope that there are two ...

This article is closer to the subject of Texnique. To understand the content of this article, you should at least read Texbook or TeX by topic.

One

NFSS Framework is the core of latex2e, accounting for the latex2e source of about 30% of the space. If you don't understand the importance of it, there is one more data: In the fully installed TeX Live release, the font definition file (*.FD) written by various font macro packages has 3000 +. With NFSS, we can happily use \bfseries \itshape and other commands to switch fonts, do not exceed the moment.

Then how to switch fonts without NFSS? If you read one of the two books as you said in the No. 0, then you know it is:

% with Txfonts macro package font TXR For example
\FONT\TXRM=TXR at 12pt
\txrm Hello, \tex\ and its fonts!

You need to define a control sequence (command) that represents the actual font, and then use it when switching fonts. Plain TeX has already defined some, such as \BF \it \tt. The problem is that \BF is upright and bold, \it is a plain heavy Italian italic, if you want bold italic, this font has nothing to do with either of them, you have to redefine a font command such as \bfit. Even fonts of different font sizes need to be redefined.

Then again, in fact, \bfseries \itshape and \mdseries \itshape, \bfseries \upshape, and other commands given by the same font is not the same ah, this how to engage. Look down.

<!--before looking down, it is advisable to take a closer look at the two important documents Encguide and Fntguide in the TeX release. -->

<!--what you've seen. -->

<!--I don't know if you've really finished reading it or not, okay, keep-->.

Two

The two documents shown above describe the important properties of NFSS-coordinates. A font has the encoding/family/series/shape and the font size of these five coordinates, such as the default font, 10pt Computer modern Roman (Cmr10), in the NFSS coordinates are OT1/CMR/M/N/10. Here is not spread out, you need to really read the two documents.

Oh, you seem to have seen such a string of wording somewhere. Yes, in Overfull \hbox and other information is full of this writing. Well, it's time to tell you the truth: Before you call this font, there's actually a global definition:

\global\font\ot1/cmr/m/n/10=cmr10

But it is wrong to write this directly, because the name of the control sequence must be the letter class (the catcode=11 character). The right way to do this is to:

\global\expandafter\font\csname Ot1/cmr/m/n/10\endcsname=cmr10

\expandafter and \csname ... if you do not understand the use of \endcsname, hurry to read.

In other words, the real font commands are built by these coordinates. Different coordinates will construct different font commands, and each time you switch the coordinates, it is likely that a new font command will be generated.

Three

Really is to put the font coordinates together so simple. Of course, LaTeX needs additional information to find the name of the font to be assigned after the equals sign in the code above. The object that maps the coordinates to the font name is the essential. fd file for each font macro package. This is put in the back interspersed with said.

Four

Now it's time to mention a core command--\selectfont in NFSS. It is in the definition of \bfseries \itshape or \small \large. You use \FONTSERIES{BX} or \fontsize{10}{12} to change the coordinates of the role of the font, it is only the coordinates of the information stored in some internal macros, such as \f@encoding \f@series. \selectfont is the actual operation of changing the font.

So what did \selectfont mainly do?

\declarerobustcommand\selectfont
        {%
    \ifx\f@linespread\baselinestretch \else
      \set@fontsize\ Baselinestretch\f@size\f@baselineskip \fi
    \xdef\font@name{%
      \csname\curr@fontshape/\f@size\endcsname}%
    \pickup@font
    \font@name
    \size@update
    \enc@update
    }

Definition, the first two lines do not look closely, it is the role of processing line spacing information. There are two ways to change the line spacing: \linespread{***} and \renewcommand {\baselinestretch}{***}, which results in \baselinestretch and the line spacing expansion factor with internal command caching \ F@linespread inconsistent (the former does not have this problem), so here to deal with.

第3-4 line is defined as the so-called \OT1/CMR/M/N/10, where the definition of a global \font@name, the next many places to be useful, another important internal macro is \curr@fontshape, which stores the first four coordinates.

Line 6th uses this \OT1/CMR/M/N/10 to change the font, and the 7th line is to update \baselineskip and so on, and the 8th line is to change some of the processing after encoding.

Focus on line 5th:

\def\pickup@font{%
    \expandafter \ifx \font@name \relax
       \define@newfont
    }

The meaning is not difficult, if \OT1/CMR/M/N/10 already defined, take to use ready-made, otherwise need to define new font. Next look:

\def\define@newfont{%
  \begingroup
    \let\typeout\ @font @info
    \escapechar\m@ne
    \expandafter\ Expandafter\expandafter
       \split@name\expandafter\string\font@name\ @nil
      \try@load@fontshape% try Always
    \expandafter\ifx
       \csname\curr@fontshape\endcsname \relax
      \wrong@fontshape\else
      \ Extract@font\fi
  \endgroup}

Group, the first line affects the information that is output to the terminal; The 第2-4 line is a unpacking of the \font@name content, and the font coordinates inside it are stored in the \f@encoding \f@series.

One of the following key macros is \try@load@fontshape:

\def\try@load@fontshape{%
   \expandafter
   \ifx\csname \f@encoding+\f@family\endcsname\relax
     \@ Font@info{try loading font information for
                   \f@encoding+\f@family}%
    \global\expandafter\let
       \csname\ f@encoding+\f@family\endcsname\ @empty
     \nfss@catcodes
     \let\nfss@catcodes\relax
     \edef\reserved@a{%
       \lowercase{%
         \noexpand\inputiffileexists{\f@encoding\f@family.fd}}}%
     \reserved@a\relax
          {\@ input@{\f@encoding\f@family.fd}}%
   \fi}

As we can see, the function of this macro is to load the. fd font definition file. Explain two macros here: \csname \f@encoding+\f@family\endcsname, shaped like \OT1+CMR. Its definition indicates that the. fd file is loaded. It is defined by the \declarefontencoding command in the. fd file. \csname \curr@fontshape\endcsname, shaped like \ot1/cmr/m/n, defines that the. fd file is loaded, and the first four coordinates are defined by the \declarefontfamily command in the. fd file. So you can bring the last piece of the puzzle, that is, the font size information spelling.

So good, go down, if. fd file loaded, each \declarefontfamily also passed, still can't find the corresponding font how to do. This means that the font package may not define the coordinates you want, then the rollback (fallback), the work is done by \wrong@fontshape. Each encoding definition file, such as T1enc.def, uses the \declarefontsubstitution command to give the three coordinates to be rolled back (OT1 in the latex2e kernel).

\wrong@fontshape code will not continue to paste, for example, if I get a wrong coordinates out, \ot1/cmr/xxx/xxx,latex loaded OT1CMR.FD found that there is no such coordinates, it will fall back to \ot1/cmr/xxx/n, If you can't find it, fall back to \ot1/cmr/m/n. If you have a fallback, you will see the "Font shape * * * Undefined, use * * * instead" hint.

If you find the first four coordinates of the information, or back to the appropriate first four coordinates, next to the size of the coordinates to find the font (TFM). This function is completed by \extract@font, which calls the \get@external@font to parse the definitions of various complex font sizes and TFM mapping relationships in the \declarefontshape command, which internally uses the \try@size@range Complete the actual analysis, using \try@size@substitution to complete the fallback of the font size.

Five

After a long-winded writing, I don't know how many people are patient enough to see it, and to read more books to understand it. LaTeX to the font of this set of solutions may not be optimal, but I am afraid is irreplaceable, otherwise the scenes scenes font macro package must be changed.

Well, I'm not saying that 30% of the code is NFSS. In fact, this part of the discussion today does not even account for 5%. The rest of the big head was encoding and math fonts accounted for. The encoding section is about the implementation of commands and accents under different font encodings, such as the OT1 "O is two characters, and T1 can find a single character." The mathematical font is not here to say, it must be said to open a different post.

\endinput



Author: Louis Stuart
Link: https://zhuanlan.zhihu.com/p/21339128
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author to obtain authorization, non-commercial reprint please indicate the source.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.