Skip to main content

Module dialect

Module dialect 

Source
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§

BeginItemizeOptions
configuration for begin_itemize
NewCounterOptions
configuration for new_counter
RawRefstep
A raw counter step a \label names (current_raw_refstep): the tags LaTeXML 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, \listparindent and \itemindent cleared, \@list<depth> run (the class’s \leftmargin and spacing), \makelabel reset (:15859), then setup, the list’s own second argument (its \makelabel). end_list_registers then narrows the line.
counter_for_type
The counter that \refstepcounter{<ctype>} steps: the counter_for_type mapping (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 \label made now names: \@currentlabel is 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 (\labelrel in {align*}).
define_counter_ids
The id half of new_counter (Perl Package.pm:689-705, NewCounter’s idprefix/idwithin/nested): records @ID@prefix@<ctr> and nested_counters_<ctr>, and defines \the<ctr>@ID and \@<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, not section1.subsection1); the register and its reset list stay the class’s.
define_item_fnum
The \fnum@<counter> an item’s tag defines as label (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 \label made the label mark_display_label announced.
end_list_registers
latex.ltx:15863-15867, after \@trivlist: \parskip\parsep, and \linewidth and \@totalleftmargin moved in by the list’s margins (\lx@list@margins; \parindent stays, sect06.rs).
forget_raw_refstep
Forgets the raw step locally, keeping it for renote_forgotten_raw_refstep: a listing starts, where listings makes \@currentlabel its line number’s (lstmisc.sty:1228 \lst@Init, and \refstepcounter{lstnumber} per line, :1225), so a \label in an unnumbered listing does not name a step made before it (a \refstepcounter{problem} then an lstlisting with (*\label{ln1}*): pdflatex the line’s 2; repro cross-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 \@currentlabel global after its \refstepcounter (algorithm2e.sty:1663 \gdef\@currentlabel{\theAlgoLine}, :1659 with hyperref), so that a \label after 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 \label makes (mark_display_label) name the step held here, not one made in a row. amsmath’s \label there is \label@in@display (amsmath.sty:1230-1236), which only stores the key; \make@display@tag makes the label in the row’s tag cell (:1240-1252, :1621-1627 {gather}, every row), after the cell group a \refstepcounter was 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@@@align makes the display tag only under \iftag@ (:1833-1843), so an untagged row’s label is the next tagged row’s (\df@label carried) or none (pdflatex ??), never a step held at the start (repro cross-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 \refstepcounter environment is equation 1). The kernel’s \label a document saved before (\let\originallabel\label at \begin{document}, the \labelrel idiom 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 ctype an 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 \captionof set 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 \label after 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 \label made now follows a counter step a group has since undone: LaTeX’s \label names \@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 counter ctr just stepped for ctype. Returns the tags and id properties.
leave_display_for_parbox
A paragraph box ({minipage}, \parbox, the kernel’s \@arrayparboxrestore) starts: amsmath’s \@arrayparboxrestore restores \label to 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; repro cross-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>@ID formatter chain reach \the<target>@ID? begin_itemize defines each list’s \the<usecounter>@ID through 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…@ID macros. 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@tags if it can act (label_can_act), else \lx@make@tags.
mark_display_label
The display’s own \label is making a label (amsmath’s \label@in@display, expanded): the kernel’s \label it reaches (directly, through cleveref’s, or after a row’s \noalign deferral) names the step current where the display started (hold_raw_refstep_for_display), until end_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 \@item sets 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 within is defined, ctr will be reset whenever within is incremented.
note_raw_refstep
Records the step a raw \refstepcounter made on counter (its props from label_stepped_counter), whose number LaTeX’s \label takes from \@currentlabel (latex.ltx:14963-14967), for the labels made after it (current_raw_refstep). Local, as LaTeX’s \@currentlabel is (\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, its raw_refstep_tags and raw_refstep_serial properties).
record_refstep_props
Records the props the kernel’s \refstepcounter label computed for a planned step on counter.
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 keys refnum and id.
ref_step_counter_by_meaning
\refstepcounter{<ctype>} through what \refstepcounter means now (ref_step_counter_planned).
ref_step_counter_planned
A counter step as LaTeX’s caption, equation, item and section steps are: \refstepcounter with its current meaning (latex.ltx:17391-17399 \refstepcounter\@captype, :15737-15738), so a rebinding applies — floatrow measures each floatbox under \FR@loc@, whose \refstepcounter is a local \advance undone 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 \stepcounter for 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@isinresetlist compares it with \ifx, cleveref.sty:658-685; fncylab’s \stepcounter{#1} reads it) — with ctype left 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). Guards perfect_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 \label made 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 alias as an alias counter of base, as aliascnt.sty’s \newaliascnt{alias}{base} makes it (aliascnt_sty.rs; llncs.cls v2.16+’s \@spothm, llncs_cls.rs): \refstepcounter{alias} steps base’s root counter (counter_for_type, following a chain of aliases), so the alias shares its number and its ids, while the type stays alias — the counter LaTeX’s \refstepcounter is 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_refstep forgot where the listing started: the box a tcolorbox listing box is, whose phantom code (its label) 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 (\newtcblisting with auto 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 ctr to zero.
reset_counter_in_cascade
reset_counter within one cascade: path holds the counters stepped or reset on the way to ctr, from path[0], which tex_step says TeX steps too (\stepcounter), not LaTeXML alone (an id’s UN counter, a reset). A cycle of reset lists (\newcounter{subsubsection}[subsubsection], AEA.cls:800, witness 2308.05200; any \@addtoreset/\numberwithin chain back to its start) loops in TeX’s \@stpelt (latex.ltx:10138) and in Perl’s ResetCounter (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; its UN companion, whose list mirrors its own, is not named).
reset_list_reaches
Whether resetting from resets target: target is in from’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@hook in 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 register begin_itemize labels 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
\@listdepth set globally to depth, its value put back where the current group ends by \lx@listdepth@restore (the \endlist half, latex.ltx:15913; a minipage’s \@mplistdepth, :16325).
step_counter
Analog of \stepcounter, steps the counter and returns the expansion of \the$ctr Usually you should use ref_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 counter makes, 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 \trivlist in LaTeX (center, theorem, proof).