Rewrite Rulesbase/matrix-to-matrix-env

base/matrix-to-matrix-env

Rewrite plain-TeX matrix to the standard matrix environment with row breaks.

Rewrite patterns#

  1. cr\matrix{#1 \cr #2}\begin{matrix} #1 \\ #2 \end{matrix}
  2. linebreak-arguments\matrix{#1 \\*[#2] #3}\begin{matrix} #1 \\*[#2] #3 \end{matrix}
  3. newline\matrix{#1 \newline #2}\begin{matrix} #1 \\ #2 \end{matrix}
  4. leading-row-scripts\matrix{#1 \cr_{#2}^{#3}#4}\begin{matrix} #1 \\{}_{#2}^{#3}#4 \end{matrix}
  5. leading-row-primes\matrix{#1 \cr'#2}\begin{matrix} #1 \\{}'#2 \end{matrix}

Examples#

Each example shows this rule applied in isolation. A complete normalization profile may make additional changes.

Three by three upper triangular#

Before

\matrix{1 & x & x^2 \cr 0 & 1 & 2x \cr 0 & 0 & 1}

After this rule

\begin{matrix} 1 & x & x^2 \\ 0 & 1 & 2x \\ 0 & 0 & 1 \end{matrix}

The rendered result has pixel differences from the input.

Ams matrix env out of scope#

Before

\begin{matrix} a & b \\ c & d \end{matrix}

After this rule

\begin{matrix} a & b \\ c & d \end{matrix}

Rendering verified with the declared packages.

Same family#

Notes#

Convert only known body-level \cr, \\, and \newline row separators. Normalize \cr and \newline to an unstarred linebreak with no spacing argument; preserve the original star and optional spacing slots on \\ (including \\*, \\[2pt], and \\*[2pt]). Split a separator through any Scripted base chain, transfer its leading subscript, superscript, and Prime content to a fresh empty base at the start of the next row, and preserve nested script layers. Do not split separators inside explicit groups or nested environments, and leave unknown names such as \crcr untouched. Preserve real internal empty rows and the body sequence, including trailing separators. Only the plain-TeX source command is eliminated; existing AMS environments are out of scope.

Disable this rule#

TransformEngine(profile="corpus", disable_rules=["base/matrix-to-matrix-env"])
new TransformEngine({ profile: 'corpus', disableRules: ['base/matrix-to-matrix-env'] })

Open in Playground