This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimetravel.sty
79 lines (67 loc) · 2.19 KB
/
timetravel.sty
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Use the command \setCounters{counter1,counter2,..} to specify the
%% set of counters that should be included in the time travel.
%%
%% Create named wormholes using the command \wormhole{name}.
%%
%% Between \begin{backInTime}{wormholename} and \end{backInTime}, the
%% counters specified with \setCounters are temporarily reset to the
%% value they had when the wormhole with the name "wormholename" was
%% defined.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ProvidesPackage{timetravel}
\newcommand{\setCounters}[1]{
\def\@allCounters{#1}
\@initCounters
}
\newcommand{\wormhole}[1]{
% the argument is a new label
%
% just save all counters at this point and associate the values with
% the new label
\@processlist{\@saveCounter{#1}}{\@allCounters}
}
\newenvironment{backInTime}[1]{
% first argument is a label defined with \wormhole
%
% sets all counters back to the value they had when the label was
% defined and restore the current value afterwards
\@processlist{\begin{@tmpRestoreCounter}{#1}}{\@allCounters}
}{
\@processlist{\end{@tmpRestoreCounter}\@comment}{\@allCounters}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% internal stuff
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@allCounters{}
\newcommand{\@saveCounter}[2]{
% first argument is the label, second the counter
%
% just save the value of the counter at the current position
\newcounter{#1#2}
\setcounter{#1#2}{\value{#2}}
}
\newcommand{\@initCounters}{
\@processlist{\@makeTmpCounter}{\@allCounters}
}
\newcommand{\@makeTmpCounter}[1]{
\newcounter{tmp#1}
}
\newenvironment{@tmpRestoreCounter}[2]{
% first argument is the label, second the counter
%
% sets the counter back to the value it had at the label defined
% with \wormhole and restores the current value afterwards
\def\counter{#2}
% \newcounter{tmp#2}
\setcounter{tmp#2}{\value{#2}}
\setcounter{#2}{\value{#1#2}}
}{
\setcounter{\counter}{\value{tmp\counter}}
}
\newcommand{\@comment}[1]{}
\newcommand{\@processlist}[2]{
\@for\timetraveliter:=#2\do{%
#1{\timetraveliter}
}
}