% tenkzmanual2.sty - typographic system for the compact tenkz manual. % % Loaded by docs/tenkz/manual2.tex only. The page is an asymmetric grid: % a 112 mm text column and a 50 mm margin column. Mathematics lives in the % margin column, beside the diagram it describes; the diagram itself is the % primary object and is set first; the source that produced it follows in a % quiet block. Every example is live-compiled: the body of a tnexample or % tnmultiples environment is written verbatim to an auxiliary file and read % back, so the rendered output is produced by the exact source shown. If an % example stops compiling, the manual stops compiling. A tnrefusal body is % the deliberate exception: it prints without rendering, and the doctest % requires it to fail with the diagnostic the manual quotes. \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{tenkzmanual2}[2026/08/10 v2.3 compact tenkz manual typography] % --------------------------------------------------------------------------- % Page grid (Tufte-lite, one-sided; margin column on the right) % --------------------------------------------------------------------------- \RequirePackage[a4paper, left=20mm, textwidth=112mm, marginparsep=7mm, marginparwidth=50mm, top=25mm, bottom=30mm, headsep=7mm, head=14pt]{geometry} \RequirePackage{amsmath, amssymb} \RequirePackage{booktabs, array, tabularx, longtable, multicol} \RequirePackage{fancyvrb} \RequirePackage{needspace} \RequirePackage{fancyhdr} \RequirePackage{marginnote} \RequirePackage{tikz-tensor-networks} % full measure = text column + gutter + margin column (for hero rows, % wide diagrams, and the quick-reference card) \newlength{\mfullwidth} \AtBeginDocument{% \setlength{\mfullwidth}{\dimexpr\textwidth+\marginparsep+\marginparwidth\relax}} % --------------------------------------------------------------------------- % Palette (bound to the package's semantic hues) % --------------------------------------------------------------------------- \colorlet{mcmd}{tenkzMarked} % command names \colorlet{mkey}{tenkzExtra} % key names, sidenote numbers \definecolor{mrule}{gray}{0.60} % example-unit rules \definecolor{msrcrule}{gray}{0.78} % source-block left rule \definecolor{mquiet}{gray}{0.35} % de-emphasised text \definecolor{mtag}{gray}{0.13} % thumb-tags % --------------------------------------------------------------------------- % Metrics (vertical rhythm of the example unit, panel spacing) % --------------------------------------------------------------------------- % \baselineskip- and em-relative values must be evaluated where they are % used, so these are macros rather than lengths \newcommand*{\mtwo@unitsep}{0.62\baselineskip} % space above/below a unit \newcommand*{\mtwo@unitseam}{0.3\baselineskip} % rule/caption/diagram/source seams \newcommand*{\mtwo@panelsep}{2.2em} % gap between small-multiples panels \newcommand*{\mtwo@panellabelsep}{4pt} % panel-to-variant-label gap % Clear paper a panel reserves below its variant label. A row of panels % is one paragraph line; when the row wraps, TeX separates the deep lines % by \lineskip alone, which parks the next row's ink one point under the % caption band of the row above. The panel's vertical extent therefore % includes its caption plus this clearance, so a wrapped panel always % starts on a clear row. \newcommand*{\mtwo@panelrowsep}{1.0\baselineskip} % --------------------------------------------------------------------------- % Margin apparatus: sidenotes, margin formulas, thumb-tags % --------------------------------------------------------------------------- \renewcommand*{\marginfont}{\footnotesize\normalfont\raggedright} % numbered sidenotes, numbers restart with each section \newcounter{sidenote}[section] % Older LaTeX releases do not synthesize the hyperref anchor form here. \providecommand*{\theHsidenote}{} \renewcommand*{\theHsidenote}{\arabic{section}.\arabic{sidenote}} \newcommand*{\msidemark}{\textsuperscript{\textcolor{mkey}{\arabic{sidenote}}}} % margin text opened by its sidenote number (shared by \sidenote and the % example unit's margin block) \newcommand{\mtwo@sidenotetext}[1]{\msidemark\hspace{0.3em}#1} % \sidenote{} — superscript mark here, numbered note in the margin \newcommand{\sidenote}[1]{% \refstepcounter{sidenote}\msidemark \marginnote{\mtwo@sidenotetext{#1}}} % display-style formula at margin size (shared by \marginformula and the % example unit's margin block) \newcommand{\mtwo@displayformula}[1]{\footnotesize$\displaystyle #1$} % \marginformula{} — a display-style formula in the % margin column, anchored at the current line \newcommand{\marginformula}[1]{% \marginnote{\mtwo@displayformula{#1}}} % \thumbtag[]{} — a reference thumb-tag, flush toward the % outer edge; place one at each reference entry (typically % \thumbtag{\textbackslash tn} or \thumbtag{boundary=}). The optional % vertical offset shifts the tag down past a neighbouring margin block % when the two would share a line. % neutralise coloured markup inside tags: tags are white-on-dark \newcommand{\mtwo@tagreset}{% \def\tncmd##1{\texttt{\char`\\##1}}% \def\tnkey##1{\texttt{##1}}% \def\tnenv##1{\texttt{##1}}} \newcommand{\thumbtag}[2][0pt]{% \marginnote{\makebox[\linewidth][r]{% \setlength{\fboxsep}{3.5pt}% \colorbox{mtag}{\color{white}\mtwo@tagreset \ttfamily\footnotesize\vphantom{gj\textbackslash}#2}}}[#1]} % \tnlogline{} — one line of a .tnlog event stream, for quoting % boundary signatures inside sidenotes \newcommand{\tnlogline}[1]{{\ttfamily\scriptsize #1}} % --------------------------------------------------------------------------- % Dangerous bends and exercises (the TeXbook devices) % --------------------------------------------------------------------------- \RequirePackage{manfnt}% \dbend, the road sign % \dbendpar / \ddbendpar — open a paragraph a first reading may skip: one % bend marks advanced or trap material, two bends the truly advanced. The % sign stands in the margin; the paragraph itself is ordinary text. \newcommand*{\dbendpar}{\marginnote{\dbend}} \newcommand*{\ddbendpar}{\marginnote{\dbend\kern 2pt\dbend}} % \tnexercise{