Expand description
§Counters
This is modelled on LaTeX’s counter mechanisms, but since it also provides support for ID’s, even where there is no visible reference number, it is defined in general. These id’s should be both unique, and parallel the visible reference numbers (as much as possible). Also, for consistency, we add id’s to unnumbered document elements (eg from \section*); this requires an additional counter (eg. UNsection) and mechanisms to track it.
Structs§
- Begin
Itemize Options - configuration for begin_itemize
- NewCounter
Options - configuration for new_counter
- RawRefstep
- A raw counter step a
\labelnames (current_raw_refstep): thetagsLaTeXML makes for every step and the step’s serial.
Functions§
- add_
to_ counter - increments a named counter by a
Number - add_
to_ counter_ reset - Perl
addtoCounterReset(latex_constructs.pool.ltxml:3005-3012): put\<ctr>and\UN<ctr>at the front of\cl@<within>, globally, as latex.ltx:10156’s\@cons\xdefs — a reset registered inside a group outlives it — and re-derive the list’s macro. Repro macro-state/counter_reset_lists_are_global. - begin_
itemize - Prepare for an list (itemize/enumerate/description/etc) by determining the right counter (level) and binding the right \item ( $type@item, if $type is defined)
- begin_
list_ registers - latex.ltx:15854-15861
\list’s parameters, in the current group:\rightmargin,\listparindentand\itemindentcleared,\@list<depth>run (the class’s\leftmarginand spacing),\makelabelreset (:15859), thensetup, the list’s own second argument (its\makelabel).end_list_registersthen narrows the line. - counter_
for_ type - The counter that
\refstepcounter{<ctype>}steps: thecounter_for_typemapping (theorem types sharing a counter), else<ctype>itself. - counter_
value - Fetches the value associated with the counter C<$ctr>.
- current_
raw_ refstep - The raw step (
note_raw_refstep) a\labelmade now names:\@currentlabelis still the step’s\the<counter>, not text a package defined since (\protected@edef\@currentlabel{…}); for an amsmath display’s own\label(mark_display_label) the step current where the display started (hold_raw_refstep_for_display). Witnesses: 2506.01072 (\newtcbtheorem), 2505.20088 (\newtcolorbox[auto counter]), 2402.06608 ([blend into= figures]), 2609.20563 (\newtcblisting), 2310.19138 (\labelrelin{align*}). - define_
counter_ ids - The id half of
new_counter(Perl Package.pm:689-705,NewCounter’sidprefix/idwithin/nested): records@ID@prefix@<ctr>andnested_counters_<ctr>, and defines\the<ctr>@IDand\@<ctr>@ID. A binding calls it alone for a counter a raw class declared, to give it the ids its standard-class binding gives (the KOMA classes,koma_script.rs:S1.SS1, notsection1.subsection1); the register and its reset list stay the class’s. - define_
item_ fnum - The
\fnum@<counter>an item’s tag defines aslabel(Perl latex_constructs.pool.ltxml:1391, :1650): when the label is the author’s own\fnum@<counter>(\list{\fnum@figcaption}{\usecounter{figcaption}}), whose label TeX typesets with\fnum@untouched (latex.ltx\@item), the author’s meaning is kept as\lx@author@fnum@<counter>and the label calls that, so the new\fnum@<counter>no longer expands into itself (Perl: one Error; we looped to a Fatal: cond-mat9505034). KNOWN_PERL_ERRORS #1325. The returned tokens make the definition. - end_
display_ label - The kernel’s
\labelmade the labelmark_display_labelannounced. - end_
list_ registers - latex.ltx:15863-15867, after
\@trivlist:\parskip\parsep, and\linewidthand\@totalleftmarginmoved in by the list’s margins (\lx@list@margins;\parindentstays, sect06.rs). - forget_
raw_ refstep - Forgets the raw step locally, keeping it for
renote_forgotten_raw_refstep: a listing starts, where listings makes\@currentlabelits line number’s (lstmisc.sty:1228\lst@Init, and\refstepcounter{lstnumber}per line, :1225), so a\labelin an unnumbered listing does not name a step made before it (a\refstepcounter{problem}then anlstlistingwith(*\label{ln1}*): pdflatex the line’s 2; reprocross-references/listing_label_names_no_step_before_it.tex). - globalize_
raw_ refstep - The raw step recorded now (
note_raw_refstep) stays recorded after the group it was made in: a package that makes\@currentlabelglobal after its\refstepcounter(algorithm2e.sty:1663\gdef\@currentlabel{\theAlgoLine}, :1659 with hyperref), so that a\labelafter the group (\While{c}{\label{x} …}, the line’s number made in the header’s group) still names the step (\lx@refstep@global, algorithm2e_sty.rs). Witness 1602.05866 (algline:mainloop, PDF 8). - hold_
raw_ refstep_ for_ display - An amsmath display starts (
{gather},{align},{multline},{aligned}… and their starred forms): the labels its own\labelmakes (mark_display_label) name the step held here, not one made in a row. amsmath’s\labelthere is\label@in@display(amsmath.sty:1230-1236), which only stores the key;\make@display@tagmakes the label in the row’s tag cell (:1240-1252, :1621-1627{gather}, every row), after the cell group a\refstepcounterwas made in restored\@currentlabel—\begin{gather*} u=v \refstepcounter{foo}\label{e6} \end{gather*}is the section’s 7 in pdflatex.names_the_step: the display’s labels may name the step current here ({gather}, and an{aligned}/{split}in an{equation*}: pdflatex 44, 45). Not for the align family ({align},{flalign},{alignat}) and{multline}, starred or not:\math@cr@@@alignmakes the display tag only under\iftag@(:1833-1843), so an untagged row’s label is the next tagged row’s (\df@labelcarried) or none (pdflatex??), never a step held at the start (reprocross-references/amsmath_row_label_names_the_display_step.tex, review probe rev78g2 al2.tex:\begin{align} a&=b \label{n2}\notag \\ c&=d \end{align}in a\refstepcounterenvironment is equation 1). The kernel’s\labela document saved before (\let\originallabel\labelat\begin{document}, the\labelrelidiom of 2310.19138) labels at once, after the cell’s step (“a”). Local to the display; an inner one ({aligned}in{gather*}) keeps the outer’s. The outermost start forgets a display label announced and never made (mark_display_label). - is_
counter_ alias - Is
ctypean alias counter (register_counter_alias)? - keep_
latest_ refstep_ in_ scope - The latest counter step stays the one in scope although the group it was made in has closed: a wrapper group of
LaTeXML’s own (caption’s
\captionofset in a float, caption_sty.rs\@captionof@) around a step LaTeX makes in the current group (caption.sty:390-391\setcaptiontype*then\caption), so a\labelafter it names the step’s object (2402.05535\captionof{figure}{…}\fi\label{…}). - label_
calls_ fnum - Whether an item label calls
\fnum@<counter>itself (define_item_fnum). - label_
can_ act - Create id, and tags for an itemize type \item
Whether a label the document wrote can act when its reference forms re-read it: it holds a control sequence or an
active character (a
\footnote,\label,\index, a\stepcounter). A label of characters only (\item[(b)]) has nothing for them to neutralize (tag_forms, OD #1233) nor to undo (OD #1250) and pays nothing. - label_
follows_ an_ undone_ step - Whether a
\labelmade now follows a counter step a group has since undone: LaTeX’s\labelnames\@currentlabel(latex.ltx:14963-14967), which reverts when the group of the step that set it closes, so a label after\end{equation}inside a theorem names the theorem, not the equation (math0107195, “Theorem 5.3”). Such a label never names the object that closed step numbered, however near it is (Document::float_to_label_scoped). - label_
stepped_ counter - The labelling half of
\refstepcounter(latex.ltx:14956-14967, after its\stepcounter):\@currentlabel,\@currentID, the tags and the counter’s scope, for the counterctrjust stepped forctype. Returns thetagsandidproperties. - leave_
display_ for_ parbox - A paragraph box (
{minipage},\parbox, the kernel’s\@arrayparboxrestore) starts: amsmath’s\@arrayparboxrestorerestores\labelto the kernel’s (amsmath.sty:1237-1238\let\label\ltx@label), so a label in the box is made at once and names the step current in it, not the display’s held step (review probe rev78g2 nest.tex z5,\begin{gather*} a=b \refstepcounter{foo}\text{\begin{minipage}{2cm}\label{z5}x\end{minipage}} \end{gather*}: pdflatex 42; reprocross-references/amsmath_row_label_names_the_display_step.tex). Local to the box. Outside an amsmath display nothing. - list_
depth - The current
\@listdepth. - list_
id_ chain_ reaches - Does the
\the<start>@IDformatter chain reach\the<target>@ID?begin_itemizedefines each list’s\the<usecounter>@IDthrough its own\the<listcounter>@ID, which is defined through the enclosing list’s\the<outerusecounter>@ID— so the open lists form a chain of\the…@IDmacros. Walking the bodies (never expanding) is bounded by the nesting depth. - make_
tags_ for - The tags of a label the document wrote:
\lx@make@reread@tagsif it can act (label_can_act), else\lx@make@tags. - mark_
display_ label - The display’s own
\labelis making a label (amsmath’s\label@in@display, expanded): the kernel’s\labelit reaches (directly, through cleveref’s, or after a row’s\noaligndeferral) names the step current where the display started (hold_raw_refstep_for_display), untilend_display_label. - maybe_
note_ label - Use to note a discovered label to support label-derived refererence numbers Can by used by \label, among others. Note we only record the label if it hasn’t already been peeked, and consumed.
- maybe_
peek_ label - Use to peek for FOLLOWING \label{…} to support label-derived reference numbers (Perl: MaybePeekLabel)
- net_
label_ labelsep - latex.ltx:16028-16039
\@itemsets the label’s box after\hskip-\labelsep, so the glue a label opens with (\hskip\labelsep, :17206\@begintheorem, article.cls:364\descriptionlabel) nets against it: of the label’s leading run of skips and kerns, an\unhboxed box’s too,max(0, sum - \labelsep)stays (\lx@item@labelbox). Witnesses 1508.03599 (acmlarge.cls:628\hskip10pt\hskip\labelsep: 10pt), 2605.07451 (syntax.sty:244: none). - new_
counter - Defines a new counter named $ctr.
If
withinis defined,ctrwill be reset wheneverwithinis incremented. - note_
raw_ refstep - Records the step a raw
\refstepcountermade oncounter(itspropsfromlabel_stepped_counter), whose number LaTeX’s\labeltakes from\@currentlabel(latex.ltx:14963-14967), for the labels made after it (current_raw_refstep). Local, as LaTeX’s\@currentlabelis (\protected@edef): a box’s step stays in the box. Any other step forgets it (label_stepped_counter). Witnesses: 2506.01072 (\newtcbtheorem), 2505.20088 (\newtcolorbox[auto counter]), 2402.06608 ([blend into=figures]), 2609.20563 (\newtcblisting). - raw_
refstep_ of - The raw step a
\label’s whatsit recorded (current_raw_refstep, itsraw_refstep_tagsandraw_refstep_serialproperties). - record_
refstep_ props - Records the props the kernel’s
\refstepcounterlabel computed for a planned step oncounter. - ref_
current_ id - Recycle the last ID without incrementing (Perl: RefCurrentID) Useful if the last ID-ed box got pruned.
- ref_
step_ counter - Analog of
\refstepcounter, steps the counter and returns a hash containing the keysrefnumandid. - ref_
step_ counter_ by_ meaning \refstepcounter{<ctype>}through what\refstepcountermeans now (ref_step_counter_planned).- ref_
step_ counter_ planned - A counter step as LaTeX’s caption, equation, item and section steps are:
\refstepcounterwith its current meaning (latex.ltx:17391-17399\refstepcounter\@captype, :15737-15738), so a rebinding applies — floatrow measures each floatbox under\FR@loc@, whose\refstepcounteris a local\advanceundone with the box (floatrow.sty:543-556); cleveref’s (and hyperref’s, on a format before 2024-11-01) wrap the kernel’s; crossreference.sty and old varioref copy it. As caption does (caption.sty:551-570):before(its prepare hook) is digested first, and a continued float’s step suppresses the counter’s own\stepcounterfor the length of the\refstepcounter(\caption@@refcounter), so the number repeats without resets. With the kernel meaning this is direct; otherwise\refstepcounter{<counter>}is digested — the counter’s name in letters, as LaTeX passes it (cleveref’s\cref@isinresetlistcompares it with\ifx, cleveref.sty:658-685; fncylab’s\stepcounter{#1}reads it) — withctypeleft for the kernel’s label to make the tags of (a shared-counter theorem’s own type); the props are the ones it recorded, else (a rebinding that never reaches the kernel) the label of the counter’s value as it now stands. Perl steps the counter directly (RefStepCounter; KPE #412). Witness kaytannollista-latexia (floatrow), 2605.17685 (continued floats). Guardsperfect_kernel_batch58::{caption_steps_through_refstepcounter, floatrow_floatbox_steps_its_counter_once, floatbox_steps_its_equation_once, steps_keep_their_type_and_continuation_through_a_wrapper}. - ref_
step_ id - For UN-numbered units.
Like
RefStepCounter, but only steps the “uncounter”, and returns only the id; This is useful for unnumbered cases of objects that normally get both a refnum and id. - ref_
step_ item_ counter - refstep_
in_ scope - The serial of the counter step in scope, which a
\labelmade now names (\@currentlabel, latex.ltx:14963): what tells a step made inside a frontmatter item from one made before it (\lx@set@frontmatter@label). - register_
counter_ alias - Records
aliasas an alias counter ofbase, as aliascnt.sty’s\newaliascnt{alias}{base}makes it (aliascnt_sty.rs; llncs.cls v2.16+’s\@spothm, llncs_cls.rs):\refstepcounter{alias}stepsbase’s root counter (counter_for_type, following a chain of aliases), so the alias shares its number and its ids, while the type staysalias— the counter LaTeX’s\refstepcounteris passed, whose name hyperref gives the target (\<alias>autorefname,\<alias>name;is_counter_alias). Witnesses 2605.20695 (aliascnt lemmas), 2202.10090 (llncs, envcountsame). - remove_
from_ counter_ reset - Perl
remfromCounterReset(latex_constructs.pool.ltxml:3014-3022): drop\<ctr>and\UN<ctr>from\cl@<within>, globally (latex.ltx:10170\xdef), when there is a list. - renote_
forgotten_ raw_ refstep - Notes again, locally, the step
forget_raw_refstepforgot where the listing started: the box a tcolorbox listing box is, whose phantom code (itslabel) runs before the listing in the box (tcolorbox.sty:1154-1161, :1925) while this port runs it in the listing’s first line (listings_sty::with_tcb_phantom): its label names the box’s step (\newtcblistingwithauto counter, 2609.20563). - rescue_
caption_ counters - Copies the current id, tags, and inlist counter values into whatsit properties Perl: RescueCaptionCounters (latex_constructs.pool.ltxml L3203-3214)
- reset_
counter - Resets the counter
ctrto zero. - reset_
counter_ in_ cascade reset_counterwithin one cascade:pathholds the counters stepped or reset on the way toctr, frompath[0], whichtex_stepsays TeX steps too (\stepcounter), not LaTeXML alone (an id’sUNcounter, a reset). A cycle of reset lists (\newcounter{subsubsection}[subsubsection], AEA.cls:800, witness 2308.05200; any\@addtoreset/\numberwithinchain back to its start) loops in TeX’s\@stpelt(latex.ltx:10138) and in Perl’sResetCounter(Package.pm:892, deep recursion) once stepped. A counter already on the path is reset, so it is skipped: an Error where TeX’s own lists loop from that step (“TeX capacity exceeded”), else a Warning naming it (each once; itsUNcompanion, whose list mirrors its own, is not named).- reset_
list_ reaches - Whether resetting
fromresetstarget:targetis infrom’s reset list (\cl@<from>), or in the list of a counter there, and so on. - reset_
refstep_ state - Forgets pending steps and recorded props (per document: they hold its symbols).
- run_
trivlist_ hook - Runs
\lx@trivlist@hookin the current group: what a package adds to latex.ltx’s\@trivlist, which every list but an in-paragraph one runs (:15862; tabu.sty:2390\tabu@trivlist) and which is locked here (sect06.rs). - set_
counter - Perl
SetCounter(Package.pm:722): assign\\c@<ctr>globally, run any\\afterassignment, re-derive\\@<ctr>@ID. - set_
enumeration_ style - Set the enumeration style for a given level. Perl: setEnumerationStyle($stuff, $level) Parses the style tokens to detect A/a/I/i/1 patterns and defines \theenum$level and \labelenum$level accordingly.
- set_
itemization_ style - Set the itemization style for a given level.
Perl: setItemizationStyle($stuff, $level)
If $level is not given, uses the current itemize depth: paralist.sty:281-282 names the label
labelitem\romannumeral\the\@itemdepth, the registerbegin_itemizelabels an itemize by. Perl reads@itemlevel, which also counts kernel\lists (PERL-ORIGIN; repro list-structure/itemize_label_follows_the_itemize_depth). Defines \labelitem$level to $stuff. - set_
list_ depth \@listdepthset globally todepth, its value put back where the current group ends by\lx@listdepth@restore(the\endlisthalf, latex.ltx:15913; a minipage’s\@mplistdepth, :16325).- step_
counter - Analog of
\stepcounter, steps the counter and returns the expansion of\the$ctrUsually you should useref_step_counter(ctr)instead. - step_
list_ depth - latex.ltx:15852
\list’s\global\advance\@listdepth\@ne(set_list_depth). - strip_
counter_ type_ sentinel <ctype>without a trailing sentinel control sequence the parameter reader may have pulled in.- sync_
reset_ list_ macro - Mirror the reset list into the
\cl@<ctr>MACRO latex.ltx exposes. - take_
pending_ step - The type whose tags the step in progress on
countermakes, if a binding planned one (the kernel’s\lx@refstepcounter). - trivlist_
registers - latex.ltx:15903-15910
\trivlist:\parsep\parskip, and no label or left margin (\lx@trivlist@margins), the line as wide as around it. For the environments that are a\trivlistin LaTeX (center, theorem, proof).