summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/autonum/autonum.sty
blob: 303aa4f89c7a7d034c22257cc0d3e072d2f482ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
%%
%% This is file `autonum.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% autonum.dtx  (with options: `package')
%% ----------------------------------------------------------------
%% autonum --- Automatic number referenced equations
%% E-mail: pat_h@web.de
%% Released under the LaTeX Project Public License v1.3c or later
%% See http://www.latex-project.org/lppl.txt
%% ----------------------------------------------------------------
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{autonum}[2012/05/26 v0.1 autonum LaTeX package]
\RequirePackage{etoolbox}

\newcommand{\csxdefaux}[2]{%
\protected@write\@mainaux{}{%
\expandafter\string\expandafter\xdef\expandafter\string\csname #1\endcsname{#2}%
}%
}

\newcommand{\csxdefall}[2]{%
\csxdefaux{#1}{#2}%
\csxdef{#1}{#2}%
}

\newcounter{autonum@counter}

\newcommand{\autonum@patchEnvironment}[1]{
\csletcs{autonum@#1Old}{#1}%
\csletcs{autonum@end#1Old}{end#1}%
\autonum@saveOldEnvironment{#1}%
\autonum@changeEnvironment{#1}%
}

\newcommand{\autonum@saveOldEnvironment}[1]{
\newenvironment{#1+}{%
\csuse{autonum@#1Old}%
}{%
\csuse{autonum@end#1Old}%
}%
}

\newcommand{\autonum@changeEnvironment}[1]{
\renewenvironment{#1}{%
\autonum@IfReferenced{\Roman{autonum@counter}}{%
\csuse{autonum@#1Old}%
}{%
\begin{#1*}%
}%
}{%
\autonum@IfReferenced{\Roman{autonum@counter}}{%
\csuse{autonum@end#1Old}%
}{%
\end{#1*}%
\ignorespacesafterend
}%
\stepcounter{autonum@counter}%
}%
}

\AfterPreamble{
\autonum@patchEnvironment{equation}
%%  \forcsvlist{\autonum@patchEnvironment}{gather,multline,align.flalign,alignat}

\ifcsundef{equation*}{%
\newenvironment{equation*}{\[}{\]}%
}{}

\newcommand{\autonum@IfReferenced}[3]{%
\ifcsdef{autonum@#1Referenced}{#2}{#3}%
}

\newcommand{\autonum@patchLabel}[1]{%
\letcs{\autonum@labelOld}{#1}%
\csdef{#1}##1{%
\csxdefall{autonum@##1Labeled}{\Roman{autonum@counter}}%
\autonum@labelOld{##1}%
}%
}
\ifdef{\label@in@display}{%
\autonum@patchLabel{label@in@display}%
}{%
\autonum@patchLabel{label}%
}

\newcommand{\autonum@patchReference}[1]{%
\letcs{\autonum@referenceOld}{#1}%
\csdef{#1}##1{%
\ifcsdef{autonum@##1Labeled}{%
\csxdefall{autonum@\csuse{autonum@##1Labeled}Referenced}{}%
}{}%
\autonum@referenceOld{##1}%
}%
}
\autonum@patchReference{ref}%
\ifdef{\cref}{%
\autonum@patchReference{cref}%
}{}%
}

%% 
%% Copyright (C) 2012 by Patrick Häcker <pat_h@web.de>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License (LPPL), either
%% version 1.3c of this license or (at your option) any later
%% version.  The latest version of this license is in the file:
%% 
%% http://www.latex-project.org/lppl.txt
%% 
%% This work is "maintained" (as per LPPL maintenance status) by
%% Patrick Häcker.
%% 
%% This work consists of the file  autonum.dtx
%% and the derived files           autonum.ins,
%%                                 autonum.pdf and
%%                                 autonum.sty.
%% 
%%
%% End of file `autonum.sty'.