From 45315eeacd920a9de59a96471f23d904108cd94b Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 18 Jan 2015 22:04:07 +0000 Subject: autonum (18jan15) git-svn-id: svn://tug.org/texlive/trunk@36084 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/autonum/autonum.pdf | Bin 291482 -> 294486 bytes .../texmf-dist/doc/latex/autonum/test-autonum.pdf | Bin 102991 -> 103842 bytes .../texmf-dist/doc/latex/autonum/test-autonum.tex | 17 +++++ Master/texmf-dist/source/latex/autonum/autonum.dtx | 82 ++++++++++++++++----- Master/texmf-dist/tex/latex/autonum/autonum.sty | 22 +++--- 5 files changed, 93 insertions(+), 28 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/autonum/autonum.pdf b/Master/texmf-dist/doc/latex/autonum/autonum.pdf index 9f0c2751d5b..a286856378d 100644 Binary files a/Master/texmf-dist/doc/latex/autonum/autonum.pdf and b/Master/texmf-dist/doc/latex/autonum/autonum.pdf differ diff --git a/Master/texmf-dist/doc/latex/autonum/test-autonum.pdf b/Master/texmf-dist/doc/latex/autonum/test-autonum.pdf index 5f306d008a5..fb8c8377965 100644 Binary files a/Master/texmf-dist/doc/latex/autonum/test-autonum.pdf and b/Master/texmf-dist/doc/latex/autonum/test-autonum.pdf differ diff --git a/Master/texmf-dist/doc/latex/autonum/test-autonum.tex b/Master/texmf-dist/doc/latex/autonum/test-autonum.tex index 1e312c4bd23..df692263510 100644 --- a/Master/texmf-dist/doc/latex/autonum/test-autonum.tex +++ b/Master/texmf-dist/doc/latex/autonum/test-autonum.tex @@ -356,6 +356,23 @@ \end{split} \end{equation} Note, that the \textbackslash\texttt{label} must not be put inside the \texttt{split} environment, as according to the \AmS-math documentation \texttt{split} provides no numbering. + \item Split inside an equation, where the label is inside split (which is discouraged, see directly above) and reference \ref{insideSplit} + \begin{equation} + \begin{split} + \label{insideSplit} + \text{Check this line for an equation number!} + \end{split} + \end{equation} + \item This is a reference to an align environment with alignment \ref{alignment}. + \begin{align}% + a &= 1,\label{alignment}\\% + cd &= 2\label{rowTwo}% + \end{align}% + \item This is an align environment with alignment and no text before the equation sign (there once was an error with the optional argument handling of the newline command). + \begin{align} + a &= 1,\label{eq:a}\\ + &= 2\label{eq:b} + \end{align} \end{itemize} \section{Using ref in section \ref{i1}}\label{i1} text \ifcleveref{ diff --git a/Master/texmf-dist/source/latex/autonum/autonum.dtx b/Master/texmf-dist/source/latex/autonum/autonum.dtx index 4cc968f12cb..b0355fe7784 100644 --- a/Master/texmf-dist/source/latex/autonum/autonum.dtx +++ b/Master/texmf-dist/source/latex/autonum/autonum.dtx @@ -85,7 +85,7 @@ and the derived files autonum.ins, % %<*package> \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{autonum}[2015/01/03 v0.3.10 autonum LaTeX package] +\ProvidesPackage{autonum}[2015/01/18 v0.3.11 Automatic numbering of equations] \PassOptionsToPackage{hypertexnames=false}{hyperref} \RequirePackage{etoolbox} % @@ -145,6 +145,7 @@ and the derived files autonum.ins, %\changes{v0.3.8}{2014-04-14}{Correct vertical whitespace after long lines with split.} %\changes{v0.3.9}{2014-12-19}{Fix problems and increase robustness for split environment and newline options.} %\changes{v0.3.10}{2015-01-03}{Fix incompatibility to biblatex and possible other packages.} +%\changes{v0.3.11}{2015-01-18}{Fix referencing of align. Fix alignment directly following newline. Fix labeling split.} % % \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 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. @@ -267,7 +268,7 @@ and the derived files autonum.ins, % So it's a mess and probably not worth the time, as \texttt{hypertexnames=false} solves all these problems. % % \subsection{Reference commands}\label{referenceCommands} -% As default the \cmd{\ref} and cleveref's \cmd{\cref} commands are supported (the latter one only if the cleveref package is loaded). +% As default the \cmd{\ref} and cleveref's \cmd{\cref} commands are supported (the latter one only if the cleveref package is loaded). % If you want to add autonum support for other referencing commands, you have the following choices. Please mind that these interfaces might change in the future, as it's unclear what reference commands make sense beyond \cmd{\cref}. Please also mind the \cmd{\makeatletter} and \cmd{\makeatother} command before and after the commands, respectively. % %\begin{macro}{\autonum@generatePatchedReference} @@ -396,12 +397,26 @@ and the derived files autonum.ins, % \item Deniz Stiegemann % \begin{itemize} % \item found an incompatibility with biblatex, which lead to its fix +% \item found a bug when having a newline directly followed by an alignment character in an align environment, which lead to its fix +% \end{itemize} +% \item Fredrick Freekowtski +% \begin{itemize} +% \item found a bug when referencing an align environment, which lead to its fix +% \item found a bug when having a newline directly followed by an alignment character in an align environment, which lead to its fix +% \end{itemize} +% \item TeX Stack Exchange user bers +% \begin{itemize} +% \item found a bug when putting a label inside a split itself being inside of an equation, which lead to its fix +% \end{itemize} +% \item Denis Bitouzé +% \begin{itemize} +% \item found a bug when having a newline directly followed by an alignment character in an align environment, which lead to its fix % \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. +% 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. % % ^^A Calling the old newline command leads to a redefinition (overwriting, not patching) of the (current) newline command (proved by using \cmd{\show}\cmd{\\} before and after the call to amsmath's newline command) when using local definitions. As amsmath behaves like a virus then, the patched newline function is only called for the first newline. After the first call, amsmath's hijacked newline is used directly without giving a chance to do something useful. To correct this behavior, the newline command would need to be patched again. Unfortunately, \cmd{\let} cannot be used to save the current command, because the copy generated by \cmd{\let} is deleted by amsmath (WTF?). To avoid all this, some global definitions are used. % @@ -678,7 +693,7 @@ and the derived files autonum.ins, \def\autonum@patchBlockEnvironment#1{% % \autonum@debug{patchBlockEnvironment; 1=#1}% % \end{macrocode} -% There is no need to patch the newline or label commands like for the other environments, as they already have been patched in those outer math environments. So the environment subcommands do not have to be saved, too. +% There is no need to patch the newline or label commands like for the other environments, as they already have been patched in those outer math environments. So the environment subcommands do not have to be saved, too. However, split inside of an equation environment resets the label command, so that our version of the label command (of the equation) is no longer valid. Currently, this is taken care of in startChangeEnvironment. % \begin{macrocode} \autonum@renameEnvironment{#1}{0}% \autonum@changeEnvironment{#1}{0}% @@ -707,7 +722,7 @@ and the derived files autonum.ins, \deflength{\autonum@environmentWidth}{\linewidth-\multlinegap-\multlinegap}% \hspace{\autonum@environmentWidth}% % \end{macrocode} - % Using global here is necessary to get the information out of the environment. As \cmd{\\} has an optional argument, you would think, that \cmd{\GlobalCsLetLtxMacro} is correct, while \cmd{\global}\cmd{\cslet} is incorrect (\href{http://tex.stackexchange.com/a/29837}{see here}). But although \cmd{\\} has an optional argument, it does not use \cmd{\newcommand} (see the definintion of \cmd{\Let@} in amsmath.sty for the details), but plain \cmd{\TeX}. Although using LetLtxMacro \href{http://tex.stackexchange.com/a/88007}{should never no harm}, it results in errors here, so it isn't used. + % Using global here is necessary to get the information out of the environment. As \cmd{\\} has an optional argument, you would think, that \cmd{\GlobalCsLetLtxMacro} is correct, while \cmd{\global}\cmd{\cslet} is incorrect (\href{http://tex.stackexchange.com/a/29837}{see here}). But although \cmd{\\} has an optional argument, it does not use \cmd{\newcommand} (see the definintion of \cmd{\Let@} in amsmath.sty for the details), but plain \cmd{\TeX}. Although using LetLtxMacro \href{http://tex.stackexchange.com/a/88007}{should never no harm}, it results in errors here, so it isn't used. % \begin{macrocode} \global\cslet{autonum@newline#1}\\% % \end{macrocode} @@ -715,9 +730,10 @@ and the derived files autonum.ins, % \begin{macrocode} \notag % \end{macrocode} - % For multline, check, that autonum's label command is undefined, because this means, that the first pass (measuring pass) of the environment is active. This is to avoid getting the \cmd{\label} command of the second pass (displaying pass), where the \cmd{\label} command is set to the \href{http://tex.stackexchange.com/a/59088/7323}{null definition}. The multline environment seems to need the first pass, whereas other environments seem to need the second pass, so adapt to the environments. + % For multline, check, that autonum's label command is undefined, because this means, that the first pass (measuring pass) of the environment is active. This is to avoid getting the \cmd{\label} command of the second pass (displaying pass), where the \cmd{\label} command is set to the \href{http://tex.stackexchange.com/a/59088/7323}{null definition}. The multline environment seems to need the first pass, whereas other environments seem to need the second pass, so adapt to the environments. The following code does the macro definition twice for the other environments - once for the measurement pass and once for the display pass. This is not a problem, as the result of the first pass is overwritten with the correct definition in the second pass. % \begin{macrocode} \ifboolexpr{not test {\ifstrequal{#1}{multline}} or test {\ifcsundef{autonum@label#1}}}{% +% \autonum@debug{In saveEnvironmentSubcommands, define autonum@label#1 to \meaning\label}% \GlobalCsLetLtxMacro{autonum@label#1}\label }{}% \end{#1}% @@ -781,11 +797,21 @@ and the derived files autonum.ins, % Prepare the label and the newline commands and begin the displayed equation environment. % \begin{macrocode} \ifstrequal{#1}{split}{% +% \end{macrocode} + % Split does not have its own label command. However, beginning the split environment inside of an equation environment resets the label command so that our definition is no longer used. Thus, save the (currently patched) label command before starting the environment. +% \begin{macrocode} + \GlobalLetLtxMacro\autonum@outerMathEnvironmentLabel\label }{% \autonum@saveSubcommands }% + % \csuse{autonum@#1Old}#2% + % \ifstrequal{#1}{split}{% +% \end{macrocode} + % Restore the just saved label command (see above). +% \begin{macrocode} + \GlobalLetLtxMacro\label\autonum@outerMathEnvironmentLabel }{% \autonum@patchSubcommands{#1}% }% @@ -797,7 +823,7 @@ and the derived files autonum.ins, % Close the changed environment. % \begin{macrocode} \def\autonum@endChangeEnvironment#1{% -% \autonum@debug{endChangeEnvironment; 1=#1}% +% \autonum@debug{In endChangeEnvironment; 1=#1}% % \end{macrocode} % Possibly hide the number of the last equation in the displayed equation environment and end the latter one. % \begin{macrocode} @@ -808,7 +834,7 @@ and the derived files autonum.ins, % \begin{macrocode} \ifstrequal{#1}{split}{% % \end{macrocode} - % If a split environment is inside an align environment, the \cmd{\notag} must be set inside of the split environment to get correct vertical spacing after the environment if the line is so long, that the equation number would be placed below the equation and if the equation is not referenced. In order to set the \cmd{\notag} it must be known of the equation is referenced or not. With the current logic, the label is used to identify an equation. If the label is only given after the split (but before the line of the align ends), this is impossible, thus, the label has to be given before the end of the split environment. As split provides not numbering, it's best to provide the label before the beginning of the split environment. To save users, redefine \cmd{\label} to result in an error if the \cmd{\label} is called too late. In the future, this could be changed if equations have another unique identifier like a number. The \cmd{\label} can be overwritten (but mind the optional argument, which must be supported), as the split TeX-group will end directly after this macro. In order to be effective, it must be smuggled outside, which \cmd{\aftergroup@def} from etextools takes care of. Outside, it will be removed automatically, as soon as the TeX-group ends, e.g. if the line or the environment ends. + % If a split environment is inside an align environment, the \cmd{\notag} must be set inside of the split environment to get correct vertical spacing after the environment if the line is so long, that the equation number would be placed below the equation and if the equation is not referenced. In order to set the \cmd{\notag} it must be known if the equation is referenced or not. With the current logic, the label is used to identify an equation. If the label is only given after the split (but before the line of the align ends), this is impossible, thus, the label has to be given before the end of the split environment. As split provides no numbering, it's best to provide the label before the beginning of the split environment. To save users, redefine \cmd{\label} to result in an error if the \cmd{\label} is called too late. In the future, this could be changed if equations have another unique identifier like a number. The \cmd{\label} can be overwritten (but mind the optional argument, which must be supported), as the split TeX-group will end directly after this macro. In order to be effective, it must be smuggled outside, which \cmd{\aftergroup@def} from etextools takes care of. Outside, it will be removed automatically, as soon as the TeX-group ends, e.g. if the line or the environment ends. % \begin{macrocode} \renewcommand\label[2][]{% \PackageError{autonum}{% @@ -823,6 +849,7 @@ and the derived files autonum.ins, \autonum@restoreSubcommands \global\undef\autonum@currentLabel }% +% \autonum@debug{In endChangeEnvironment at the end}% } % \end{macrocode} %\end{macro} @@ -831,8 +858,8 @@ and the derived files autonum.ins, % Save the current newline and label commands. % \begin{macrocode} \def\autonum@saveSubcommands{% - \LetLtxMacro\autonum@labelNormal\label - \LetLtxMacro\autonum@newlineNormal\\% + \GlobalLetLtxMacro\autonum@labelNormal\label + \GlobalLetLtxMacro\autonum@newlineNormal\\% } % \end{macrocode} %\end{macro} @@ -860,8 +887,10 @@ and the derived files autonum.ins, % Restore the newline and label commands. This must be global, as it had been overwritten globally in \cmd{\autonum@patchSubcommands}. % \begin{macrocode} \def\autonum@restoreSubcommands{% +% \autonum@debug{In restoreSubcommands}% \GlobalLetLtxMacro\label\autonum@labelNormal \GlobalLetLtxMacro\\\autonum@newlineNormal +% \autonum@debug{In restoreSubcommands at the end}% } % \end{macrocode} %\end{macro} @@ -874,6 +903,12 @@ and the derived files autonum.ins, % As the \cmd{\label} command can have an optional argument (see cleveref: Overriding the Cross-Reference Type), it must be supported in the patched version of the command, too. As the basic version of \cmd{\label} does not support an optional argument (see texdoc source2e), inside of the following macro the label command must not be called with a possible empty optional argument unconditionally. Instead, there must be a test if an optional argument has been provided and only then it must be used in the call of the original label command. Use the trick with the \href{http://tex.stackexchange.com/a/60896}{empty macro} as a test. % \begin{macrocode} \newcommandsequence{autonum@patched#1Label}[2][]{% +% \autonum@debug{In patched#1Label, 1=##1, 2=##2}% +% \end{macrocode} + % Do not do the labeling work twice, i.e. in amsmath's measuring and in it's display pass. Doing everything in the display pass is correct, because during the measuring pass, the original label commands are set to only gobble their arguments instead of doing something useful (the latter is done in the display pass). +% \begin{macrocode} + \ifmeasuring@ + \else % \end{macrocode} % The labeling information is needed in the newline command. Therefore, the following variable is used to store it until the next newline command. As the definition is local and every line in an multi-line displayed math environment has its own group, the variable does not have to be deleted explicitly. % \begin{macrocode} @@ -894,6 +929,7 @@ and the derived files autonum.ins, % \begin{macrocode} \def\autonum@currentLabel{##2}% }{% +% \autonum@debug{In patched#1Label, currentLabel globally defined to ##2}% \global\def\autonum@currentLabel{##2}% }% }% @@ -901,6 +937,7 @@ and the derived files autonum.ins, % Only call the original label command if the label gets referenced. This obviously is identical if the reference is located before the label. It is also identical if the reference is located after the label, as the \cmd{\\} or \cmd{\endenvironment} commands which follow the \cmd{\label} would suppress the numbering anyway in the first pass. In the second pass, the information about referencing is the same as if only the content of the following if-command were available. % \begin{macrocode} \ifcsedef{autonum@##2Referenced}{% +% \autonum@debug{In patched#1Label, label ##2 has been referenced}% % \end{macrocode} % The environment's original label command is called to do the real labeling. As it checks for erroneous succeeding labels using \cmd{df@label}, this variable has to be emptied before every call. % \begin{macrocode} @@ -908,12 +945,17 @@ and the derived files autonum.ins, % \end{macrocode} % If the following test is true, \cmd{\label} has been called without optional argument, as the default has been used internally. This test is from \href{http://tex.stackexchange.com/a/53091}{egreg}. % \begin{macrocode} +% \autonum@debug{In patched#1Label, autonum@label#1 is called with mandatory argument ##2}% \if\relax\detokenize{##1}\relax +% \autonum@debug{In patched#1Label, no optional argument given}% \csuse{autonum@label#1}{##2}% \else \csuse{autonum@label#1}[##1]{##2}% \fi - }{}% + }{% +% \autonum@debug{In patched#1Label, label ##2 has not been referenced}% + }% + \fi }% } % \end{macrocode} @@ -924,16 +966,17 @@ and the derived files autonum.ins, % \begin{macrocode} \def\autonum@generatePatchedNewline#1{% % \end{macrocode} -% The \cmd{\\} command has an optional argument, e.g. in an align environment, to put some extra vertical space between two lines. Thus, the patched newline command must currectly cope with an optional argument, too, if it has been given. +% The \cmd{\\} command has an optional argument, e.g. in an align environment, to put some extra vertical space between two lines. Thus, the patched newline command must correctly cope with an optional argument, too, if it has been given. % \begin{macrocode} - \newcommandsequence{autonum@patched#1Newline}[1][]{% + \newcommandsequence{autonum@patched#1Newline}{% +% \autonum@debug{In patched#1Newline, 1=##1}% \autonum@possiblyHideNumber - \if\relax\detokenize{##1}\relax - \csuse{autonum@newline#1}% - \else - \csuse{autonum@newline#1}[##1]% - \fi \global\undef\autonum@currentLabel +% \autonum@debug{\expandafter\meaning\csname autonum@newline#1\endcsname}% + \csuse{autonum@newline#1}% +% \end{macrocode} + % CAUTION: Do not write code below this comment and inside of this macro. This is because the newline command above looks for an optional argument in the input stream, which it cannot read if there are further tokens inside of this macro. Absorbing the optional argument in this macro and transfering it to the newline command did have unexpected side effects (a test case has been added for this). +% \begin{macrocode} }% } % \end{macrocode} @@ -944,6 +987,7 @@ and the derived files autonum.ins, % \begin{macrocode} \def\autonum@possiblyHideNumber{ \ifdef{\autonum@currentLabel}{% +% \autonum@debug{In possiblyHideNumber, existing currentLabel=\autonum@currentLabel}% \ifcsedef{autonum@\autonum@currentLabel Referenced}{% }{% \notag @@ -1041,6 +1085,7 @@ and the derived files autonum.ins, % \begin{macrocode} % \autonum@processReferenceHelper{reference command name}{extraction command name}{star or empty}{label} \def\autonum@processReferenceHelper#1#2#3#4{% +% \autonum@debug{In processReferenceHelper, 1=#1, 2=\detokenize{#2}, 3=#3, 4=#4}% \skipInPDFTOC{% \vanishprotect{% \csuse{#2}{\protect\autonum@markLabelAsReferenced}{#4}% @@ -1055,6 +1100,7 @@ and the derived files autonum.ins, % 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{% +% \autonum@debug{In markLabelAsReferenced, autonum@#1Referenced defined}% \csxdefall{autonum@#1Referenced}{}% } % \end{macrocode} diff --git a/Master/texmf-dist/tex/latex/autonum/autonum.sty b/Master/texmf-dist/tex/latex/autonum/autonum.sty index 09ad9b60fc1..fc2f22192b8 100644 --- a/Master/texmf-dist/tex/latex/autonum/autonum.sty +++ b/Master/texmf-dist/tex/latex/autonum/autonum.sty @@ -13,7 +13,7 @@ %% ---------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{autonum}[2015/01/03 v0.3.10 autonum LaTeX package] +\ProvidesPackage{autonum}[2015/01/18 v0.3.11 Automatic numbering of equations] \PassOptionsToPackage{hypertexnames=false}{hyperref} \RequirePackage{etoolbox} \makeatletter % The missing \makeatother command is on purpose (as every other combination results in an error). @@ -203,11 +203,13 @@ with \expandafter\detokenize\expandafter{\csname\string#1\endcsname}defined as\M \def\autonum@startChangeEnvironment#1#2{% \ifstrequal{#1}{split}{% +\GlobalLetLtxMacro\autonum@outerMathEnvironmentLabel\label }{% \autonum@saveSubcommands }% \csuse{autonum@#1Old}#2% \ifstrequal{#1}{split}{% +\GlobalLetLtxMacro\label\autonum@outerMathEnvironmentLabel }{% \autonum@patchSubcommands{#1}% }% @@ -233,8 +235,8 @@ when using autonum. Wrongly placed label is:\MessageBreak } \def\autonum@saveSubcommands{% -\LetLtxMacro\autonum@labelNormal\label -\LetLtxMacro\autonum@newlineNormal\\% +\GlobalLetLtxMacro\autonum@labelNormal\label +\GlobalLetLtxMacro\autonum@newlineNormal\\% } \def\autonum@patchSubcommands#1{% @@ -252,6 +254,8 @@ when using autonum. Wrongly placed label is:\MessageBreak \def\autonum@generatePatchedLabel#1{% \newcommandsequence{autonum@patched#1Label}[2][]{% +\ifmeasuring@ +\else \ifdef{\autonum@currentLabel}{% \ifmeasuring@ \PackageError{autonum}{Two succeeding \string\label's detected}{Did you forget a \string\\?}% @@ -270,19 +274,17 @@ when using autonum. Wrongly placed label is:\MessageBreak \else \csuse{autonum@label#1}[##1]{##2}% \fi -}{}% +}{% +}% +\fi }% } \def\autonum@generatePatchedNewline#1{% -\newcommandsequence{autonum@patched#1Newline}[1][]{% +\newcommandsequence{autonum@patched#1Newline}{% \autonum@possiblyHideNumber -\if\relax\detokenize{##1}\relax -\csuse{autonum@newline#1}% -\else -\csuse{autonum@newline#1}[##1]% -\fi \global\undef\autonum@currentLabel +\csuse{autonum@newline#1}% }% } -- cgit v1.2.3