# MaLxTeX

MaLxTeX, pronounced **ma-lex-tex**, draws mathematical notation directly inside *Lx's* Markdown Preview.

It runs inside *Lx*. It does not rely on a separate library or external tool.

## Put a formula in Markdown

Use single dollar signs for a formula inside a sentence:

```markdown
The area is $A = \pi r^2$.
```

Keep the formula next to its dollar signs. For example, `$x+1$` is math, while `$ x+1 $` stays ordinary text. This helps keep prices and stray dollar signs from turning into formulas.

Use dollar signs on their own lines for a larger formula:

```markdown
$$
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$
```

For a longer expression, you can use a fenced `math` block:

````markdown
```math
\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}
```
````

Use `\MaLxTeX` inside a formula when you want to write the renderer's name.

## What MaLxTeX can draw

MaLxTeX follows the familiar TeX and KaTeX way of writing math. Its feature set includes:

| Area | What is supported |
| --- | --- |
| Everyday notation | Superscripts, subscripts, primes, fractions, continued fractions, roots, and binomials |
| Symbols | Greek letters, arrows, relations, logic, sets, calculus symbols, large operators, and named operators |
| Spacing | TeX-style automatic spacing, manual spacing commands, math classes, and common length units |
| Delimiters | Fixed sizes, automatic `\left` and `\right` sizing, one-sided delimiters, and `\middle` |
| Accents | Hats, checks, bars, vectors, dots, braces, groups, and other wide accents |
| Overlays | `\not`, forward and backward cancellation, crossed cancellation, and zero-width overlap controls |
| Fonts | Roman, italic, bold, sans serif, monospace, blackboard, calligraphic, script, and Fraktur math |
| Text | Plain text inside formulas, text weights and shapes, verbatim text, and embedded math inside text |
| Structured math | Matrices, arrays, cases, aligned work, gathered work, split formulas, and multiline formulas |
| Equations | Automatic numbers, custom tags, hidden numbers, labels, and references |
| Boxes and colors | Frames, filled boxes, colored text, MathJax-style `\bbox`, rules, and long-division enclosures |
| Fine layout control | Phantoms, struts, smashed dimensions, raised content, explicit math styles, and `\mathchoice` |
| Reuse | Formula-local commands, named operators, and simple custom environments |
| Links | Clickable `\href` and `\url` targets using the preview's normal link handling |

Unsupported commands remain visible where possible. A misspelling should not silently erase part of your formula.

Less common notation is covered too. This includes bra-ket forms, set builders, modular forms, labelled arrows, leading scripts, `\substack`, hexadecimal `\char` codes, and custom math classes.

## Fractions, roots, and delimiters

The usual TeX forms work:

```tex
\frac{a+b}{c}
\sqrt{x^2+y^2}
\sqrt[n]{x}
\binom{n}{k}
```

Use `\left`, `\right`, and `\middle` when delimiters should grow with their contents:

```tex
\left\{x \middle| x > \frac{1}{2}\right\}
```

You can use a period for an invisible side:

```tex
\left.\frac{df}{dx}\right|_{x=0}
```

## Spacing

You normally don't need to add spaces yourself. MaLxTeX leaves suitable room around symbols such as `+`, `=`, sums, integrals, and delimiters.

Ordinary spaces and line breaks inside a formula don't change its appearance. Use a spacing command when you want to adjust one particular place:

| Write | What it does |
| --- | --- |
| `\,`, `\:`, or `\;` | Add a small, medium, or larger space |
| `\!` | Pull two parts slightly closer |
| `\quad` or `\qquad` | Add one or two wide spaces |
| `\hspace{0.5em}` | Add an exact amount of space |

The named forms `\thinspace`, `\medspace`, `\thickspace`, and their negative versions work too.

For example, this pulls the function name closer to its opening delimiter, then leaves a wide break before the next expression:

```tex
f\!\left(x\right) \qquad g\left(x\right)
```

## Matrices, cases, and aligned work

MaLxTeX supports these matrix and table-like environments:

- `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, and `Vmatrix`
- Their starred forms, plus `smallmatrix`
- `array` and `subarray`
- `cases` and `rcases`
- `aligned`, `alignedat`, and `split`
- `align`, `alignat`, `gather`, `gathered`, `multline`, and `equation`
- AMS `CD` diagrams

Use `&` to separate columns and `\\` to start a new row:

```tex
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix}
```

Alignment environments line up related parts of several equations:

```tex
\begin{aligned}
a &= b + c \\
d &= e + f
\end{aligned}
```

Arrays also support column alignment, vertical separators, row gaps, solid or dashed row lines, partial lines, and cells which span several columns.

## Equation numbers and references

The `equation`, `align`, `alignat`, `gather`, and `multline` environments receive numbers inside display math.

```markdown
$$
\begin{equation}
E = mc^2 \label{eq:energy}
\end{equation}
$$

See $\eqref{eq:energy}$.
```

Use `\tag{energy}` for your own tag. Use `\tag*{energy}` when you do not want parentheses. `\nonumber` and `\notag` hide the number for one row.

The starred equation environments do not receive automatic numbers.

## Text and fonts

Use `\text{...}` for ordinary words inside a formula:

```tex
v = \frac{d}{t} \quad \text{for constant speed}
```

The main math font commands include:

- `\mathrm`, `\mathit`, `\mathbf`, and `\boldsymbol`
- `\mathsf` and `\mathtt`
- `\mathbb`, `\mathcal`, `\mathscr`, and `\mathfrak`
- `\textbf`, `\textit`, `\textrm`, `\textsf`, and `\texttt`

Font and size changes stay inside their current group. Display, text, script, and scriptscript styles follow the surrounding formula.

## Colors, frames, and marks

Use ordinary CSS color names with the color commands:

```tex
\textcolor{red}{x} + \textcolor{blue}{y}
\colorbox{yellow}{$F=ma$}
\fcolorbox{blue}{yellow}{$F=ma$}
```

Use `\boxed` or `\fbox` for a simple frame. MaLxTeX also supports `\bbox`, filled `\rule` boxes, and long-division enclosures.

For cancellation marks, use `\cancel`, `\bcancel`, or `\xcancel`.

## Commands you define yourself

You can define a short command inside a formula:

```tex
\newcommand{\norm}[1]{\left\lVert#1\right\rVert}
\norm{x}
```

Supported forms include `\def`, `\gdef`, `\edef`, `\xdef`, `\newcommand`, `\renewcommand`, `\providecommand`, `\let`, and `\DeclareMathOperator`.

Simple no-argument custom environments are supported too.

Definitions belong only to the formula which contains them. They do not carry into the next inline formula or display block.

## Links inside formulas

Use `\href` when the visible text should differ from the destination:

```tex
\href{guide.md}{\text{Read the guide}}
```

Use `\url` when the address itself should be visible:

```tex
\url{https://www.liqube.com/}
```

Web links, local file links, and heading links behave like ordinary links in Markdown Preview.

## Current limits

MaLxTeX is a math renderer, not a complete TeX or LaTeX document system. It does not process document preambles, load packages, lay out pages, or load images from TeX commands.

Its commands broadly follow KaTeX, but it is not a promise that every KaTeX or TeX command behaves identically. Font and spacing differences may also exist.

Malformed or unsupported input stays visible where possible, so you can find and correct it.

See [Markdown Preview](markdown_preview.md) for reading controls, the document structure sidebar, links, images, and PNG export.
