#header,next=TZ2_COMMANDS.html,prev=./RESPONSIVE.html

Bigger, faster, smarter - the monster returns.

Objectives

Create a javascript program to convert LaTeX math formula's into responsive MathML. In order of importance

Reference Material

Issues

In hindsight the main issues to implementation have not been the TeX syntax itself rather they have been

Implementation

Input

All input is Unicode, it's not limited to Ascii. TeXZilla interprets it's input as a stream of tokens.

Mathematical Symbols

Almost all mathematical symbols have been assigned unicode's in the extended plane and are supported in the common MathML fonts. So there is no need for any other special fonts at all. Commands like \mathfrak and \mathcal are implemented simply by mapping A-Z etc. into this plane.

Macros

Are user-defined commands. Perform text substitution - using strings of tokens. Arguments for macro's are marshalled by looking ahead in the input stream for the next token, or string of tokens contained between balanced pairs of { }. As a result of this rule macro argument values always contain balanced sets of braces. The outer pair of braces are not considered to be part of the macro value. In TeX there is no implicit boxing of command arguments. However many of the AMS commands appear to get their arguments automatically boxed in braces. I'm guessing the reason for this discrepancy is that the AMS commands were once macro's which boxed their arguments internally.

Design (in a state of flux)

Tokeniser

Input text is converted to tokens and macro substitution is performed resulting in a stream of tokens with all macro commands and arguments resolved to other tokens.

Interpreter

Tokeniser's output is interpreted and converted to a stream of MathML rendering instructions. It is here where context-specific parsing rules are implemented to ensure compatibility with LaTeX or MathJax etc. There are a number of differences in interpretation between the two.

Renderer

The renderer processes the instructions from the interpreter and builds a MathML element tree. The tree structure is obvious and quite easy to achieve. The correct styling of the tree elements is not so easy, and still a work in progress.

Accents

Despite what AI says using combining diacritics for accents does not work well in MathML in Chrome. This is because it typesets the combining diacritic at a fixed position for all glyphs. The result is the accent often does not appear in the usual position expected.

For example \\not X is resolved by the interpreter as follows. If X is a glyph which has a unicode not form then is converted to that form. Otherwise it is rendered as sub-formula overlayed with a near vertical line through it.

Math Style

The following user selectable italicization styles have been implemented.

Math Style Roman Greek Numbers
Upper Lower Upper Lower
ISO italic italic italic italic upright
TeX italic italic upright italic upright
French upright italic upright upright upright
Upright upright upright upright upright upright

LaTeX Math Fonts

The math fonts are designed to conform to the Mathematical Alphanumeric Symbols table. They do this by translating the glyph characters into the symbol table. So each standard LaTeX character has it's own unique unicode. Because of this these alphabets differ slightly from their Latex versions. In particular they provide lowercase calligraphic characters, and consistent and universal control of italicization. In the table below Italic auto means the italicization is determined by the Math Style.

The standard math font can be left as the system default math font or defined in a CSS style sheet like this:

math {
  font-family: STIX Two Math;
  font-size: 120%; 
}

For consistency across multiple platforms the font should be uploaded from your web site in the style sheet like this:

@font-face {
  font-family: 'STIX Two Math';
  src: url('myfonts/STIXTwoMath-Regular.woff2') format('woff2');
}

For better performance some fonts can be uploaded from Google by adding code like this to <head>.

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Caveat+Brush&display=swap" rel="stylesheet">
      
Font Bold Family Italic Alphabets
\mathnormal serif mixed roman, greek, numbers
\mathrm serif mixed roman, greek, numbers
\mathup serif upright roman, greek, numbers
\mathit serif italic roman, greek
\mathbfit bold serif italic roman, greek
\mathbf bold serif upright roman, greek, numbers
\mathsf sans-serif upright roman, greek, numbers
\mathsfit sans-serif italic roman, greek
\mathbfsf bold sans-serif upright roman, greek, numbers
\mathbfsfit bold sans-serif italic roman, greek
\mathbb double-struck (blackboard) upright roman, numbers
\mathbbit double-struck (blackboard) italic roman
\mathcal chancery script (calligraphic) roman
\mathbfcal bold chancery script (calligraphic) roman
\mathfrak fraktur roman
\mathbffrak bold fraktur roman
\mathscr roundhand script roman
\mathbfscr bold roundhand script roman
\mathtt monospace (teletype) roman, numbers
\oldstyle cursive (old style numbers) numbers

The current math font is used to provide almost all the glyphs for the above alphabets. But because math fonts are inconsistent in providing the glyphs for \mathcal and \mathscr those commands always use the STIX Two Math font. In addition a system-selected font is used to provide \oldstyle numerals because they are not available in most math fonts.

User Defined Fonts

You can define your own font using this Latex code

    $ \newfontfamily{\mathmkr}{mathmkr} $

at the start of the page. Then in a style sheet add a CSS font family and class, for example

@font-face {
    font-family: 'Caveat Brush';
    src: url('myfonts/CaveatBrush-Regular.ttf');
}
.mathmkr {
    font-family: Caveat Brush;
    font-size: 120%;
}

You can then use it like other Latex fonts in the TeX code for example \mathmkr{x} = ...