Commit Graph
16 Commits
Author SHA1 Message Date
gloamxun f05723808c Support explicit footnote numbers
\footnotemark[n] and \footnotetext[n]{...} left the bracket text in the line
and ignored the requested number. The footnote pass now reads an optional
bracketed integer: \footnotemark[n] emits that marker (and advances the counter
to it), while \footnotetext[n] attaches its body to the pending note with that
number, creating the entry when the mark appeared elsewhere in the paragraph.

A test uses mark and text with [7], checks "(7)" and the deferred body render
with no warnings, and that no "[7]" text leaks.
2026-10-27 02:30:01 +08:00
gloamxun d3baa78e1e Attach heading labels that follow on the next line
A \label on the line after \section without a blank line was discarded with the
rest of the text after the heading's closing brace, so \ref printed "??".
heading_command now keeps any immediately following \label groups (allowing
whitespace/newlines) in the heading text, which lets the numbering pass attach
them to that heading; other trailing text is still ignored as before.

A preview test puts \label{sec:intro} directly under \section{Introduction},
refers to it, and checks "See 1." with no warnings and no "??".
2026-10-27 02:27:17 +08:00
gloamxun 723b9e220f Render acknowledgement environments as a heading
The acks, acknowledgments and acknowledgements environments were reported as
unsupported. A body pass now rewrites their \begin into an unnumbered
"Acknowledgments" \section* and drops the matching \end, and the environment
names count as supported so the preview warning stays empty.

A test wraps "Thanks." in \begin{acks}, then checks the heading and body text
render with no warnings and no leaked environment names.
2026-10-27 02:24:23 +08:00
gloamxun 0a4bc0ade5 Handle cleardoublepage and column switches
\cleardoublepage was unsupported and \onecolumn/\twocolumn leaked into the
text. The block splitter now treats \cleardoublepage like \newpage/\clearpage
(it sets the pending page break) and consumes the two column switches, since
the engine lays documents out in a single column.

A test alternates the three commands around First/Second/Third, checks at least
two pages, all three texts present, and no leaked commands or warnings.
2026-10-27 02:21:01 +08:00
gloamxun c25c38f16a Resolve running marks in fancy headers
\markboth/\markright and the \leftmark/\rightmark placeholders were
unsupported. The page-geometry pass now consumes those mark assignments and
records the last left/right mark; the running-head text expands \leftmark and
\rightmark from that record (document-wide, not per page) before scrubbing, so
a fancy header or footer can carry the current short title.

A test sets \pagestyle{fancy}, \fancyhead[R]{\rightmark} and
\markboth{Left title}{Right title}, then checks the header text is
"Right title" with no warnings and no leaked \rightmark.
2026-10-27 02:18:11 +08:00
gloamxun 0728d78b29 Resolve nameref to heading titles
Section numbering now also records the heading title for each label: a
number_sections_with_titles variant fills a titles table (the existing
number_sections wrapper keeps its signature for tests), and
resolve_section_refs takes that table. \nameref{label} becomes the heading
title, falling back to the number when no title was recorded, while \autoref
keeps producing "Section <number>"; unresolved forms become "??".

A preview test labels a heading inside its braces and renders \ref, \autoref
and \nameref together as "1 and Section 1 and Introduction" with no warnings.
2026-10-27 02:15:13 +08:00
gloamxun c399481c6a Resolve autoref to its section number
\autoref was unsupported and leaked. The section-reference pass now rewrites
\autoref{label} to "Section <number>" using the same label table as \ref, and
unresolved autorefs become "??" with the other reference commands.

A preview test labels a heading inside its braces
(\section{Introduction\label{sec:intro}}), shows \ref and \autoref side by
side, and checks "1 and Section 1" with no warnings.
2026-10-27 02:12:21 +08:00
gloamxun 6139621653 Consume caption and numbering declarations
\captionsetup, \numberwithin and \DeclareCaption were unsupported and could
leak into the body. The page-geometry pass now consumes those declaration lines
(the caption styling and equation-number scoping are not modelled), in the
preamble and in the body alike.

A preview test declares \captionsetup (plain and with [figure]) and
\numberwithin before and inside the document, then checks "Text." renders with
no warnings and no leaked declarations.
2026-10-27 02:08:59 +08:00
gloamxun ebb178bff5 Reserve invisible space for phantom commands
Text-mode \phantom and \hphantom were unsupported. A text-stage pass measures
the scrubbed argument with the Roman metrics and replaces the command with
\hspace of that width, so the glyphs are omitted but the line keeps their
footprint; \vphantom contributes no horizontal material.

A test renders "A\phantom{wide}B and \vphantom{XX}C and \hphantom{QQ}D." and
checks "AB and C and D." with no warnings and none of the hidden text.
2026-10-27 02:06:20 +08:00
gloamxun 5fbcc34ddd Keep hyperref command labels
\hyperref[label]{text}, \hyperlink{name}{text} and \hypertarget{name}{text}
were unsupported and leaked as text. A text-stage pass now drops the link
machinery and keeps the visible label, accepting the optional [label] argument
of \hyperref and the braced target of the other two; internal PDF destinations
are not modelled.

A preview test uses all three forms and checks "the intro", "linked" and
"anchor" with no warnings and no leaked command names.
2026-10-27 02:00:35 +08:00
gloamxun 6c6963cac7 Support footnotemark and footnotetext
\footnotemark and \footnotetext were unsupported, so deferring a note body was
impossible. The footnote numbering pass now selects among \footnote,
\footnotemark and \footnotetext (longest name first so the prefix cannot win):
\footnotemark advances the counter, emits the numbered reference and records an
empty note for the number; \footnotetext fills that pending note with its body
and leaves no text in the line; the remaining text is appended once.

A test pairs a mark and its text in one paragraph, checks the page carries
"(1)" and "Deferred note." with no warnings, and that neither command leaks.
2026-10-27 01:58:22 +08:00
gloamxun 53a299bd58 Honour protect in edef but expand it normally
\protect was just a no-op token, so \edef\b{\protect\a} expanded \a at
definition time. In an edef-style pass the expander now copies \protect and the
following token unchanged (so the stored body keeps the protected command); in
the ordinary document pass it drops \protect and lets the token expand as
LaTeX does when the text is typeset.

A test defines a=A, \edef b={\protect\a}, redefines a=C, and checks both \b and
a literal \protect\a print C with no warnings.
2026-10-27 01:54:13 +08:00
gloamxun c3ae52452d Resolve csname targets with arguments
\csname foo\endcsname stopped after looking up a zero-argument macro; a
parameterised target was left unresolved. After the zero-argument fast path,
build a synthetic command from the resolved name plus the text following
\endcsname and run the normal macro lookup, so arguments/defaults/delimited
parameter text are consumed exactly as for a literal \foo, and only the bytes
belonging to the csname construct are charged to the caller.

A test defines \foo#1{[#1]} and prints both \csname foo\endcsname{x} and
\csname foo\endcsname{y} as "[x] and [y]" with no warnings.
2026-10-27 01:51:29 +08:00
gloamxun c3e02f0586 Make global definitions override group shadows
A group-local \def stayed visible after a later \gdef of the same name because
scoped lookup preferred the newest scope entry, and an inline \global\def was
unsupported. Route \gdef/\xdef and \global\def/\global\let/\global\chardef
through an upsert that removes same-name entries from every live scope before
updating the global table, so the global meaning wins inside the group and
after it.

A test defines a group-local L, replaces it with G via \gdef inside the group,
and checks the group prints G and the following \a prints G; an
inline \global\def also expands.
2026-10-27 01:49:17 +08:00
gloamxun 16b61cd368 Freeze unexpanded tokens through an edef
\unexpanded passed its text straight through, so \edef\b{\unexpanded{\a}}
expanded \a at definition time. Split the expander into an inner pass with a
freeze flag: the edef-style wrapper protects each backslash in \unexpanded's
argument with the existing no-expand marker, which the pass restores on the way
out, while the normal document pass still writes the text through so it expands
at use time.

A test defines a=A, \edef b={\unexpanded{\a}}, redefines a=C, and checks \b
prints C with no warnings; the earlier \expanded/\unexpanded/\detokenize test
still passes.
2026-10-27 01:47:08 +08:00
gloamxun 4024fa7435 Add the route-D status handoff and fix README defaults 2026-10-27 01:43:17 +08:00