% language=us runpath=texruns:manuals/math

\environment math-layout

\startcomponent math-input

\startchapter[title=Inputting math]

\startsection[title=Collapsing]

When in text mode you enter a combination of combining accent and character, a
composed character is assumed and often you then get one shape in your document.
A similar feature is available in math mode. After some discussion and analysis
of the potential clashes and confusion (thanks to Aditya Mahajan) we settled on a
combination of methods: so called math lists entries that we entered in the
character database and|/|or so called special sequences that are part of
\UNICODE. In the next tables we use \type {ml} for math list and \type {sp} for
specials. Collapsing mode \type {1} only uses the specials, while \type {2} first
checks the specials and then the math lists, and \type {3} does the reverse.

In the database you can find this (a few fields have been omitted):

\starttyping
[0x2260] = {
    adobename   = "notequal",
    category    = "sm",
    description = "NOT EQUAL TO",
    mathlist    = { 0x2F, 0x3D },
    mathspec    = {
        {
            class = "relation",
            name  = "neq",
        },
        {
            class = "relation",
            name  = "ne",
        },
    },
    specials    = { "char", 0x3D, 0x338 },
    unicodeslot = 0x2260,
}
\stoptyping

and

\starttyping
[0x2261] = {
    adobename      = "equivalence",
    category       = "sm",
    description    = "IDENTICAL TO",
    mathclass      = "relation",
    mathextensible = "h",
    mathname       = "equiv",
    mathlist       = { 0x3D, 0x3D },
    unicodeslot    = 0x2261,
}
\stoptyping

Here are a few examples:

\def\Test#1%
  {\NC \bf \type{$#1$}
   \NC \setupmathematics[collapsing=0] $#1$
   \NC \setupmathematics[collapsing=1] $#1$
   \NC \setupmathematics[collapsing=2] $#1$
   \NC \setupmathematics[collapsing=3] $#1$ \NC \NR}

\starttabulate[|c|cp|cp|cp|cp|]
    \NC \BC \ttbf 0 \BC \ttbf 1 (sp) \BC \ttbf 2 (sp ml) \BC \ttbf 3 (ml sp) \BC \NR
    \Test{==}
    \Test{/=}
    \Test{>=}
\stoptabulate

A complete list of collapses can be generated after loading one of the tracing
modules:

\startbuffer
\usemodule[math-ligatures]
\stopbuffer

\typebuffer \getbuffer

This provides the command:

\startbuffer
\showmathligatures
\stopbuffer

\typebuffer

which gives:

\start \switchtobodyfont[8pt] \getbuffer \stop

\stopsection

\startsection [title=Scripts]

With \UNICODE\ providing math symbols and a limited set of super- and subscripts,
it made sense to add yet another feature. The scripts were already supported for
a long time, but at some point on the mailing list sequential scripts were
mentioned. So here is an example of both (some fonts, like the one used for
verbatim, don't have all symbols but you get the idea anyway):

\startbuffer
\startformula
    𝑷₂₀(0), ∀²𝑥⁰⁺²₂₀: 𝑷₂₀(𝑥⁰⁺²₂₀) ⇒ 𝑷₂₀(s(𝑥⁰⁺²₂₀)) ⊢ ∀¹𝑦⁰⁺¹₂₀ 𝑷₂₀(𝑦⁰⁺¹₂₀)
\stopformula

\startformula
    \unstackscripts
    𝑷₂₀(0), ∀²𝑥⁰⁺²₂₀: 𝑷₂₀(𝑥⁰⁺²₂₀) ⇒ 𝑷₂₀(s(𝑥⁰⁺²₂₀)) ⊢ ∀¹𝑦⁰⁺¹₂₀ 𝑷₂₀(𝑦⁰⁺¹₂₀)
\stopformula
\stopbuffer

\typebuffer

which renders the clueless formulas:

\getbuffer

The \type {\unstackscripts} macro triggers the unstacking of super and
subscripts.

\stopsection

\stopchapter

\stopcomponent

