Documentation version 0.1.0a4
Documentation
On this page

Text output

The rules for the plain text target, which writes a formula as one line of readable Unicode text such as x^2 + 1.

The text writer renders a formula as readable plain Unicode text on a single line. It preserves the structure of the formula with the notation people commonly type, ^, _, / and parentheses, plus a few names such as sqrt, so that a plain reading of the text gives the same formula as the input. The text target has no options of its own and writes no delimiters.

Examples follow the conventions of LaTeX output style. Here a simple item is a single token, a fence, or a name applied to arguments in parentheses, such as x, 10, α, (a + b) or sqrt(x); any other item is compound.

CodeSectionCovers
CCharacters and spacingcharacters, text and spaces
LLettersletter styles
SScripts^, _ and parentheses around scripts
FFractions and roots/, binom, stack, sqrt and root
UUnder and overlimits, accents and other items below or above
BBracketsfences and bars
MMatrices and tablesrows and cells
EEnclosuresboxes, strikes and lines
PPhantoms and other contentphantoms, unknown content
KContent markupproducts, numbers and piecewise definitions of content markup

Characters and spacing#

C1. Tokens, text and spaces#

Characters of tokens and text are written as they are. Operators are spaced as in LaTeX rule S2, except that inside scripts, limits and indices no operator gets spaces. A function name is separated by a space from a letter or digit on either side. Text keeps its whitespace as in LaTeX rule T2. A Space at least 5 eighteenths of an em wide is one space; a narrower one is not written. There is never more than one space in a row, and none at the start or end.

An accent over text of one letter is the composed character, as in LaTeX rule T5.

InputOutput
<mi>a</mi><mo>+</mo><mi>b</mi><mo>=</mo><mi>c</mi>a + b = c
<mi>sgn</mi><mo>&#x2061;</mo><mi>x</mi>sgn x
<mn>2</mn><mi>sin</mi><mi>x</mi>2 sin x
<mi>x</mi><mtext>&#xA0;if&#xA0;</mtext><mi>y</mi>x if y
<mtext>for all </mtext><mi>x</mi>for all x
<mi>a</mi><mtext> </mtext><mi>b</mi>a b
<mtext>m</mtext><mover accent="true"><mtext>e</mtext><mo>ˊ</mo></mover><mtext>dia</mtext>média

C2. < never starts a raw tag#

As in LaTeX rule C5, a space is written between < and a directly following letter, /, ! or ?, after all other spacing, in tokens and in text alike.

InputOutput
<msub><mi>x</mi><mrow><mi>a</mi><mo>&lt;</mo><mi>b</mi></mrow></msub>x_(a< b)
<mtext>&lt;b&gt;</mtext>< b>

Letters#

L1. Variants become styled letters#

A letter of a token or of text in a variant other than normal or italic is written as the Unicode letter with that style built in, when Unicode has one, and as the plain letter otherwise.

InputOutput
<mi mathvariant="double-struck">R</mi>ℝ
<mi mathvariant="bold">x</mi>𝐱

Scripts#

S1. Scripts use ^ and _#

A subscript is written after _ and a superscript after ^, the subscript first. A compound script or a compound base is put in parentheses; a text of one word counts as simple. Primes are apostrophes, as in LaTeX rule C6, and follow the item before them directly, as in s^2'; an apostrophe that delimits a fence stays an apostrophe. An empty base is not written. Left scripts are written before the base, with a space before and after them. A token or text script directly followed by a letter or digit is also put in parentheses, so that x^(2)3 is not read as x^23.

A superscript that is exactly the ring operator U+2218 or the degree sign, with no subscript, is written as the character ° directly after its base or the previous item, with no caret and no parentheses. Both encodings of the degree sign read 90° and 30°C.

InputOutput
<msubsup><mi>a</mi><mi>i</mi><mn>2</mn></msubsup>a_i^2
<msup><mi>x</mi><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></msup>x^(n+1)
<msup><mrow><mi>a</mi><mi>b</mi></mrow><mn>2</mn></msup>(ab)^2
<msub><mi>x</mi><mtext>max</mtext></msub>x_max
<mn>90</mn><msup><mi/><mo>∘</mo></msup>90°
<mn>30</mn><mo>°</mo><mi mathvariant="normal">C</mi>30°C
<msubsup><mi>x</mi><mn>1</mn><mo>∘</mo></msubsup>x_1^∘
<msup><mi>x</mi><mn>2</mn></msup><mn>3</mn>x^(2)3
<msup><mi>s</mi><mn>2</mn></msup><mo>′</mo>s^2'
<mmultiscripts><mi>C</mi><mprescripts/><mn>6</mn><mn>14</mn></mmultiscripts>_6^14 C

Fractions and roots#

F1. Fractions use /#

A fraction is written as numerator, / and denominator. A compound numerator or denominator is put in parentheses, and an empty one is not written. A fraction directly next to anything other than an operator is itself put in parentheses. A space between items, such as a Space at least 5 eighteenths of an em wide, does not count as an item.

As in LaTeX rule F2, a fraction without a line that is alone inside round parentheses that stretch is binom(n, k), and the parentheses are not written. Any other fraction without a line is stack(n, k). Both carry their own parentheses, so they never get others.

InputOutput
<mfrac><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow><mn>2</mn></mfrac>(a + b)/2
<mfrac><mn>1</mn><mn>2</mn></mfrac><mi>x</mi>(1/2)x
<mi>x</mi><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac>x = 1/2
<mfrac linethickness="0"><mi>n</mi><mi>k</mi></mfrac>stack(n, k)
<mo>(</mo><mfrac linethickness="0"><mi>n</mi><mi>k</mi></mfrac><mo>)</mo>binom(n, k)

F2. Roots use sqrt and root#

A square root is sqrt(radicand); a root with an index is root(index, radicand). Operators in the index get no spaces. A name such as sqrt, root or stack directly after a letter, a digit or a closing bracket is preceded by a space.

InputOutput
<msqrt><mi>x</mi></msqrt>sqrt(x)
<mroot><mi>x</mi><mn>3</mn></mroot>root(3, x)
<mn>2</mn><msqrt><mi>x</mi></msqrt>2 sqrt(x)

Under and over#

U1. Limits are scripts; other items use names#

Limits of a large operator or a function name are written as scripts, by rule S1. An accent is written as a name applied to its base: hat, tilde, bar, vec, dot, ddot, check, breve, acute and grave above, and underline below. A mark is an accent whichever element holds it and whatever accent says, as in LaTeX rule U2. A horizontal brace is overbrace(…) or underbrace(…), with its label as a script. Anything else, including an arrow with a label, is over(base, above), under(base, below) or underover(base, below, above). A name applied to its base counts as simple, so it takes no parentheses as a script base.

InputOutput
<munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover>∑_(i=1)^n
<mover accent="true"><mi>x</mi><mo>^</mo></mover>hat(x)
<munder><munder><mrow><mi>a</mi><mi>b</mi></mrow><mo>⏟</mo></munder><mi>n</mi></munder>underbrace(ab)_n
<mover><mi>x</mi><mo>*</mo></mover>over(x, *)
<mover><mo>→</mo><mi>f</mi></mover>over(→, f)

Brackets#

B1. Fences are written with their delimiters#

A fence is written as its opening delimiter, its content and its closing delimiter; a missing delimiter is not written. An mfenced with only one of open and close has no delimiter on the other side, and it writes no separator next to a child that is an operator taking operands, as in LaTeX rules B2. The divides sign ∣ pairs as a bar and keeps its character. A lone bar is written |, with a space on each side when it stands between two items inside braces, as \mid does in LaTeX rule B4.

input:  <mo>|</mo><mi>x</mi><mo>|</mo>
output: |x|
input:  <mo>{</mo><mi>x</mi><mo>|</mo><mi>x</mi><mo>&gt;</mo><mn>0</mn><mo>}</mo>
output: {x | x > 0}

Matrices and tables#

M1. Tables are written in rows#

A matrix is written in square brackets, with , between cells and ; between rows. A table alone inside a fence uses the fence's delimiters in place of the square brackets when it is a matrix or all its columns are centred. A table that the LaTeX writer writes as cases is written the same way, after its { and with no closing delimiter.

A table of equations is written row by row, with ; between rows. The cells of a row are joined with one space. A relation that begins a cell keeps its relation spacing, so the cells a and = b read a = b, as the plain row does.

A row label, such as an equation number, follows the cells of its row after a space, as it is written in the markup: a = b (2); c = d (3). A labelled table of one row is its line followed by its label, as in E = mc^2 (1). The option drop_labels leaves labels out.

TableOutput
rows 1 0 and 0 1, no fence[1, 0; 0, 1]
the same matrix inside round parentheses(1, 0; 0, 1)
the cases example of LaTeX rule M1{x, x ≥ 0; -x, x < 0
equations with cells a, = b and c, = da = b; c = d
lines a = b and c = d in one columna = b; c = d
the same lines labelled (2) and (3)a = b (2); c = d (3)

Enclosures#

E1. Enclosures use names#

The notations that LaTeX rule E1 writes are written as names, nested in the same order: box(…) for box and roundedbox, cancel(…) for each diagonal strike and both together, overline(…) for top, underline(…) for bottom and sqrt(…) for radical. Any other notation is not written: the content is written alone, and the fallback unsupported-notation is recorded. A name directly after a letter or digit is separated from it by a space, as in a sqrt(x).

InputOutput
<menclose notation="box"><mi>x</mi></menclose>box(x)
<menclose notation="circle"><mi>x</mi></menclose>x

Phantoms and other content#

P1. Hidden content is not written#

Hidden phantom content is not written; shown phantom content is. An Unknown node is written like a row of its children. A Verbatim node, which no current reader produces, is written as its head followed by its arguments in their recorded brackets.

InputOutput
<mi>a</mi><mphantom><mi>x</mi></mphantom>a

Content markup#

K1. Content markup is written as the nodes it lowers to#

Content markup lowers to the nodes of presentation markup, by the notation of LaTeX rules K1 to K7, and the rules above write them. A product whose factors would run together is written with ⋅ between them, a number in e-notation with ×, a derivative as a fraction of differentials, and a piecewise definition as a table after its {, with "if" before each condition.

InputOutput
<apply><times/><ci>kf</ci><ci>A</ci></apply>kf ⋅ A
<apply><times/><cn>2</cn><ci>x</ci></apply>2x
<cn type="e-notation">2<sep/>-5</cn>2 × 10^-5
<apply><diff/><bvar><ci>x</ci></bvar><ci>y</ci></apply>(dy)/(dx)
<lambda><bvar><ci>x</ci></bvar><apply><power/><ci>x</ci><cn>2</cn></apply></lambda>x ↦ x^2
<piecewise><piece><cn>1</cn><apply><gt/><ci>x</ci><cn>0</cn></apply></piece><otherwise><cn>0</cn></otherwise></piecewise>{1, if x > 0; 0, otherwise

Edit this page on GitHub