% !TeX program = lualatex
% =====================================================================
%  03-math.tex
%  The whole maths story: the inline mini-language (operators, fractions,
%  powers, roots, sums, Greek, helpers abs/norm/vec/lim), then the block
%  constructs (matrix, det, bmatrix, augmented matrix, equation systems).
%  lang=en here keeps the decimal point; set lang=fr for a comma.
% =====================================================================
\documentclass[
  margins=20,
  font=Latin Modern Roman,
  size=12,
  lang=en
]{scholatex}
\begin{document}

let title = <red b 18pt c>
let h1    = <navy b section>
let raw   = <gray i>

<title>Simple LaTeX — maths

% =====================================================================
<line h1>The inline mini-language
% =====================================================================
Wrap maths in <tt>{$...$}. A handful of rewrites keep it light: <tt>{*}
gives a product, <tt>{+-} a plus-or-minus, and <tt>{\<=} <tt>{\>=} <tt>{!=}
the three comparisons.
$a * b$, $x +- y$, $a <= b$, $c >= d$, $e != f$.

Fractions use <tt>{/} and chain left to right, powers use <tt>{^}, indices
use <tt>{_}:
$1/2$, $a/b/c$, $x^2 + y^2 = r^2$, $x_1 + x_2$.

Roots, sums and Greek names need no backslashes:
$sqrt(2)$, $sqrt(x^2 + y^2)$, $sum(i=1, n) i = n(n+1)/2$,
$alpha + beta != gamma$, $pi >= 3$, and $inf$ for infinity.

<h1>Interpolation inside maths
A value computed with <tt>{\#\{...\}} or <tt>{\#name} drops straight into a
formula, and follows the <tt>{lang} option so a typed and a computed number
always match.
let n = 7
$n = #n$, so $n^2 = #{n*n}$ and $n/2 = #{n/2}$.

<h1>Helpers: abs, norm, vec, lim
In the spirit of <tt>{sqrt()}: <tt>{abs(x)} gives $abs(x)$, <tt>{norm(v)}
gives $norm(v)$, and <tt>{vec(AB)} draws a vector: $vec(AB)$.
A limit reads as an operator whose <tt>{(...)} holds the approach, written
with <tt>{->}: $lim(x->0) f(x)$ and $lim(n->inf) 1/n$.

Because the helpers nest, the secondary-school vector notation falls out for
free — Chasles' relation $vec(AB) + vec(BC) = vec(AC)$, and the norm of a
vector $norm(vec(AB))$, need nothing extra.

% =====================================================================
<h1>Matrix blocks
% =====================================================================
A matrix is a block: one line is one row, <tt>{;} separates the entries.
Every cell goes through the mini-language, so $2x + 1$ or $1/2$ work inside
a cell.
<matrix>{
	1 ; 2 ; 3
	4 ; 5 ; 6
}
<raw>The raw form needs a <tt>{pmatrix} environment, an ampersand between
every entry and a double backslash at every row end.

The same block under two other names draws a determinant or square brackets:
<det>{
	a ; b
	c ; d
}
<bmatrix>{
	2x + 1 ; 0
	0 ; 1/2
}

<h1>Augmented matrix
A single <tt>{|} inside a row draws the separation bar, at the very place
you type it, between two cells — the same column on every row. This is how a
linear system is set up for elimination:
<bmatrix>{
	2 ; 1 | 7
	1 ; -1 | 1
}
The bar is allowed on <tt>{\<matrix\>} and <tt>{\<bmatrix\>}, never on
<tt>{\<det\>}. A bar at a row edge, or misaligned across rows, raises a clear
<tt>{scholatex:} error naming the line.

<h1>Systems of equations
A system aligns automatically on the first relational operator, so equalities
and inequalities mix freely. One equation per line, no separator:
<system>{
	2x + 3y = 7
	x - y = 1
}
<system>{
	2x + 3 <= 7
	x >= 0
}

<violet b c>End of the demonstration.

\end{document}
