% \iffalse meta-comment % % Copyright (C) 2026 Evan Berkowitz % % This work may be distributed and/or modified under the conditions of the % LaTeX Project Public License, either version 1.3c of this license or (at % your option) any later version. The latest version of this license is in % https://www.latex-project.org/lppl.txt % and version 1.3c or later is part of all distributions of LaTeX % version 2008 or later. % % This work has the LPPL maintenance status `maintained'. % The Current Maintainer of this work is Evan Berkowitz. % This work consists of the files mermin-equations.dtx and % mermin-equations.ins and the derived file mermin-equations.sty. % % \fi % % \iffalse %<*driver> \ProvidesFile{mermin-equations.dtx} % %\NeedsTeXFormat{LaTeX2e}[2021/11/15] %\ProvidesPackage{mermin-equations} %<*package> [2026/11/18 v0.1.1 Mermin-style equation tools] % % %<*driver> \documentclass{ltxdoc} \PassOptionsToPackage{hidelinks}{hyperref} % doc before v3 (LaTeX 2022-06) does not load hyperref for \href and % \url; hypdoc does, without breaking doc's index entries as a bare % \usepackage{hyperref} would. \IfFormatAtLeastTF{2022-06-01}{}{\usepackage{hypdoc}} \usepackage{amsmath} \usepackage{mermin-equations} \EnableCrossrefs \CodelineIndex \RecordChanges \begin{document} \DocInput{mermin-equations.dtx} \PrintChanges \clearpage \PrintIndex \end{document} % % \fi % % \changes{v0.1}{2026/11/17}{Initial version, providing \cs{aka} (\cs{alsolabel}) and \cs{eq} (\cs{eqcite}).} % \changes{v0.1.1}{2026/11/18}{Renamed from \textsf{mermin} to \textsf{mermin-equations} at CTAN's request; the commands are unchanged.} % % \GetFileInfo{mermin-equations.sty} % % \DoNotIndex{\begingroup,\endgroup,\def,\gdef,\let,\global,\else,\fi} % \DoNotIndex{\ifx,\ifdefined,\expandafter,\noexpand,\unexpanded,\xdef} % \DoNotIndex{\newcommand,\newif,\label,\do,\the,\toks@,\@xp,\@empty} % \DoNotIndex{\AddToHook,\NeedsTeXFormat,\ProvidesPackage,\RequirePackage} % \DoNotIndex{\@ifnextchar,\endinput} % % \title{The \textsf{mermin-equations} package\thanks{This document corresponds to % \textsf{mermin-equations}~\fileversion, dated \filedate.}} % \author{Evan Berkowitz} % \date{\filedate} % % \maketitle % % \begin{abstract} % The \textsf{mermin-equations} package helps physicists write equations the way % N.~David Mermin asks in ``What's Wrong with These Equations?''\ % \cite{mermin}. % An equation is labeled by the noun phrases that describe it, as many as % the prose needs, with \cs{aka}, and cited by one of those phrases % with \cs{eq}, which prints the phrase and the number together. % Citing an equation by a bare number becomes the harder thing to write. % \end{abstract} % % \section{Introduction} % % In his 1989 column~\cite{mermin} Mermin proposed three rules for % equations in physics writing. % Fisher's rule asks that every displayed equation be numbered, whether or % not the text refers to it yet, because readers, referees, and later papers % will. % The Good Samaritan rule asks that an equation be cited by a phrase as well % as a number, so that the reader need not page back to learn what % ``(11)'' says: one writes ``the anomaly condition~(11)'', never a bare % ``(11)'' and never ``Eq.~(11) shows''. % An equation number locates; the noun phrase says what is there. % The third rule, that mathematics is prose, asks that a display be % punctuated as part of its sentence, so that the paragraph reads straight % through the equation. % % \LaTeX\ makes the Good Samaritan rule harder than it need be. % A label is an arbitrary key, so nothing ties a citation to the phrase % that should accompany it, and \textsf{amsmath} allows a numbered line % exactly one \cs{label}, although the right phrase depends on why the % equation is being cited. % The same line may be ``the anomaly condition'' in one paragraph and % ``the Pythagorean condition'' in another. % This package makes the phrase the key. % A line is labeled by each phrase that describes it, and \cs{eq} cites it % by one of them, printing the phrase and the number. % % \section{Usage} % % \DescribeMacro{\aka} % \DescribeMacro{\eq} % Load the package with |\usepackage{mermin-equations}|. % Then |\aka{|\meta{phrase}|}|, for ``also known as'', attaches % \meta{phrase} as a key to the % current equation, or to the current line of a multi-line display, in % addition to its \cs{label}. % It may be used any number of times on a line, before or after the % \cs{label}, or on a line that has no \cs{label} at all. % Every key refers to the same number and, with \textsf{hyperref}, to the % same anchor. % |\eq{|\meta{phrase}|}| prints \meta{phrase}, a tie, and the equation % number in parentheses, linked by \textsf{hyperref} to the equation. % % Consider two-flavor chiral gauge theories in two dimensions, whose gauge % anomaly cancels when the left- and right-handed charges obey % \begin{equation} % L_1^2+L_2^2=R_1^2+R_2^2. % \label{anomaly condition} % \aka{Pythagorean condition} % \end{equation} % The source of this display, and of a paragraph that cites it, reads % \begin{verbatim} % \begin{equation} % L_1^2+L_2^2=R_1^2+R_2^2. % \label{anomaly condition} % \aka{Pythagorean condition} % \end{equation} % % The 3450 model, with charges $(3,4\,\vert\,5,0)$, satisfies % the \eq{anomaly condition}. % Read as a statement about integers, the same line is % the \eq{Pythagorean condition}, and $3^2+4^2=5^2$ is its % smallest nontrivial solution. % \end{verbatim} % and typesets as % \begin{quote} % The 3450 model, with charges $(3,4\,\vert\,5,0)$, satisfies % the \eq{anomaly condition}. % Read as a statement about integers, the same line is % the \eq{Pythagorean condition}, and $3^2+4^2=5^2$ is its % smallest nontrivial solution. % \end{quote} % We advise leaving the article out of the phrase and in the prose. % Capitalization is the reason. % A sentence that opens with a citation needs ``The'', one that cites in % the middle needs ``the'', and |The \eq{anomaly condition}| handles both, % because the capital falls on the article, which the sentence supplies. % With the article inside the key, the capitalized and lowercase forms % would be different labels. % Keeping it out also leaves the sentence free to say ``this'', ``that'', % or nothing at all. % This is only advice: a label such as |the anomaly condition| works like % any other key. % % Lines of an \textsf{align} are labeled the same way, one set of phrases % per line, and a line may be labeled by \cs{aka} alone: % \begin{verbatim} % \begin{align} % S &= \int d^2x\,\mathcal{L} \label{action} \aka{fermion action} \\ % P_{L,R} &= \tfrac12(1\pm\gamma_5) \aka{chiral projectors} % \end{align} % \end{verbatim} % % \subsection{Phrases and keys} % % Labels written with an |eq:| prefix, as many papers already have, need % no change: when no label \meta{phrase} exists, \cs{eq} uses % |eq:|\meta{phrase}. % For example, |\eq{shift relation}| cites the line labeled % |\label{eq:shift relation}|; so does |\eq{eq:shift relation}|, and both % print ``shift relation'', without the prefix. % If |shift relation| labels a section, say, and |eq:shift relation| % an equation, \cs{eq} cites the equation; if both label equations, % different ones, \cs{eq} cites the first and warns. % % \cs{eq} prints its argument as the phrase. % A phrase that cannot be a key, because it contains mathematics or a % command, is given where the label is defined, as the optional argument of % \cs{aka}, and every citation then uses the plain key. % For example, a compact boson on a lattice may be given the Villain action % \begin{equation} % S_\Gamma=\frac{\beta}{2}\sum_{\ell}\left(d\phi-2\pi n\right)_\ell^2. % \aka[$\Gamma$ action]{Gamma action} % \aka{Villain model} % \end{equation} % The source of this display, and of a paragraph that cites it by both % phrases, reads % \begin{verbatim} % \begin{equation} % S_\Gamma=\frac{\beta}{2}\sum_{\ell}\left(d\phi-2\pi n\right)_\ell^2. % \aka[$\Gamma$ action]{Gamma action} % \aka{Villain model} % \end{equation} % % The integer field $n$ makes the \eq{Gamma action} invariant % under $\phi\to\phi+2\pi k$ with $n\to n+dk$. % Summed over $n$, the \eq{Villain model} is a periodic function % of each $d\phi_\ell$. % \end{verbatim} % and typesets as % \begin{quote} % The integer field $n$ makes the \eq{Gamma action} invariant % under $\phi\to\phi+2\pi k$ with $n\to n+dk$. % Summed over $n$, the \eq{Villain model} is a periodic function % of each $d\phi_\ell$. % \end{quote} % % A key that is not printable text, such as |E_field|, needs a phrase in % the same way. % Without one \cs{eq} prints the key verbatim and, once the label exists, % warns. % To give a phrase to a line that already has a \cs{label}, add \cs{aka} % with the same key, |\label{E_field}\aka[$E$ field]{E_field}|, or replace % the \cs{label} with it. % % \subsection{How \cs{aka} behaves} % % Because \cs{label} is left alone, two \cs{label}s on one line remain the % error \textsf{amsmath} has always reported; only \cs{aka} adds keys. % Citing a key with \cs{ref}, \cs{eqref}, \cs{pageref}, or the % \textsf{cleveref} command \cs{cref} works exactly as for a key given to % \cs{label}. % Outside a display \cs{aka} is simply \cs{label}, so it can also give a % section, a figure, or a theorem a second name, and it may stand inside a % heading or caption just as \cs{label} may. % \cs{eq}, however, is for equations only, since it prints a parenthesized % number, and it warns when its key names anything else. % % On a line without a number, such as one with \cs{notag} or in % |equation*|, \cs{aka} does what \cs{label} would do there, which is % seldom what is wanted, and \cs{eq} cannot tell: on an \textsf{align} % line it labels the next numbered line, even one with its own % \cs{label}, or nothing on the last line; in \textsf{gather} its number % is empty; and in |equation*| it takes the section's number. % Put it on a numbered line. % % \subsection{Mermin's rules as warnings} % % Two of Mermin's rules become warnings, which never stop compilation. % \emph{Fisher's rule}, ``number all displayed equations'', warns at % every \textsf{amsmath} display, \textsf{empheq}, or \textsf{eqnarray} % that typesets no number: |equation*|, |\[|\ldots|\]|, or an % \textsf{align} whose every line is \cs{notag}. % (Other packages' unnumbered displays, such as \textsf{breqn}'s |dmath*|, % and plain \TeX's |$$|\ldots|$$|, are not checked.) % A derivation that is numbered once, on its last line, is one equation % and is numbered: % \begin{verbatim} % \begin{align} % f &= g \nonumber\\ % &= h \label{f=h} % \end{align} % \end{verbatim} % The \textsf{mathtools} option |showonlyrefs|, which numbers only the % equations that are cited, is the practice Mermin calls Occam's rule, a % heresy; with it, one warning says so. % The \emph{Good Samaritan rule}, ``when referring to an equation identify % it by a phrase as well as a number'', warns at every \cs{eqref}, % \cs{cref}, \cs{Cref}, or \cs{labelcref} of an equation, even one that % words precede, as in |the Dirac equation~\eqref{Dirac}|: \cs{eq} gives % the phrase and the number together, from one place. % Page references such as \cs{cpageref} are not checked, and neither is % plain \cs{ref}, which other commands use internally; so % |Eq.~(\ref{x})|, a common REVTeX style, passes unremarked. % The options |nofisher| and |nosamaritan| turn the warnings off. % % The warnings appear in the log file, and in the summaries of tools such % as \texttt{latexmk}, like this: % \begingroup % \def\MacroFont{\footnotesize\ttfamily} % \begin{verbatim} % Package mermin-equations Warning: `equation*' display without a number. % (mermin-equations) Fisher's rule: number every display % (mermin-equations) (option nofisher) on input line 4. % % Package mermin-equations Warning: `chain' is cited by number alone. % (mermin-equations) Good Samaritan rule: name it, as \eq does % (mermin-equations) (option nosamaritan) on input line 12. % \end{verbatim} % \endgroup % The first names the environment (|\[|\ldots|\]| is |equation*|) and % the line where the display ends; the second names the key and the line % of the citation. % With |showonlyrefs| a single warning appears at |\begin{document}|: % \begingroup % \def\MacroFont{\footnotesize\ttfamily} % \begin{verbatim} % Package mermin-equations Warning: mathtools' showonlyrefs numbers only the % (mermin-equations) equations that are cited, which Mermin calls % (mermin-equations) Occam's rule; Fisher's rule numbers them all % (mermin-equations) (option nofisher silences this). % \end{verbatim} % \endgroup % % \subsection{Long names} % % \DescribeMacro{\alsolabel} % \DescribeMacro{\eqcite} % Short names are easily taken. % \cs{alsolabel} and \cs{eqcite} are the same commands as \cs{aka} and % \cs{eq}, under names no other package uses. % Several packages, among them \textsf{nccmath}, define their own \cs{eq}, % and a document may define its own \cs{aka}. % \textsf{mermin-equations} then leaves the existing command alone, says so in a % warning, and the document uses the long name instead. % % \section{Compatibility} % % \subsection{Requirements and loading} % % The package requires a \LaTeX\ format from 2021-11-15 or later, for the % hooks it uses, and loads \textsf{amsmath}. % Load \textsf{amsmath} with options, such as |fleqn|, before % \textsf{mermin-equations}, as before any package that loads it. % \textsf{hyperref} and \textsf{cleveref} may be loaded before or after % \textsf{mermin-equations}; \textsf{cleveref}, as always, after \textsf{amsmath}. % arXiv compiles papers with its own fixed \TeX\ Live installations, which % do not receive new packages, so a paper submitted there should include % \texttt{mermin-equations.sty} among its files. % % \subsection{Displays} % % The package works in the \textsf{amsmath} environments \textsf{equation}, % \textsf{align}, \textsf{gather}, \textsf{multline}, \textsf{split} (with % the keys given in the enclosing \textsf{equation}), and % \textsf{subequations}, and in \textsf{empheq}; in \textsf{breqn}'s % |dmath|, |dseries|, and |dgroup|; in the \textsf{cases} package's % |numcases| and |subnumcases|; in \textsf{IEEEtrantools}' |IEEEeqnarray|; % in \textsf{subeqnarray}; and in the kernel's \textsf{eqnarray}. % With the \textsf{mathtools} option |showonlyrefs|, a line is numbered % when any of its keys is cited. % % \subsection{Other documents} % % With \textsf{xr} or \textsf{xr-hyper}, |\eq{S-|\meta{key}|}| cites an % equation of a document loaded with |\externaldocument[S-]|, and prints % its phrase, or its key without the prefix; the |eq:| fallback reaches % it too, so |\eq{S-sum rule}| cites |\label{eq:sum rule}| there. % A document that does not use \textsf{mermin-equations} has no record of which % labels are equations, so \cs{eq} treats all of its labels as equations. % Load \textsf{mermin-equations} before calling \cs{externaldocument}: a document % read earlier is imported without its phrases or its record of which % labels are equations, so its keys print with the prefix, the |eq:| % fallback does not reach it, and \cs{eq} warns about every one. % % A paper that adopts \textsf{mermin-equations} while \cs{includeonly} leaves out % chapters may see such warnings for equations in those chapters, until % each is compiled once with the package. % % \subsection{Headings, bookmarks, and running heads} % % \cs{aka}, like \cs{label}, vanishes from tables of contents, running % heads, and PDF bookmarks. % In a bookmark \cs{eq} gives its phrase and number as plain text. % A phrase with mathematics is dropped from bookmarks, as mathematics is % from any bookmark; \textsf{hyperref}'s \cs{texorpdfstring} gives a % plain-text form, as in |\aka[\texorpdfstring{$E$}{E} field]{E_field}|. % % In a heading or running head that a class sets in capitals with % \cs{MakeUppercase}, the phrase is left as written, from the \LaTeX\ % release of 2022-06 on, since it is printed % from its key; for a running head, give the heading a short form without % \cs{eq}, as in |\section[|\ldots|]{|\ldots|}|. % REVTeX sets the section headings themselves in capitals, and the phrase % stays lowercase there (``THE anomaly condition (1)''); \cs{eqref} in % the same place fails altogether, printing ``(??)''. % Classes that use the primitive \cs{uppercase}, such as \textsf{mnras} % and \textsf{aastex631}, capitalize the key itself, which breaks % \cs{eq} there as it breaks \cs{eqref}; wrap such a citation in a % command defined in the preamble. % % \subsection{Classes and tools} % % In \textsf{beamer}, |\aka<|\meta{overlay}|>| passes the overlay to % \cs{label}, as |\label<|\meta{overlay}|>| does. % In a display the overlay of \cs{aka} or \cs{label} is dropped, and the % label's anchor is on the frame's first slide. % % The \textsf{iopart} class conflicts with \textsf{amsmath}, which this % package loads; when \textsf{iopart} is the class, the package applies % IOP's usual remedy, undefining |equation*| first. % % \textsf{latexdiff} shows a changed \cs{eq} only when told that it is % safe to keep in deleted text, with |--append-safecmd=eq,eqcite|; do not % add |aka|, which would bring deleted labels back. % An \cs{aka} in text \textsf{latexdiff} marks as deleted is ignored. % % \textsf{showkeys} and \textsf{showlabels} show the first key of a display % line, not the keys \cs{aka} adds to it. % % \subsection{Not supported} % % \textsf{autonum} copies \cs{label} before this package can attach its % extra keys, and numbers a line by its first key only. % \textsf{witharrows}' |DispWithArrows| keeps its labels where \cs{aka} % cannot reach them. % % \section{Testing} % % The package's repository, % \url{https://github.com/evanberkowitz/mermin}, also holds a test suite % and the issue tracker. % Running |make test| there typesets every environment above, with the % keys given before, after, and instead of \cs{label}, in four package % configurations, and checks that each key in the resulting \texttt{.aux} % file carries its line's number and anchor. % It also checks the text \cs{eq} prints, its warnings, and each of the % interactions above. % The suite runs with pdf\LaTeX, Lua\LaTeX, and Xe\LaTeX\ on the current % \TeX\ Live, and with pdf\LaTeX\ on \TeX\ Live 2021, 2023, and 2025. % % \begin{thebibliography}{1} % \bibitem{mermin} % N.~D. Mermin, ``What's Wrong with These Equations?'', % \emph{Physics Today} \textbf{42}(10), 9 (1989), % \href{https://doi.org/10.1063/1.2811173}{doi:10.1063/1.2811173}. % \end{thebibliography} % % \StopEventually{} % % \section{Implementation} % % The implementation has eleven parts. % Parts~\ref{impl:load}--\ref{impl:aux} set up the package and the records % it keeps in the \texttt{.aux} file. % Parts~\ref{impl:aka}--\ref{impl:queue} define \cs{alsolabel} and the % machinery that gives a display line several keys. % Part~\ref{impl:xr} imports the records of another document through % \textsf{xr}. % Parts~\ref{impl:cite}--\ref{impl:short} define \cs{eqcite} and the % short names, and make both behave in headings and bookmarks. % Part~\ref{impl:rules} turns two of Mermin's rules into warnings. % % The narrative is here; the code carries short comments wherever a % construction looks odd or exists for one particular package, kernel % version, or engine, so that a reader of the bare \texttt{mermin-equations.sty} is % not lost. % Two words are kept apart: a key is \emph{marked} when it is recorded as % an equation, and an \texttt{.aux} file is \emph{signed} when it was % written with this package. % % \subsection{Loading}\label{impl:load} % % The package needs \textsf{amsmath}, whose display machinery it extends. % IOP's \textsf{iopart} class defines |equation*| itself, which % \textsf{amsmath} then refuses to redefine; IOP's documented remedy is to % undefine it first, and the package does so when \textsf{iopart} is the % class and \textsf{amsmath} is not yet loaded. % \begin{macrocode} %<*package> % iopart.cls defines equation*, and amsmath would stop with "Command % \equation* already defined"; this is IOP's own workaround. amsmath's % \@xp is not defined yet, hence \expandafter. \@ifclassloaded{iopart}{% \@ifpackageloaded{amsmath}{}{% \expandafter\let\csname equation*\endcsname\relax \expandafter\let\csname endequation*\endcsname\relax}}{} \RequirePackage{amsmath} % \end{macrocode} % % Two options turn off the warnings of part~\ref{impl:rules}. % \begin{macrocode} \newif\ifmermin@fisher \mermin@fishertrue \newif\ifmermin@samaritan \mermin@samaritantrue \DeclareOption{nofisher}{\mermin@fisherfalse} \DeclareOption{nosamaritan}{\mermin@samaritanfalse} \ProcessOptions\relax % \end{macrocode} % % \subsection{Utilities}\label{impl:util} % % \begin{macro}{\mermin@warn} % \begin{macro}{\mermin@warn@noline} % Every warning goes through these, so the package's name is written once. % A warning's lines are kept under 45 characters: the prefix % |(mermin-equations)| and its padding take 34 of the 79 that \TeX\ % prints before it breaks a line of the log. % \begin{macrocode} \def\mermin@warn{\PackageWarning{mermin-equations}} \def\mermin@warn@noline{\PackageWarningNoLine{mermin-equations}} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@firstchar} % \begin{macro}{\mermin@ifeqprefix} % Two expandable tests on a key look at its characters rather than its % tokens. % |\mermin@firstchar{|\meta{text}|}| expands to the first character of % \meta{text}, as a character of category 12. % |\mermin@ifeqprefix{|\meta{key}|}{|\meta{true}|}{|\meta{false}|}| tests % whether \meta{key} begins with |eq:|. % Both detokenize first, for two reasons. % The raw key is never scanned as a delimited argument, which inside an % alignment would end the cell at an |&| in the key; and the test does not % depend on categories, which \textsf{babel} languages change: French makes % the colon active in the document body. % |\if| compares character codes only, so the category-12 characters of % the detokenized key match the letters typed here. % \begin{macrocode} % Detokenized, so that an & in a key cannot end an alignment cell and % babel's active characters still compare as characters. \def\mermin@firstchar#1{% \@xp\mermin@firstchar@\detokenize{#1}\relax\mermin@nil} % Without the \relax an empty key would make #1 \mermin@nil, and #2 % would run away looking for it. \def\mermin@firstchar@#1#2\mermin@nil{#1} % The three \relax pad keys shorter than three characters. \def\mermin@ifeqprefix#1{% \@xp\mermin@ifeqprefix@\detokenize{#1}\relax\relax\relax\mermin@nil} \def\mermin@ifeqprefix@#1#2#3#4\mermin@nil{% \ifnum\if e#1\if q#2\if :#3 1\else 0\fi\else 0\fi\else 0\fi=1 \@xp\@firstoftwo \else \@xp\@secondoftwo \fi} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@ifunprintable} % \begin{macro}{\mermin@verbatim} % A key that is printed as text, because it has no typeset phrase, must % not contain characters that typesetting would misread. % |\mermin@ifunprintable| tests for them; |\mermin@verbatim| prints a key % character by character in typewriter type, whose fonts have every % \textsc{ascii} character. % Braces are not in the list: \cs{in@} cannot find a brace character, and % a key with braces prints, only without them. % \begin{macrocode} \edef\mermin@specials{% < > | print as other glyphs in OT1 fonts \detokenize{_^$&<>|}\@percentchar\@backslashchar} \def\mermin@ifunprintable#1{% \edef\mermin@tmp{\detokenize{#1}}% \let\mermin@bad\@empty \@xp\@tfor\@xp\mermin@c\@xp:\@xp=\mermin@specials\do{% \edef\reserved@a{\noexpand\in@{\mermin@c}{\mermin@tmp}}% \reserved@a \ifin@\def\mermin@bad{x}\fi}% \ifx\mermin@bad\@empty\@xp\@secondoftwo\else\@xp\@firstoftwo\fi} \def\mermin@verbatim#1{{\normalfont\ttfamily\detokenize{#1}}} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{Records in the \texttt{.aux} file}\label{impl:aux} % % Three kinds of record travel through the \texttt{.aux} file, like % labels, so that a citation may come before its equation: % \begin{itemize} % \item the typeset phrase given to \cs{alsolabel}, as |\mermin@newphrase| % with the arguments \meta{key} and \meta{phrase}, which defines % |\mermin@ph@|\meta{key}; % \item |\mermin@equation{|\meta{key}|}|, which marks \meta{key} as an % equation by defining |\mermin@eq@|\meta{key}, so that \cs{eqcite} can % warn about anything else; % \item |\mermin@signature|, once per file, which signs the file as % written with this package and sets |\mermin@signed|. % \end{itemize} % Until a signed file has been read, \cs{eqcite} does not warn about % non-equations: a paper that has just adopted the package has an % \texttt{.aux} file full of equation labels and no marks for them. % % \begin{macro}{\mermin@record} % \begin{macro}{\mermin@writephrase} % \begin{macro}{\mermin@markeq} % Records do not depend on the page, so they are written immediately. % The argument is expanded as \cs{label} expands its key, robust commands % excepted, so that a key such as |sec\thesection:mass| is recorded as the % same key that \cs{label} writes. % \begin{macrocode} \def\mermin@record#1{% \if@filesw % Expand the key, robust commands excepted, as \label's write does % (which expands once more at shipout), but write now. \begingroup \let\protect\@unexpandable@protect \immediate\write\@auxout{#1}% \endgroup \fi} \def\mermin@writephrase#1#2{% \mermin@record{\string\mermin@newphrase{#1}{\unexpanded{#2}}}} \def\mermin@markeq#1{\mermin@record{\string\mermin@equation{#1}}} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@auxheader} % \begin{macro}{\mermin@equation} % \begin{macro}{\mermin@signature} % At the beginning of the document the package writes, to each % \texttt{.aux} file, |\providecommand|s for the three records, so that a % document that stops loading the package still reads its old files, and % then the signature. % Files of chapters read with \cs{include} get the same lines: under % \cs{includeonly} their old files are read without being rewritten. % \begin{macrocode} \def\mermin@auxheader#1{% \immediate\write#1{% \string\providecommand\string\mermin@newphrase[2]{}% \string\providecommand\string\mermin@equation[1]{}% \string\providecommand\string\mermin@signature{}}% % The signature gets a line of its own: xr looks only at the first % token of each line. \immediate\write#1{\string\mermin@signature}} \AtBeginDocument{\if@filesw\mermin@auxheader\@auxout\fi} % Under \includeonly, the old .aux files of excluded chapters are read % but not rewritten, so each needs its own \providecommand lines. \AddToHook{include/before}{\if@filesw\mermin@auxheader\@partaux\fi} \def\mermin@signature{\global\let\mermin@signed\@empty} \def\mermin@equation#1{\@xp\gdef\csname mermin@eq@#1\endcsname{}} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@newphrase} % \begin{macro}{\mermin@checkphrases} % When \LaTeX\ rereads the \texttt{.aux} file at the end of the document % to look for changed labels, a changed phrase also asks for another run. % So does a removed one: the keys that had phrases when the run began are % listed in |\mermin@phkeys|, and after the reread any of them that was % not seen again sets the same flag. % Phrases are compared by their characters only. % \begin{macrocode} \let\mermin@phkeys\@empty \def\mermin@newphrase#1#2{% % The end-of-document reread is recognized by \@setckpt, which the % kernel (and REVTeX) makes \@gobbletwo only then. \@newl@bel is the % obvious test, but acronym changes it during the reread. \ifx\@setckpt\@gobbletwo \global\@namedef{mermin@seen@#1}{}% % Detokenized: unicode-math changes the category of letters such as % a literal Gamma after the .aux file is first read, and comparing % tokens would ask for a rerun forever. \edef\reserved@a{\detokenize{#2}}% \edef\reserved@b{% \detokenize\@xp\@xp\@xp{\csname mermin@ph@#1\endcsname}}% \ifx\reserved@a\reserved@b\else\@tempswatrue\fi \else \@xp\gdef\csname mermin@ph@#1\endcsname{#2}% \g@addto@macro\mermin@phkeys{\do{#1}}% \fi} \def\mermin@checkphrases{% % Runs inside \enddocument's group, so \do is redefined only there. \def\do##1{\@ifundefined{mermin@seen@##1}{\@tempswatrue}{}}% \mermin@phkeys} % afteraux runs after the reread and before the kernel's rerun warning. \AddToHook{enddocument/afteraux}{\if@filesw\mermin@checkphrases\fi} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{The command \cs{alsolabel}}\label{impl:aka} % % \begin{macro}{\alsolabel} % Where \LaTeX\ disables \cs{label}, as it does in the text written to a % table of contents or a running head, \cs{alsolabel} must disappear with % it, together with its arguments. % \cs{alsolabel} is therefore expandable: it looks at what \cs{label} % means and expands either to a gobbler or to the real command, % |\mermin@alsolabel|, which is robust. % Releases before 2025-06-01 disable \cs{label} as |\@gobble| or % |\relax|, as \textsf{hyperref}, \textsf{memoir}, and REVTeX do on any % release; later releases as |\@gobble@om|, or |\@gobble@with@sphack@om| % where the text is typeset, which \cs{alsolabel} then uses itself; and % the \textsf{caption} package as |\caption@gobble|. % % \cs{alsolabel} also disappears in text that \textsf{latexdiff} marks as % deleted. % \textsf{latexdiff} keeps a deleted display, as |displaymath| between % |\DIFdelbegin| and |\DIFdelend|, and comments out the \cs{label}s in % it, but its list of label commands is fixed and cannot be extended; a % deleted \cs{alsolabel} would define its key a second time, possibly with % the wrong number. % The package therefore sets |\ifmermin@deleted| between the two markers. % \textsf{latexdiff} defines them in the preamble, after % |\usepackage{mermin-equations}|, so they are wrapped only at % |begindocument/end|. % \begin{macrocode} \newif\ifmermin@deleted \AddToHook{begindocument/end}{% % latexdiff defines its markers in the preamble, after % \usepackage{mermin-equations}. They are made \protected so that, % in a moving argument such as a heading, they are written as % themselves and still set the flag when the heading is typeset % again. \ifdefined\DIFdelbegin \let\mermin@DIFdelbegin\DIFdelbegin \let\mermin@DIFdelend\DIFdelend \protected\def\DIFdelbegin{% \global\mermin@deletedtrue\mermin@DIFdelbegin}% \protected\def\DIFdelend{% \mermin@DIFdelend\global\mermin@deletedfalse}% \fi} \def\alsolabel{% \ifmermin@deleted \mermin@aka@use\mermin@gobble@aka\fi % \@gobble and \relax: kernels before 2025-06, and hyperref, % memoir, and REVTeX on any kernel. \ifx\label\@gobble \mermin@aka@use\mermin@gobble@aka\fi \ifx\label\relax \mermin@aka@use\mermin@gobble@aka\fi % \@gobble@om and \@gobble@with@sphack@om: kernels from 2025-06. \ifx\label\@gobble@om \mermin@aka@use\mermin@gobble@aka\fi \ifx\label\@gobble@with@sphack@om \mermin@aka@use\@gobble@with@sphack@om\fi % caption disables \label this way, in its single-line check and in % subcaption's list of figures. \ifx\label\caption@gobble \mermin@aka@use\mermin@gobble@aka\fi \mermin@alsolabel} % \mermin@aka@use ends the test that matched, drops the remaining tests % up to \mermin@alsolabel, and leaves #1 in its place. \def\mermin@aka@use#1#2\mermin@alsolabel{\fi#1} \NewExpandableDocumentCommand\mermin@gobble@aka{d<> o m}{} % \end{macrocode} % \end{macro} % % \begin{macro}{\mermin@alsolabel} % The real command records the optional phrase and then calls whatever % \cs{label} means at that point, with the flag |\ifmermin@also| raised. % In a display \cs{label} is |\label@in@display|, which % part~\ref{impl:queue} wraps to read the flag; elsewhere \cs{label} acts as % usual, and \cs{alsolabel} gives a section or a figure a second name. % The measuring passes of \textsf{amsmath} gobble or defer \cs{label}, and % \cs{alsolabel} inherits the same treatment. % A \textsf{beamer} overlay, |<|\meta{overlay}|>|, goes to \textsf{beamer}'s % \cs{label} outside displays, and is dropped inside them. % |\mermin@doclabel| is the document's \cs{label}, saved at % |begindocument/end| after \textsf{hyperref} and \textsf{beamer} have set % it. % \begin{macrocode} \newif\ifmermin@also \AddToHook{begindocument/end}{% after hyperref and beamer set \label \let\mermin@doclabel\label} \NewDocumentCommand\mermin@alsolabel{d<> o m}{% % \label ends with \@esphack, but inside the group below it cannot % remove the space after the command in running text; the command % therefore has its own \@bsphack and \@esphack. \@bsphack \IfValueT{#2}{\mermin@writephrase{#3}{#2}}% \begingroup \mermin@alsotrue % cleveref's multline trial pass calls this hook directly instead % of \label@in@display; see \mermin@cref@entry. \ifdefined\mermin@cref@old \let\cref@old@label@in@display\mermin@also@stored \fi \IfValueTF{#1}% % Only beamer's \label takes an overlay: the document's \label, % or \mermin@marklabel wrapping it. amsmath's display \label % does not. {\ifx\label\mermin@doclabel \label<#1>{#3}% \else\ifx\label\mermin@marklabel \label<#1>{#3}% \else \label{#3}% \fi\fi}% {\label{#3}}% \endgroup \@esphack} % \end{macrocode} % \end{macro} % % \subsection{Which keys are equations}\label{impl:mark} % % \begin{macro}{\mermin@markargs} % \begin{macro}{\mermin@keyof} % A key is marked as an equation where a display registers it, and not % where labels are written: |\ltx@label|, which writes them, is reached % from outside displays too. % A key arrives as |{|\meta{key}|}|, as |[|\meta{type}|]{|\meta{key}|}| % with \textsf{cleveref}'s optional argument, or as \textsf{amsmath} stores % it without \textsf{cleveref}, the bare \meta{key}. % |\mermin@keyof| sets |\mermin@rawkey| to the key in any of these forms. % \begin{macrocode} \def\mermin@markargs#1{% % The \iffalse braces raise TeX's alignment brace count without % opening a group, so that an & in a bare key, scanned as a delimited % argument inside align, does not end the cell. \iffalse{\fi \mermin@keyof#1\mermin@nil \@xp\mermin@markeq\@xp{\mermin@rawkey}% \iffalse}\fi} % [type] is cleveref's optional argument of \label. \def\mermin@keyof{\@ifnextchar[\mermin@keyof@opt\mermin@keyof@plain} \def\mermin@keyof@plain#1\mermin@nil{\def\mermin@rawkey{#1}} \def\mermin@keyof@opt[#1]#2\mermin@nil{\def\mermin@rawkey{#2}} % \end{macrocode} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@wraplabel} % \begin{macro}{\mermin@marklabel} % Some equations are labeled by an ordinary \cs{label}, not by % |\label@in@display|: the label of a \textsf{subequations} group, numbered % like ``(12)'', and the labels in \textsf{breqn}'s displays, in the % \textsf{cases} package's |numcases|, in \textsf{IEEEtrantools}' % |IEEEeqnarray|, in \textsf{subeqnarray}, and in the kernel's % \textsf{eqnarray}. % Inside these environments \cs{label} is |\mermin@marklabel|, which % marks its key and calls the \cs{label} it replaced. % The \textsf{amsmath} displays within them install their own \cs{label}, % and an environment nested in another, such as |dmath| in |dgroup|, % finds \cs{label} already wrapped and leaves it. % \begin{macrocode} % For environments that label equations with the ordinary \label. \def\mermin@wraplabel{% \ifx\label\mermin@marklabel\else \let\mermin@marklabel@orig\label \let\label\mermin@marklabel \fi} % beamer's \label takes an overlay, <...>, before the optional % argument. \def\mermin@marklabel{% \@ifnextchar<\mermin@marklabel@ov {\@ifnextchar[\mermin@marklabel@opt\mermin@marklabel@plain}} \def\mermin@marklabel@plain#1{% \mermin@markeq{#1}\mermin@marklabel@orig{#1}} \def\mermin@marklabel@opt[#1]#2{% \mermin@markeq{#2}\mermin@marklabel@orig[#1]{#2}} \def\mermin@marklabel@ov<#1>#2{% \mermin@markeq{#2}\mermin@marklabel@orig<#1>{#2}} \def\mermin@markenv#1{\AddToHook{env/#1/begin}{\mermin@wraplabel}} \@for\mermin@env:=% subequations,% amsmath dmath,dseries,dgroup,% breqn numcases,subnumcases,% cases IEEEeqnarray,IEEEeqnarray*,% IEEEtrantools eqnarray,% LaTeX kernel subeqnarray% subeqnarray \do{\@xp\mermin@markenv\@xp{\mermin@env}} % subeqnarray labels each row with \slabel, which writes \newlabel % itself. \AddToHook{env/subeqnarray/begin}{% \let\mermin@slabel@orig\slabel \def\slabel#1{\mermin@markeq{#1}\mermin@slabel@orig{#1}}} % \end{macrocode} % \end{macro} % \end{macro} % % \subsection{Extra keys on a display line}\label{impl:queue} % % \textsf{amsmath} does not write a display label when it meets \cs{label}. % It stores the key in |\df@label| and writes it with % |\ltx@label{|\meta{contents of \texttt{\char`\\df@label}}|}| once the % line's tag, and so |\@currentlabel| and the \textsf{hyperref} anchor, are % known. % The package keeps the extra keys of a line in a queue and writes them % immediately after that primary label, so they receive the same number and % anchor. % % Three complications shape the code. % First, \textsf{cleveref} stores keys in a different form, wrapping the % key in braces or preceding it with an optional argument, so every queued % key is stored in exactly the form |\label@in@display| would have stored % it. % Second, \textsf{amsmath} and \textsf{empheq} typeset some displays twice, % once to measure them, and may discard a primary label without writing % it. % The queue is therefore tagged with the primary label it belongs to and % written only when that label is, and a key is never queued twice. % Third, \cs{alsolabel} may come before \cs{label} or without it. % It then occupies |\df@label| itself, \emph{promoted}, and a later % \cs{label} reclaims the slot and moves the earlier key into the queue. % % \begin{macro}{\mermin@queue} % \begin{macro}{\mermin@tag} % \begin{macro}{\mermin@promoted} % The queue holds extra keys as |\do{|\meta{stored form}|}|. % The tag is the |\df@label| the queue belongs to. % |\mermin@promoted| is nonempty while \cs{alsolabel} occupies % |\df@label|. % All three are global, like |\df@label| itself, because the cells of an % alignment are groups. % \begin{macrocode} \gdef\mermin@queue{} % the line's extra keys, as \do{} \gdef\mermin@tag{} % the \df@label the queue belongs to \gdef\mermin@promoted{} % an \aka key occupying \df@label, if any % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@store} % \begin{macro}{\mermin@markstore} % \begin{macro}{\mermin@canonical} % |\mermin@store| calls the |\label@in@display| that was in force before % the package wrapped it, which stores the key in |\df@label|; |\mermin@markstore| also marks the key as an % equation. % Their argument is the complete argument list, braces included. % |\mermin@canonical{|\meta{key}|}| sets |\mermin@form| to the form in which % that |\label@in@display| would store \meta{key}, by letting it store the % key into an emptied |\df@label| and restoring the old contents. % \begin{macrocode} \def\mermin@store#1{% \begingroup % Undo, locally, the redirection of cleveref's inner hook. \ifdefined\mermin@cref@old \let\cref@old@label@in@display\mermin@cref@old \fi \mermin@orig@label@in@display#1% \endgroup} \def\mermin@markstore#1{\mermin@markargs{#1}\mermin@store{#1}} \def\mermin@canonical#1{% % Let the original store #1 into an empty \df@label, read the stored % form back, and restore \df@label: cleveref and amsmath store keys % differently, and queued keys must match the form exactly. \global\let\mermin@saved\df@label \global\let\df@label\@empty \mermin@store{{#1}}% \global\let\mermin@form\df@label \global\let\df@label\mermin@saved} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % % \begin{macro}{\mermin@enqueue} % This queues |\mermin@form| for the current |\df@label|. % A queue tagged with a different label is stale and is discarded first. % A form already in the queue is skipped: a display typeset twice runs its % \cs{alsolabel}s twice, and \cs{text} typesets its argument four times. % With the \textsf{mathtools} option |showonlyrefs| a line is numbered only % if its primary label was cited, which \textsf{mathtools} records as % |\MT_r_|\meta{label}; a citation of a queued key counts for the line too. % \begin{macrocode} \def\mermin@enqueue{% \ifx\mermin@tag\df@label\else \gdef\mermin@queue{}% \global\let\mermin@tag\df@label \fi \iffalse{\fi % alignment guard, as in \mermin@markargs % mathtools' showonlyrefs numbers a line whose label is cited, which % it records as \MT_r_ % \end{macrocode} % \end{macro} % \end{macro} % % \Finale \endinput