diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/autonum')
-rw-r--r-- | Master/texmf-dist/source/latex/autonum/autonum.dtx | 211 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/autonum/autonum.ins | 83 |
2 files changed, 223 insertions, 71 deletions
diff --git a/Master/texmf-dist/source/latex/autonum/autonum.dtx b/Master/texmf-dist/source/latex/autonum/autonum.dtx index 4e9bb08f028..05b7b4658a0 100644 --- a/Master/texmf-dist/source/latex/autonum/autonum.dtx +++ b/Master/texmf-dist/source/latex/autonum/autonum.dtx @@ -86,7 +86,7 @@ and the derived files autonum.ins, %</internal> %<*package> \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{autonum}[2012/06/21 v0.2 autonum LaTeX package] +\ProvidesPackage{autonum}[2012/08/16 v0.3 autonum LaTeX package] \PassOptionsToPackage{hypertexnames=false}{hyperref} \RequirePackage{etoolbox} \RequirePackage{amsmath} @@ -127,6 +127,7 @@ and the derived files autonum.ins, % %\changes{v0.1}{2012/05/26}{First public release} %\changes{v0.2}{2012/06/21}{Support multi-line environments. Redefine \cmd{\[} to use the new \cmd{\equation}.} +%\changes{v0.3}{2012/08/16}{Support alignat and flalign environments. Fix handling of special characters in label names. Fix handling of multiple label names in \cmd{\cref} command.} % % \section{Introduction} % With \LaTeX, the user has to decide manually to not number an equation by adding a star in the math environment. Authors who do not want to think about the numbering during the writing (and maybe they should not), often use the environments without stars. As default, these users get all equations numbered, although there are \href{http://tex.stackexchange.com/q/29267/7323}{different opinions} about what should be numbered. @@ -141,7 +142,9 @@ and the derived files autonum.ins, % \cmd{\usepackage\{autonum\}} % \vspace{0.5em} % -% The recommended style is to add a label to each logical equation. Then, simply use the references as needed. Never use the starred form. You can use the (redefined) \texttt{equation} or \cmd{\[}-\cmd{\]}-environment in most cases, if you add the appropriate \cmd{\begin\{split\}}-\cmd{\end\{split\}} pairs when needed. Sometimes, an \texttt{align}, \texttt{multline}, or \texttt{gather} environment is needed.^^A, rarely use the \texttt{aligned} or \texttt{gathered} environments. +% The recommended style is to add a label to each logical equation. Then, simply use the references as needed. Never use the starred forms when defining an equation as they do not make sense with autonum and are deactivated. You can use the (redefined) \texttt{equation} or \cmd{\[}-\cmd{\]}-environment in most cases, if you add the appropriate \cmd{\begin\{split\}}-\cmd{\end\{split\}} pairs when needed. Sometimes, an \texttt{align}, \texttt{multline}, \texttt{gather}, \texttt{flalign} or \texttt{alignat} environment is needed.^^A, rarely use the \texttt{aligned} or \texttt{gathered} environments. +% +% Please keep in mind, that using autonum might not always be a good thing. If you hand-in a paper for review with many equations on a page, you might avoid using autonum or if you do, you probably should reference most of your equations or activate line numbers. % %\begin{macro}{equation} % The following examples show the results of the equation environment after loading the package. Now let's reference the third equation: \ref{alreadyReferenced}. @@ -182,7 +185,7 @@ and the derived files autonum.ins, %\end{macro} % % \begin{macro}{\[ et al.} -% Instead of equation you may also use one of the following environments: \texttt{align}, \texttt{gather}, \texttt{multline}, \texttt{equation}. ^^A, \texttt{aligned}, \texttt{gathered}. ^^A The \texttt{multlined} environment is patched, if it is available. +% Instead of equation you may also use one of the following environments: \texttt{align}, \texttt{gather}, \texttt{multline}, \texttt{flalign}. ^^A, \texttt{aligned}, \texttt{gathered}. ^^A The \texttt{multlined} environment is patched, if it is available. % As the commands \cmd{\[} and \cmd{\]} are useless when using autonum, they are redefined to be an alias of \texttt{begin\{equation\}} and \texttt{end\{equation\}}, respectively. ^^A, instead either the \texttt{equation} or the \texttt{align} environments are used, depending on the number of lines in the equation. % Without adding labels or referencing added labels, the new \cmd{\[}-\cmd{\]}-environment behaves like the old one. ^^A if the equation is only one line. The new definition inherits all the multi-line and alignment capabilities from align and thus is recommended as default while writing. If the environment's content has only one line, the equation environment is used, which has a \href{http://tex.stackexchange.com/questions/321/align-vs-equation}{smaller vertical space} for short lines above the environment compared to align. % \end{macro} @@ -201,10 +204,28 @@ and the derived files autonum.ins, % % \subsection{Hyperref} % The hyperref package must be loaded with the option \texttt{hypertexnames=false} to work when autonum is used.\\ -% Problem description: Generally, the autonum package is careful not to break other packages, but with autonum there are non-starred mathematical environment which do not increase the equation counter. This leads to the following warning in hyperref when more than one equation is used: "destination with the same identifier (name{equation.0.1}) has been already used, duplicate ignored". Additionally, the link anchors do not work correctly (with a reference followed by a labeled equation, there is a warning in tracing mode, too. Hyperref seems to increase \LaTeX's equation's counter (called \texttt{equation}) only if a equation is references. This counter may not be modified to avoid problems with Hyperref, as this would change the displayed equation number (and it does not work anyway). This problem is independent of cleveref. The problem might be solvable by modifying \cmd{\begin\{equation\}} or \cmd{\end\{equation\}}. Using \texttt{gather} instead of \texttt{equation} removes the warning, but hyperlinks still do not work. +% Problem description: Generally, the autonum package is careful not to break other packages, but with autonum there are non-starred mathematical environment which do not increase the equation counter. This leads to the following warning in hyperref when more than one equation is used: "destination with the same identifier (name{equation.0.1}) has been already used, duplicate ignored". Additionally, the link anchors do not work correctly (with a reference followed by a labeled equation, there is a warning in tracing mode, too. Hyperref seems to increase \LaTeX's equation's counter (called \texttt{equation}) only if a equation is referenced. This counter may not be modified to avoid problems with Hyperref, as this would change the displayed equation number (and it does not work anyway). This problem is independent of cleveref. The problem might be solvable by modifying \cmd{\begin\{equation\}} or \cmd{\end\{equation\}}. Using \texttt{gather} instead of \texttt{equation} removes the warning, but hyperlinks still do not work. % % \subsection{Reference commands} -% As default the \cmd{\ref} and cleveref's \cmd{\cref} commands are supported. New reference commands can be supported by executing \cmd{\let}\cmd{\ref}\cmd{\NewReferenceCommand}. If the original \cmd{\ref} command should not be overwritten, you can instead use \cmd{\autonum@generatePatchedReference}\{\cmd{\NewReferenceCommand}\}. Mind the \cmd{\makeatletter} and \cmd{\makeatother} command before and after the aforementioned command, respectively. +% As default the \cmd{\ref} and cleveref's \cmd{\cref} commands are supported. Support for new reference commands can be added by executing\\ +% \cmd{\let}\cmd{\ref}\cmd{\NewReferenceCommand}.\\ +% If the original \cmd{\ref} command should not be overwritten, you have the following choices. Please mind that these interfaces might change in the future. Please also mind the \cmd{\makeatletter} and \cmd{\makeatother} command before and after the commands, respectively. +% +%\begin{macro}{\autonum@generatePatchedReference} +% For normal reference commands expecting a single label name as an argument, you can use \cmd{\autonum@generatePatchedReference}\{\cmd{\NewReferenceCommand}\}. +%\end{macro} +% +%\begin{macro}{\autonum@generatePatchedReferenceCSL} +% For reference commands expecting a comma separated list of label names as an argument, you can use\\ +% \cmd{\autonum@generatePatchedReferenceCSL}\{\cmd{\NewReferenceCommand}\}. +%\end{macro} +% +%\begin{macro}{\autonum@generatePatchedReferenceGeneral} +% For reference commands expecting a general data structure containing label names as an argument, you can use\\ +% \cmd{\autonum@generatePatchedReferenceGeneral}\{\cmd{\NewReferenceCommand}\}\\ +% \{\cmd{\SplitAndLoopMacro}\}.\\ +% The macro \cmd{\SplitAndLoopMacro} acts as a function expecting the to-be-called function as the first argument and the data structure as the second argument. It must call the function given in the first argument for each label name given in the data structure of the second argument. An example is the \cmd{\forcsvlist} macro from the etoolbox package, which is used to implement \cmd{\autonum@generatePatchedReferenceCSL}. +%\end{macro} % % \section{Further Ideas} % \begin{itemize} @@ -212,10 +233,37 @@ and the derived files autonum.ins, % \item A warning could be printed, if another compile is necessary. % \item A "*" could be used instead of a "+". % \item If a reference is used before the label is defined, the reference information is saved in a variable and can be used later in the current run when processing the label. It does not have to be saved to the aux file. If a reference is used after defining the label, the reference information is saved in the aux file and can be used in the next run when processing the label. The information does not have to be saved into a variable, as a label must only be defined once and the definition has already happened. Unfortunately, this would make it necessary to distinguish between definitions in the current and in the last run, as otherwise this leads either to oscillation or to defining everything in the end (depending if csdefaux or csdefall is used in the not-defined case), which is probably not worth the effort. -% \item It would be good, if umlauts were possible in labels -- the \texttt{stringstrings} package might be handy -% The command \cmd{\(} could be an alias for \cmd{begin\{split\}} and \cmd{\)} could be an alias for \cmd{end\{split\}} +% \item The command \cmd{\(} could be an alias for \cmd{begin\{split\}} and \cmd{\)} could be an alias for \cmd{end\{split\}} +% \item This \href{http://tex.stackexchange.com/a/5652}{trick} might be handy +% \item The \cmd{\crefrange} might be supported. As this would require a lot of work it will only be done if multiple people show interest and there are really convincing real-world examples where using \cmd{\crefrange} is superior to using \cmd{\cref}. Patches are, of course, welcome, too. % \end{itemize} % +% \section{Contributions} +% \begin{itemize} +% \item David Carlisle +% \begin{itemize} +% \item explained that amsmath environments \href{http://tex.stackexchange.com/a/59088/7323}{are executed twice} what lead to the support of the amsmath environments +% \end{itemize} +% \item Fg Nu +% \begin{itemize} +% \item highlighted, that special characters in label names must be supported what lead to the support of special characters +% \end{itemize} +% \item Joseph Wright +% \begin{itemize} +% \item created a \href{http://tex.stackexchange.com/a/64271/7323}{correctly working} \cmd{\csxdefaux} what lead to the support of special characters +% \end{itemize} +% \item Jonas Nyrup +% \begin{itemize} +% \item reported a bug occuring when using \cmd{\cref} with comma separated arguments what lead to its fix +% \item started an interesting discussion if cleveref's \cmd{\crefrange} command should be supported in autonum or not +% \end{itemize} +% \item Toby Cubitt +% \begin{itemize} +% \item highlighted, that there are some users who might find valid use of cleveref's \cmd{\crefrange} command +% \end{itemize} +% \end{itemize} +% +% % \section{Implementation} % The basic idea is to write into the aux file and save a variable whenever a label is referenced, so that the information is available in the current and in the next run. The label information is passed from the label command to the newline command. The newline command uses the label and the reference information to possibly add a \cmd{\notag} command, deciding if it is referenced or not. % @@ -230,7 +278,7 @@ and the derived files autonum.ins, % The expandafter commands are used to first expand the \cmd{\csname}-\cmd{\endcsname}. Then there is a command definition left, where the command and its replacement (which can also be a command) are protected by \cmd{\string} to create the command in the next run (when the aux file is read) and not in the current run (when the aux file is written). % \begin{macrocode} \protected@write\@mainaux{}{% - \expandafter\string\expandafter\xdef\expandafter\string\csname #1\endcsname{#2}% + \csxdef{\detokenize{#1}}{#2}% }% } % \end{macrocode} @@ -261,13 +309,17 @@ and the derived files autonum.ins, % \begin{macrocode} \AtBeginDocument{% % \end{macrocode} - % Most of amsmath's environments are redefined. The environments alignat and alignedat are not redefined, as their syntax differs and they do not seem so useful to be worth the effort. The environment flalign is also not redefined, as it's behavior is not described in amsmath's documentation. The environments aligned and gathered are not redefined, as it is unclear, how the numbering should work. + % Most of amsmath's environments are redefined. The environments aligned and gathered are not redefined, as it is unclear, how the numbering should work. % \begin{macrocode} %^^A\forcsvlist{\autonum@patchBlockEnvironment}{gathered,aligned}% %^^A \ifdef{\multlined}{% %^^A \autonum@patchBlockEnvironment{multlined}% %^^A }{}% - \forcsvlist{\autonum@patchFullEnvironment}{equation,gather,multline,align}% +% \end{macrocode} + % If align is redefined before flalign or alignat, autonum.dtx does not build anymore. The error reason is unknown. As the error disappears when align is redefined after both, there is no motivation in finding the underlying problem. +% \begin{macrocode} + \forcsvlist{\autonum@patchParametrizedFullEnvironment}{alignat}% + \forcsvlist{\autonum@patchFullEnvironment}{equation,gather,multline,flalign,align}% % \end{macrocode} % % Patch the environment delimited by \cmd{\[} and \cmd{\]}. @@ -282,7 +334,7 @@ and the derived files autonum.ins, % \begin{macrocode} \autonum@generatePatchedReference{ref}% \ifdef{\cref}{% - \autonum@generatePatchedReference{cref}% + \autonum@generatePatchedReferenceCSL{cref}% }{}% % \end{macrocode} % \begin{macrocode} @@ -294,16 +346,20 @@ and the derived files autonum.ins, % \begin{macrocode} % \def\autonum@patchEnvironment#1{ \def\autonum@patchFullEnvironment#1{% - \autonum@saveEnvironmentSubcommands{#1}{center}% - \autonum@patchEnvironmentHelper{#1}% + \autonum@saveEnvironmentSubcommands{#1}{center}{}% + \autonum@patchEnvironmentHelper{#1}{0}% +} +\def\autonum@patchParametrizedFullEnvironment#1{% + \autonum@saveEnvironmentSubcommands{#1}{center}{1}% + \autonum@patchEnvironmentHelper{#1}{1}% } \def\autonum@patchBlockEnvironment#1{% - \autonum@saveEnvironmentSubcommands{#1}{equation*}% - \autonum@patchEnvironmentHelper{#1}% + \autonum@saveEnvironmentSubcommands{#1}{equation*}{}% + \autonum@patchEnvironmentHelper{#1}{0}% } -\def\autonum@patchEnvironmentHelper#1{% - \autonum@renameEnvironment{#1}% - \autonum@changeEnvironment{#1}% +\def\autonum@patchEnvironmentHelper#1#2{% + \autonum@renameEnvironment{#1}{#2}% + \autonum@changeEnvironment{#1}{#2}% \autonum@generatePatchedLabel{#1}% \autonum@generatePatchedNewline{#1}% } @@ -311,12 +367,12 @@ and the derived files autonum.ins, %\end{macro} %\begin{macro}{\autonum@saveEnvironmentSubcommands} -% This code is to save the newline code used in a mathematic display environment so that it can be used later. This is necessary, as saving it in the instance of the environment, where it should be used, does not work. Allow for two arguments, to enable putting the alignment building blocks into an equation environment (see amsmath documentation). +% This code is to save the newline code used in a mathematic display environment so that it can be used later. This is necessary, as saving it in the instance of the environment, where it should be used, does not work. Allow for two arguments, to enable putting the alignment building blocks into an equation environment (see amsmath documentation). The third argument is needed for environments which have arguments themself. % \begin{macrocode} -\def\autonum@saveEnvironmentSubcommands#1#2{% +\def\autonum@saveEnvironmentSubcommands#1#2#3{% \begin{textblock}{1}[1,1](0,0)% - \begin{#2} - \begin{#1}% + \begin{#2}% + \begin{#1}#3% % \end{macrocode} % Using global here is necessary to get the information out of the environment. % \begin{macrocode} @@ -336,19 +392,19 @@ and the derived files autonum.ins, % \begin{macrocode} \notag% \end{#1}% - \end{#2} + \end{#2}% \end{textblock}% } % \end{macrocode} %\end{macro} %\begin{macro}{\autonum@renameEnvironment} -% Rename the old environment to be accessible with an appended + by saving the original environment using a different name. +% Rename the old environment to be accessible with an appended + by saving the original environment using a different name. The first argument contains the environment's name, the second argument contains the number of arguments the environment has. % \begin{macrocode} -\def\autonum@renameEnvironment#1{% +\def\autonum@renameEnvironment#1#2{% \csletcs{autonum@#1Old}{#1}% \csletcs{autonum@end#1Old}{end#1}% - \newenvironment{#1+}{% + \newenvironment{#1+}[#2]{% \csuse{autonum@#1Old}% }{% \csuse{autonum@end#1Old}% @@ -358,32 +414,58 @@ and the derived files autonum.ins, %\end{macro} %\begin{macro}{\autonum@changeEnvironment} -% Now change the environment. This command only supports displayed equation structures and is not suited for other environments (as e.g. figures). +% Now change the environment. This command only supports displayed equation structures and is not suited for other environments (as e.g. figures). The second argument contains the number of arguments the redefined environment has. % \begin{macrocode} -\def\autonum@changeEnvironment#1{% +\def\autonum@changeEnvironment#1#2{% % \end{macrocode} - % Although Amsmath's environment is executed twice (for measuring and for painting), the content here is executed only once. + % Although Amsmath's environment is executed twice (for measuring and for painting), the content here is executed only once. The following if is only needed to distinguish between environments without (e.g. equation) and with one parameter (e.g. alignat). % \begin{macrocode} - \renewenvironment{#1}{% + \ifnum #2=0% + \renewenvironment{#1}{% + \autonum@startChangeEnvironment{#1}{}% + }{% + \autonum@endChangeEnvironment{#1}% + } + \else + \renewenvironment{#1}[1]{% + \autonum@startChangeEnvironment{#1}{##1}% + }{% + \autonum@endChangeEnvironment{#1}% + }% + \fi% % \end{macrocode} - % Prepare the label and the newline commands and begin the displayed equation environment. + % Delete the starred versions of the environment, as they sometimes lead to strange errors a long time after using the starred version. By deleting it, the error occurs at the right place. % \begin{macrocode} - \autonum@saveSubcommands - \csuse{autonum@#1Old}% - \autonum@patchSubcommands{#1}% - }{% + \global\csundef{#1*}% + \global\csundef{end#1*}% +} % \end{macrocode} - % Possibly hide the number of the last equation in the displayed equation environment, end the latter one and restore the subcommands. +%\end{macro} + +%\begin{macro}{\autonum@startChangeEnvironment} +% Start the changed environment. % \begin{macrocode} - \autonum@possiblyHideNumber - \csuse{autonum@end#1Old}% - \autonum@restoreSubcommands - }% +\def\autonum@startChangeEnvironment#1#2{% % \end{macrocode} - % Delete the starred versions of the environment, as they sometimes lead to strange errors a long time after using the starred version. By deleting it, the error occurs at the right place. + % Prepare the label and the newline commands and begin the displayed equation environment. % \begin{macrocode} - \global\csundef{#1*}% - \global\csundef{end#1*}% + \autonum@saveSubcommands + \csuse{autonum@#1Old}#2% + \autonum@patchSubcommands{#1}% +} +% \end{macrocode} +%\end{macro} + +%\begin{macro}{\autonum@endChangeEnvironment} +% Close the changed environment. +% \begin{macrocode} +\def\autonum@endChangeEnvironment#1{% +% \end{macrocode} + % Possibly hide the number of the last equation in the displayed equation environment, end the latter one and restore the subcommands. +% \begin{macrocode} + \autonum@possiblyHideNumber + \csuse{autonum@end#1Old}% + \autonum@restoreSubcommands } % \end{macrocode} %\end{macro} @@ -484,15 +566,30 @@ and the derived files autonum.ins, %\end{macro} %\begin{macro}{\autonum@generatePatchedReference} -% This command can patch arbitrary reference commands. The patch logic can be different to patching the label command, as the references have to be patched only once, so optimizing for speed is counter-productive. +% This command can patch reference commands with a normal input argument. % \begin{macrocode} \def\autonum@generatePatchedReference#1{% - \csletcs{autonum@reference#1Old}{#1}% - \csdef{#1}##1{% + \autonum@generatePatchedReferenceGeneral{#1}{autonum@use}% +} +% \end{macrocode} +%\end{macro} + +%\begin{macro}{\autonum@generatePatchedReferenceCSL} +% This command can patch reference commands which expect a comma separated list as input argument. +% \begin{macrocode} +\def\autonum@generatePatchedReferenceCSL#1{% + \autonum@generatePatchedReferenceGeneral{#1}{forcsvlist}% +} % \end{macrocode} - % Mark label as referenced. The reference information is stored into a variable (for the current run) and into the aux file (for the next run), so it does not matter if the reference is used before or after the definition of the label. Saving into a variable saves one compilation run, although still up to three are needed to get everything right. +%\end{macro} + +%\begin{macro}{\autonum@generatePatchedReferenceGeneral} +% This command can patch arbitrary reference commands. The patch logic can be different to patching the label command, as the references have to be patched only once, so optimizing for speed is counter-productive. % \begin{macrocode} - \csxdefall{autonum@##1Referenced}{}% +\def\autonum@generatePatchedReferenceGeneral#1#2{% + \csletcs{autonum@reference#1Old}{#1}% + \csdef{#1}##1{% + \csuse{#2}{\autonum@markLabelAsReferenced}{##1} % \end{macrocode} % Call the old reference command. % \begin{macrocode} @@ -502,6 +599,24 @@ and the derived files autonum.ins, % \end{macrocode} %\end{macro} +%\begin{macro}{\autonum@markLabelAsReferenced} +% This is a simple helper macro to mark a label as referenced. The reference information is stored into a variable (for the current run) and into the aux file (for the next run), so it does not matter if the reference is used before or after the definition of the label. Saving into a variable saves one compilation run, although still up to three are needed to get everything right. +% \begin{macrocode} +\def\autonum@markLabelAsReferenced#1{% + \csxdefall{autonum@#1Referenced}{}% +} +% \end{macrocode} +%\end{macro} + +%\begin{macro}{\autonum@use} +% This is a simple helper macro which can be used like a function handle similar to csuse but expecting a macro instead of a macro's name. +% \begin{macrocode} +\def\autonum@use#1#2{% + #1{#2}% +} +% \end{macrocode} +%\end{macro} + %\begin{macro}{\autonum@patchShortcutEnvironment} % Use a counter to numerate all \cmd{\[}-\cmd{\]}-environments linearly. % \begin{macrocode} diff --git a/Master/texmf-dist/source/latex/autonum/autonum.ins b/Master/texmf-dist/source/latex/autonum/autonum.ins index fbac37d109c..56a3a3ddd42 100644 --- a/Master/texmf-dist/source/latex/autonum/autonum.ins +++ b/Master/texmf-dist/source/latex/autonum/autonum.ins @@ -52,7 +52,7 @@ and the derived files autonum.ins, \def\csxdefaux#1#2{% \protected@write\@mainaux{}{% -\expandafter\string\expandafter\xdef\expandafter\string\csname #1\endcsname{#2}% +\csxdef{\detokenize{#1}}{#2}% }% } @@ -68,35 +68,40 @@ and the derived files autonum.ins, } \AtBeginDocument{% -\forcsvlist{\autonum@patchFullEnvironment}{equation,gather,multline,align}% +\forcsvlist{\autonum@patchParametrizedFullEnvironment}{alignat}% +\forcsvlist{\autonum@patchFullEnvironment}{equation,gather,multline,flalign,align}% \def\[#1\]{% \begin{equation}#1\end{equation}% }% \autonum@generatePatchedReference{ref}% \ifdef{\cref}{% -\autonum@generatePatchedReference{cref}% +\autonum@generatePatchedReferenceCSL{cref}% }{}% } \def\autonum@patchFullEnvironment#1{% -\autonum@saveEnvironmentSubcommands{#1}{center}% -\autonum@patchEnvironmentHelper{#1}% +\autonum@saveEnvironmentSubcommands{#1}{center}{}% +\autonum@patchEnvironmentHelper{#1}{0}% +} +\def\autonum@patchParametrizedFullEnvironment#1{% +\autonum@saveEnvironmentSubcommands{#1}{center}{1}% +\autonum@patchEnvironmentHelper{#1}{1}% } \def\autonum@patchBlockEnvironment#1{% -\autonum@saveEnvironmentSubcommands{#1}{equation*}% -\autonum@patchEnvironmentHelper{#1}% +\autonum@saveEnvironmentSubcommands{#1}{equation*}{}% +\autonum@patchEnvironmentHelper{#1}{0}% } -\def\autonum@patchEnvironmentHelper#1{% -\autonum@renameEnvironment{#1}% -\autonum@changeEnvironment{#1}% +\def\autonum@patchEnvironmentHelper#1#2{% +\autonum@renameEnvironment{#1}{#2}% +\autonum@changeEnvironment{#1}{#2}% \autonum@generatePatchedLabel{#1}% \autonum@generatePatchedNewline{#1}% } -\def\autonum@saveEnvironmentSubcommands#1#2{% +\def\autonum@saveEnvironmentSubcommands#1#2#3{% \begin{textblock}{1}[1,1](0,0)% -\begin{#2} -\begin{#1}% +\begin{#2}% +\begin{#1}#3% \global\cslet{autonum@newline#1}\\% \notag% \ifboolexpr{not test {\ifstrequal{#1}{multline}} or test {\ifcsundef{autonum@label#1}}}{% @@ -104,32 +109,48 @@ and the derived files autonum.ins, }% \notag% \end{#1}% -\end{#2} +\end{#2}% \end{textblock}% } -\def\autonum@renameEnvironment#1{% +\def\autonum@renameEnvironment#1#2{% \csletcs{autonum@#1Old}{#1}% \csletcs{autonum@end#1Old}{end#1}% -\newenvironment{#1+}{% +\newenvironment{#1+}[#2]{% \csuse{autonum@#1Old}% }{% \csuse{autonum@end#1Old}% }% } -\def\autonum@changeEnvironment#1{% +\def\autonum@changeEnvironment#1#2{% +\ifnum #2=0% \renewenvironment{#1}{% +\autonum@startChangeEnvironment{#1}{}% +}{% +\autonum@endChangeEnvironment{#1}% +} +\else +\renewenvironment{#1}[1]{% +\autonum@startChangeEnvironment{#1}{##1}% +}{% +\autonum@endChangeEnvironment{#1}% +}% +\fi% +\global\csundef{#1*}% +\global\csundef{end#1*}% +} + +\def\autonum@startChangeEnvironment#1#2{% \autonum@saveSubcommands -\csuse{autonum@#1Old}% +\csuse{autonum@#1Old}#2% \autonum@patchSubcommands{#1}% -}{% +} + +\def\autonum@endChangeEnvironment#1{% \autonum@possiblyHideNumber \csuse{autonum@end#1Old}% \autonum@restoreSubcommands -}% -\global\csundef{#1*}% -\global\csundef{end#1*}% } \def\autonum@saveSubcommands{% @@ -183,13 +204,29 @@ and the derived files autonum.ins, } \def\autonum@generatePatchedReference#1{% +\autonum@generatePatchedReferenceGeneral{#1}{autonum@use}% +} + +\def\autonum@generatePatchedReferenceCSL#1{% +\autonum@generatePatchedReferenceGeneral{#1}{forcsvlist}% +} + +\def\autonum@generatePatchedReferenceGeneral#1#2{% \csletcs{autonum@reference#1Old}{#1}% \csdef{#1}##1{% -\csxdefall{autonum@##1Referenced}{}% +\csuse{#2}{\autonum@markLabelAsReferenced}{##1} \csuse{autonum@reference#1Old}{##1}% }% } +\def\autonum@markLabelAsReferenced#1{% +\csxdefall{autonum@#1Referenced}{}% +} + +\def\autonum@use#1#2{% +#1{#2}% +} + \newcounter{autonum@counter} \def\autonum@patchShortcutEnvironment{% \def\[##1\]{% |