diff options
author | Karl Berry <karl@freefriends.org> | 2012-07-29 16:57:52 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-07-29 16:57:52 +0000 |
commit | 40fe9708662f86fa78b25ecc2a94b477c1d9bf89 (patch) | |
tree | 00afaa4dd50e0580293cbd4c1d9a53ad4e46b9de /Master/texmf-dist/tex/latex | |
parent | 25276daa94b0360e0b1b48d35a4b3cff12b73182 (diff) |
autonum (23jun12)
git-svn-id: svn://tug.org/texlive/trunk@27224 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/autonum/autonum.sty | 204 |
1 files changed, 161 insertions, 43 deletions
diff --git a/Master/texmf-dist/tex/latex/autonum/autonum.sty b/Master/texmf-dist/tex/latex/autonum/autonum.sty index 303aa4f89c7..cb9833848fe 100644 --- a/Master/texmf-dist/tex/latex/autonum/autonum.sty +++ b/Master/texmf-dist/tex/latex/autonum/autonum.sty @@ -13,30 +13,73 @@ %% ---------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{autonum}[2012/05/26 v0.1 autonum LaTeX package] +\ProvidesPackage{autonum}[2012/06/21 v0.2 autonum LaTeX package] +\PassOptionsToPackage{hypertexnames=false}{hyperref} \RequirePackage{etoolbox} +\RequirePackage{amsmath} +\RequirePackage[absolute]{textpos} -\newcommand{\csxdefaux}[2]{% +\def\csxdefaux#1#2{% \protected@write\@mainaux{}{% \expandafter\string\expandafter\xdef\expandafter\string\csname #1\endcsname{#2}% }% } -\newcommand{\csxdefall}[2]{% +\def\csxdefall#1#2{% \csxdefaux{#1}{#2}% \csxdef{#1}{#2}% } -\newcounter{autonum@counter} +\def\ifcsedef#1#2#3{% +\edef\autonum@ifcsedefTemp{#1}% +\expandafter\ifcsdef\expandafter{\autonum@ifcsedefTemp}{#2}{#3}% +\undef{\autonum@ifcsedefTemp}% +} -\newcommand{\autonum@patchEnvironment}[1]{ -\csletcs{autonum@#1Old}{#1}% -\csletcs{autonum@end#1Old}{end#1}% -\autonum@saveOldEnvironment{#1}% +\AtBeginDocument{% +\forcsvlist{\autonum@patchFullEnvironment}{equation,gather,multline,align}% +\def\[#1\]{% +\begin{equation}#1\end{equation}% +}% +\autonum@generatePatchedReference{ref}% +\ifdef{\cref}{% +\autonum@generatePatchedReference{cref}% +}{}% +} + +\def\autonum@patchFullEnvironment#1{% +\autonum@saveEnvironmentSubcommands{#1}{center}% +\autonum@patchEnvironmentHelper{#1}% +} +\def\autonum@patchBlockEnvironment#1{% +\autonum@saveEnvironmentSubcommands{#1}{equation*}% +\autonum@patchEnvironmentHelper{#1}% +} +\def\autonum@patchEnvironmentHelper#1{% +\autonum@renameEnvironment{#1}% \autonum@changeEnvironment{#1}% +\autonum@generatePatchedLabel{#1}% +\autonum@generatePatchedNewline{#1}% } -\newcommand{\autonum@saveOldEnvironment}[1]{ +\def\autonum@saveEnvironmentSubcommands#1#2{% +\begin{textblock}{1}[1,1](0,0)% +\begin{#2} +\begin{#1}% +\global\cslet{autonum@newline#1}\\% +\notag% +\ifboolexpr{not test {\ifstrequal{#1}{multline}} or test {\ifcsundef{autonum@label#1}}}{% +\global\cslet{autonum@label#1}{\label}% +}% +\notag% +\end{#1}% +\end{#2} +\end{textblock}% +} + +\def\autonum@renameEnvironment#1{% +\csletcs{autonum@#1Old}{#1}% +\csletcs{autonum@end#1Old}{end#1}% \newenvironment{#1+}{% \csuse{autonum@#1Old}% }{% @@ -44,61 +87,136 @@ }% } -\newcommand{\autonum@changeEnvironment}[1]{ +\def\autonum@changeEnvironment#1{% \renewenvironment{#1}{% -\autonum@IfReferenced{\Roman{autonum@counter}}{% +\autonum@saveSubcommands \csuse{autonum@#1Old}% +\autonum@patchSubcommands{#1}% }{% -\begin{#1*}% -}% -}{% -\autonum@IfReferenced{\Roman{autonum@counter}}{% +\autonum@possiblyHideNumber \csuse{autonum@end#1Old}% -}{% -\end{#1*}% -\ignorespacesafterend +\autonum@restoreSubcommands }% -\stepcounter{autonum@counter}% +\global\csundef{#1*}% +\global\csundef{end#1*}% +} + +\def\autonum@saveSubcommands{% +\let\autonum@labelNormal\label% +\let\autonum@newlineNormal\\% +} + +\def\autonum@patchSubcommands#1{% +\global\letcs{\label}{autonum@patched#1Label}% +\ifstrequal{#1}{multline}{% +}{% + \global\letcs{\\}{autonum@patched#1Newline}% }% } -\AfterPreamble{ -\autonum@patchEnvironment{equation} -%% \forcsvlist{\autonum@patchEnvironment}{gather,multline,align.flalign,alignat} +\def\autonum@restoreSubcommands{% +\global\let\label\autonum@labelNormal% +\global\let\\\autonum@newlineNormal% +} -\ifcsundef{equation*}{% -\newenvironment{equation*}{\[}{\]}% +\def\autonum@generatePatchedLabel#1{% +\csdef{autonum@patched#1Label}##1{% +\ifdef{\autonum@currentLabel}{% +\PackageError{autonum}{Two succeeding \string\label's detected}{Did you forget a \string\\?}% +}{% +\def\autonum@currentLabel{##1}% +}% +\ifcsedef{autonum@##1Referenced}{% +\let\df@label\@empty% +\csuse{autonum@label#1}{##1}% }{} +}% +} + +\def\autonum@generatePatchedNewline#1{% +\csdef{autonum@patched#1Newline}{% +\autonum@possiblyHideNumber +\csuse{autonum@newline#1}% +} +} -\newcommand{\autonum@IfReferenced}[3]{% -\ifcsdef{autonum@#1Referenced}{#2}{#3}% +\def\autonum@possiblyHideNumber{ +\ifdef{\autonum@currentLabel}{% +\ifcsedef{autonum@\csuse{autonum@currentLabel}Referenced}{% +}{% +\notag% +} +}{% +\notag% +}% } -\newcommand{\autonum@patchLabel}[1]{% -\letcs{\autonum@labelOld}{#1}% +\def\autonum@generatePatchedReference#1{% +\csletcs{autonum@reference#1Old}{#1}% \csdef{#1}##1{% -\csxdefall{autonum@##1Labeled}{\Roman{autonum@counter}}% -\autonum@labelOld{##1}% +\csxdefall{autonum@##1Referenced}{}% +\csuse{autonum@reference#1Old}{##1}% }% } -\ifdef{\label@in@display}{% -\autonum@patchLabel{label@in@display}% + +\newcounter{autonum@counter} +\def\autonum@patchShortcutEnvironment{% +\def\[##1\]{% +\ifcsedef{autonum@\Roman{autonum@counter}HasExactlyOneLine}{% +\autonum@useWithMultipleLineDetection{equation}{##1}% }{% -\autonum@patchLabel{label}% +\autonum@useWithMultipleLineDetection{align}{##1}% +}% +\stepcounter{autonum@counter}% +}% } -\newcommand{\autonum@patchReference}[1]{% -\letcs{\autonum@referenceOld}{#1}% -\csdef{#1}##1{% -\ifcsdef{autonum@##1Labeled}{% -\csxdefall{autonum@\csuse{autonum@##1Labeled}Referenced}{}% -}{}% -\autonum@referenceOld{##1}% +\def\autonum@useWithMultipleLineDetection#1#2{% +\begin{#1}% +\autonum@patchParentheses +\global\let\autonum@patchedNewline\\% +\ifstrequal{#1}{align}{% +\gdef\\{% +\autonum@patchedNewline +\gdef\autonum@multipleLines{}% +}% +}{% +\gdef\\{% +\gdef\autonum@multipleLines{}% }% } -\autonum@patchReference{ref}% -\ifdef{\cref}{% -\autonum@patchReference{cref}% +#2% +\global\let\\\autonum@patchedNewline% +\ifdef{\autonum@multipleLines}{% +\global\undef{\autonum@multipleLines}% +}{% +\csxdefaux{autonum@\Roman{autonum@counter}HasExactlyOneLine}{\Roman{autonum@counter}}% +}% +\autonum@restoreParentheses +\end{#1}% +} + +\global\def\autonum@patchParentheses{% +\autonum@patchParenthesis{(}{Left}{}% +\autonum@patchParenthesis{)}{Right}{end}% +} + +\global\def\autonum@patchParenthesis#1#2#3{% +\ifcsdef{#1}{% +\global\csletcs{autonum@old#2Parenthesis}{#1}% +}{}% +\global\csletcs{#1}{#3split}% +} + +\global\def\autonum@restoreParentheses{% +\autonum@restoreParenthesis{(}{Left}% +\autonum@restoreParenthesis{)}{Right}% +} + +\global\def\autonum@restoreParenthesis#1#2{% +\ifcsdef{autonum@old#2Parenthesis}{% +\global\csletcs{#1}{autonum@old#2Parenthesis}% +\global\csundef{autonum@old#2Parenthesis}% }{}% } |