1

Briefly about LaTeX/TeX,

Why would be useful to have two glyphs encodings for the same document/data processing in the same contextual time (eg. OT1 and OML)? Why two font encondings for the same program (ignore internationalization issues)?

Does "$...$" change locally* the font enconding to a mathematical one? (I was trying, but couldn't do clearer question, sorry)

2 Answers 2

1

No, $...$ doesn't simply change the encoding.

Inside a math formula, inline or display, the interpretation of character tokens changes radically.

In text mode, a character is considered a pair “character code/category code”. Characters with category code 11 or 12 are simply printed; the difference is mainly for the purpose of hyphenation: a candidate word for hyphenation only consists of category code 11 characters (letters); thus punctuation doesn't hinder the process, because punctuation characters have category code 12.

In math mode, characters with category code 11 or 12 are examined in a different way: each character has an associated math code, which is a 15-bit integer, most conveniently shown in four hexadecimal digits. For instance, the math code of a is "7195, whereas the math code of ( and ) are, respectively, "4028 and "5029.

What does this mean? Briefly, the most significant byte declares the type of the object, the next byte states the (default) math family it belongs to, the last two bytes denote a slot in a font. Type "4 means “opening”, type "5 means “closing”. Type "7 is special, but basically denotes an “ordinary” atom.

The type is important for adding automatic spacing between atoms.

In order to being able to typeset formulas, TeX needs four math families, numbered 0, 1, 2 and 3. Each family consists of three fonts, for the different levels (normal, first and second level sub/superscripts). Family 0 usually points to (different sizes of) the text font; family 1 contains math letters (Latin and Greek, plus some symbols); family 2 contains symbols; family 3 contains large symbols (summation, integral) and extensible fences.

Due to practical limitations of the time when TeX was developed, fonts were limited to 128 slots and math families to 16. This forced Knuth to fill the available slots in ways that are not always consistent. This is a font table for a typical family 1 font

enter image description here

It mostly contains letters, but also some symbols and also “old style digits” that aren't properly math, but Knuth didn't want to leave slots free. A typical font for family 2 is laid out as

enter image description here

Mostly symbols, but also the uppercase calligraphic letters. The last row has miscellaneous symbols that aren't properly math.

Now, what's an output encoding? For instance OT1, T1 or OML?

A problem raised by internationalization of TeX was that in the standard fonts letters with diacritics had to be produced with the help of the \accent primitive, which has the defect of inhibiting correct hyphenation of words past accented letters. Not a big problem for Italian, where the diacritics are only used on the last letter; a humongous problem for German, French, Hungarian, Czech and so on, where diacritics can and do appear very early in the words.

At the TUG 1990 conference in Cork, Ireland, a new font layout was agreed upon, which contained slots for accented letters providing support for most (not all) European languages using the Latin alphabet.

enter image description here

Notable exceptions are Lithuanian, Latvian, Estonian, Romanian and Maltese that need diacritics not in the font table. But, hey, fonts could only contain 256 characters! Unicode was still wearing diapers, at the time!

At the same time, Frank Mittelbach and Rainer Schöpf were working on the project of porting AMS-TeX to LaTeX and realized the need for a completely different font selection scheme for LaTeX. This is where the concept of output encoding was born. Actually, the first version of the New Font Selection Scheme (NFSS1) didn't have the concept, which was added in NFSS2, which is currently used (with changes) in LaTeX.

Each font is characterized in NFSS2 by four independent axes

  1. encoding;
  2. family (typeface);
  3. weight (or series), for medium, bold, thin, extrabold and so on;
  4. shape, for upright, italic, slanted and so on.

With a very clever method, sequences such as \'e or \`A can be dealt with differently according to the current font encoding. For instance, in OT1 they resolve to the “Knuthian accent over letter” method, in T1 they resolve to \char"E9 and \char"C0.

Side note. When you type é or À, LaTeX translates the raw internal code (one or more bytes) according to the current input encoding into \'e and \`A, respectively.

The math (output) encodings OML, OMS and OMX are never used as such for output, because of the special treatment of characters and commands in math mode. They exist for the purpose of loading fonts using NFSS2 and assigning them to math families. They also provide a framework for defining math fonts, so that they can use a “standard” association of math codes. Some math fonts comply, other use altogether different assignment of characters to slots in the font.

2

Short answer: because TeX needed more glyphs than a single font could hold in the early ’80s. Long answer:

The original TeX implementation used seven-bit font encodings. DEK needed to make more than 128 characters available. He also wanted the source files to be compatible with ASCII, so he could edit them in his editor and print them out on a standard printer.

There were good reasons for this at the time. People would often open a document written in another encoding in an ASCII editor, and there was no way to enter text in another script in an ASCII editor except by transliteration. Therefore, in the 7-bit days, encodings were usually designed so that, if you read the data as ASCII, you would get a transliteration into Latin script that a human could read, and if you wanted to enter text to be transliterated, the source code would be human-readable.

People still sometimes enter multilingual text into a TeX document this way, although now we can spare the CPU cycles for a more complex transliteration. You can find questions on this site where people ask what transliterations to use to get correctly-spelled words with devanagari, and another package that works this way is tipa.

The move to 8-bit font encodings took until the mid-’90s, in part because early networking hardware would often corrupt the eighth bit. This is why the most popular 8-bit Cyrillic encodings were laid out so that the Cyrillic alphabet was in the upper half, and if the high bit got flipped, each Latin or Cyrillic character would switch to its closest equivalent in the other alphabet.

For math fonts, Knuth didn’t go quite that far. He needed several fonts’ worth of math alphabets. OML mapped all letters to their positions in ASCII, so that if you wrote \mathit{x}, you would get the 𝑥 from OML, and OMS mapped uppercase letters to the calligraphic alphabet, so if you wrote \mathcal{T}, you would get the 𝒯 from OMS, with no extra translation required, beyond changing the current font. When an encoding did not map letters this way, you accessed it through macros, so you wrote \alpha and \Omega, not something like \mathgreek{a}.

4
  • Just, thank you. You have explained me in so direct and simple way, keeping the deepness, I couldn't imagine. May 22, 2020 at 10:41
  • "You can find questions on this site...". should have a hyperlink? May 22, 2020 at 10:44
  • @DanielBandeira Okay, I linked to one example.
    – Davislor
    May 22, 2020 at 11:00
  • Ahh! Now I've got! I think you have forgot to put a link. No problem! Thank you again! May 22, 2020 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .