Ian Jauslin
summaryrefslogtreecommitdiff
blob: 5e0408e0206d92e349ec9bd21c7070a401329bad (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
%%
%% This file contains the main style commands
%%
%% Some options can be set by changing the \loaddefaults command
%%

\usepackage{color}
\usepackage{marginnote}

\def\loaddefaults{
  \sectionstrue
  \subseqcountfalse
  \def\seqskip{\vskip1.5cm}
  \def\subseqskip{\vskip1cm}
  \resetpointattheofalse
  \parindent=0pt
  \def\indent{\hskip20pt}
}

% false if there are no sections
\newif\ifsections
% true if equation numbers should include the subsection number
\newif\ifsubseqcount
% true if there is a table of contents
\newif\iftoc
% true if point counting should reset at each theorem
\newif\ifresetpointattheo

% a prefix to put before the section number, e.g. A for appendices
\def\sectionprefix{}

\loaddefaults

%% style for the equation number
\def\eqnumstyle{}

%% hyperlinks
% hyperlinkcounter
\newcounter{lncount}
% hyperref anchor
\def\hrefanchor{%
\stepcounter{lncount}%
\hypertarget{ln.\thelncount}{}%
}

%% define a command and write it to aux file
\def\outdef#1#2{%
% define command
\expandafter\xdef\csname #1\endcsname{#2}%
% hyperlink number
\expandafter\xdef\csname #1@hl\endcsname{\thelncount}%
% write command to aux
\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1\endcsname{\csname #1\endcsname}}%
\immediate\write\@auxout{\noexpand\expandafter\noexpand\gdef\noexpand\csname #1@hl\endcsname{\thelncount}}%
}


%% define a label for the latest tag
%% label defines a command containing the string stored in \tag
\AtBeginDocument{
  \def\label#1{\expandafter\outdef{#1}{\safe\tag}}

\def\ref#1{%
% check whether the label is defined (hyperlink runs into errors if this check is ommitted)
\ifcsname #1@hl\endcsname%
\hyperlink{ln.\csname #1@hl\endcsname}{\safe\csname #1\endcsname}%
\else%
\safe\csname #1\endcsname%
\fi%
}
}

%% counters
\newcounter{sectioncount}
\newcounter{subsectioncount}
\newcounter{pointcount}
\newcounter{subpointcount}
\newcounter{subsubpointcount}
\newcounter{seqcount}
\newcounter{figcount}
\newcounter{Theocount}
\newcounter{tocsectioncount}
\newcounter{tocsubsectioncount}

%% section command
\newlength\secnumwidth
\newlength\sectitlewidth
\def\section#1{%
% reset counters
\stepcounter{sectioncount}%
\setcounter{subsectioncount}{0}%
\setcounter{pointcount}{0}%
\setcounter{subpointcount}{0}%
\setcounter{subsubpointcount}{0}%
\setcounter{figcount}{0}%
\setcounter{Theocount}{0}%
\setcounter{seqcount}{0}%
% space before section (if not first)
\ifnum\thesectioncount>1%
\seqskip%
\penalty-1000%
\fi%
% hyperref anchor
\hrefanchor%
% define tag (for \label)
\xdef\tag{\sectionprefix\thesectioncount}%
% get widths
\def\@secnum{{\bf\Large\sectionprefix\thesectioncount.\hskip10pt}}%
\settowidth\secnumwidth{\@secnum}%
\setlength\sectitlewidth\textwidth%
\addtolength\sectitlewidth{-\secnumwidth}%
% print name
\parbox{\textwidth}{%
\@secnum%
\parbox[t]{\sectitlewidth}{\Large\bf #1}}%
% write to table of contents
\iftoc%
% save lncount in aux variable which is written to toc
\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@sec.\thesectioncount\endcsname{\thelncount}}%
\write\tocoutput{\noexpand\tocsection{#1}{\thepage}}%
\fi%
\par\penalty10000%
\bigskip\penalty10000%
}

%% subsection
\def\subsection#1{
% counters
\stepcounter{subsectioncount}%
\setcounter{pointcount}{0}%
\setcounter{subpointcount}{0}%
\setcounter{subsubpointcount}{0}%
\ifsubseqcount%
\setcounter{seqcount}0%
\fi%
% space before subsection (if not first)
\ifnum\thesubsectioncount>1%
\subseqskip%
\penalty-500%
\fi%
% hyperref anchor
\hrefanchor
% define tag (for \label)
\xdef\tag{\sectionprefix\thesectioncount.\thesubsectioncount}%
% get widths
\def\@secnum{{\bf\large\hskip.5cm\sectionprefix\thesectioncount.\thesubsectioncount.\hskip5pt}}%
\settowidth\secnumwidth{\@secnum}%
\setlength\sectitlewidth\textwidth%
\addtolength\sectitlewidth{-\secnumwidth}%
% print name
\parbox{\textwidth}{%
\@secnum%
\parbox[t]{\sectitlewidth}{\large\bf #1}}%
% write to table of contents
\iftoc%
% save lncount in aux variable which is written to toc
\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@subsec.\thesectioncount.\thesubsectioncount\endcsname{\thelncount}}%
\write\tocoutput{\noexpand\tocsubsection{#1}{\thepage}}%
\fi%
\par\penalty10000%
\medskip\penalty10000%
}

%% points
\def\point{
  \stepcounter{pointcount}
  \setcounter{subpointcount}{0}
  % hyperref anchor
  \hrefanchor
  \indent{\bf \thepointcount\ - }
  % define tag (for \label)
  \xdef\tag{\thepointcount}
}
\def\subpoint{
  \stepcounter{subpointcount}
  \setcounter{subsubpointcount}0
  % hyperref anchor
  \hrefanchor
  \indent\hskip.5cm{\bf \thepointcount-\thesubpointcount\ - }
  % define tag (for \label)
  \xdef\tag{\thepointcount-\thesubpointcount}
}
\def\subsubpoint{
  \stepcounter{subsubpointcount}
  % hyperref anchor
  \hrefanchor
  \indent\hskip1cm{\bf \thepointcount-\thesubpointcount-\thesubsubpointcount\ - }
  % define tag (for \label)
  \xdef\tag{\thepointcount-\thesubpointcount-\thesubsubpointcount}
}
% reset points
\def\resetpointcounter{
  \setcounter{pointcount}{0}
  \setcounter{subpointcount}{0}
  \setcounter{subsubpointcount}{0}
}

%% equation numbering
\def\seqcount{
  \stepcounter{seqcount}
  % the output
  \edef\seqformat{\theseqcount}
  % add subsection number
  \ifsubseqcount
    \let\tmp\seqformat
    \edef\seqformat{\thesubsectioncount.\tmp}
  \fi
  % add section number
  \ifsections
    \let\tmp\seqformat
    \edef\seqformat{\sectionprefix\thesectioncount.\tmp}
  \fi
  % define tag (for \label)
  \xdef\tag{\seqformat}
  % write number
  \marginnote{\eqnumstyle\hfill(\seqformat)}
}
%% equation environment compatibility
\def\equation{\hrefanchor$$\seqcount}
\def\endequation{$$\@ignoretrue}

%% figures
\newlength\figwidth
\setlength\figwidth\textwidth
\addtolength\figwidth{-2.5cm}

\def\figcount#1{%
\stepcounter{figcount}%
% hyperref anchor
\hrefanchor%
% the number of the figure
\edef\figformat{\thefigcount}%
% add section number
\ifsections%
\let\tmp\figformat%
\edef\figformat{\sectionprefix\thesectioncount.\tmp}%
\fi%
% define tag (for \label)
\xdef\tag{\figformat}%
% write
\hfil fig \figformat: \parbox[t]{\figwidth}{\small#1}%
\par\bigskip%
}

%% environment
\def\figure{
  \par\penalty-500
}
\def\endfigure{
  \par\penalty-1000
}
\let\caption\figcount

%% delimiters
\def\delimtitle#1{\par \leavevmode\raise.3em\hbox to\hsize{\lower0.3em\hbox{\vrule height0.3em}\hrulefill\ \lower.3em\hbox{#1}\ \hrulefill\lower0.3em\hbox{\vrule height0.3em}}\par\penalty10000}
\def\delim{\par\leavevmode\raise.3em\hbox to\hsize{\vrule height0.3em\hrulefill\vrule height0.3em}\par\penalty10000}
\def\enddelim{\par\penalty10000\leavevmode\raise.3em\hbox to\hsize{\vrule height0.3em\hrulefill\vrule height0.3em}\par}

%% theorem headers
\def\theo#1{
  \stepcounter{Theocount}
  % reset points
  \ifresetpointattheo\resetpointcounter\fi
  % hyperref anchor
  \hrefanchor
  % the number
  \def\formattheo{\theTheocount}
  % add section number
  \ifsections
    \let\tmp\formattheo
    \edef\formattheo{\sectionprefix\thesectioncount.\tmp}
  \fi
  % define tag (for \label)
  \xdef\tag{\formattheo}
  % write
  \delimtitle{\bf #1 \formattheo}
}
\let\endtheo\enddelim

%% start appendices
\def\appendix{%
\vfill
\pagebreak
% counter
\setcounter{sectioncount}0%
% prefix
\def\sectionprefix{A}%
% write
{\bf \LARGE Appendices}\par\penalty10000\bigskip\penalty10000%
% add a mention in the table of contents
\iftoc%
\immediate\write\tocoutput{\noexpand\tocappendices}\penalty10000%
\fi%
%% uncomment for new page for each appendix
%\def\seqskip{\vfill\pagebreak}
}

%% start references
\def\references{%
\hrefanchor%
% write
{\bf \LARGE References}\par\penalty10000\bigskip\penalty10000%
% add a mention in the table of contents
\iftoc%
% save lncount in aux variable which is written to toc
\immediate\write\tocoutput{\noexpand\expandafter\noexpand\edef\noexpand\csname toc@references\endcsname{\thelncount}}%
\write\tocoutput{\noexpand\tocreferences{\thepage}}\penalty10000%
\fi%
}


%% table of contents
\newif\iftocopen
\def\tableofcontents{
{\bf \large Table of contents:}\par\penalty10000\bigskip\penalty10000%
% copy content from file
\IfFileExists{\jobname.toc}{\input{\jobname.toc}}{{\tt error: table of contents missing}}
% open new toc
\newwrite\tocoutput
\immediate\openout\tocoutput=\jobname.toc
\toctrue
}
%% close file
\AtEndDocument{
  % close toc
  \iftoc
    \immediate\closeout\tocoutput
  \fi
}


%% fill line with dots
\def\leaderfill{\leaders\hbox to 1em {\hss. \hss}\hfill}

%% same as sectionprefix
\def\tocsectionprefix{}

%% toc formats
\def\tocsection #1#2{
  \stepcounter{tocsectioncount}
  \setcounter{tocsubsectioncount}{0}
  % write
  \smallskip\hyperlink{ln.\csname toc@sec.\thetocsectioncount\endcsname}{{\bf \tocsectionprefix\thetocsectioncount}.\hskip5pt #1\leaderfill#2}\par
}
\def\tocsubsection #1#2#3{
  \stepcounter{tocsubsectioncount}
  % write
  {\hskip10pt\hyperlink{ln.\csname toc@subsec.\thetocsectioncount.\thetocsubsectioncount\endcsname}{{\bf \thetocsubsectioncount}.\hskip5pt {\small #1}\leaderfill#3}}\par
}
\def\tocappendices{
  \medskip
  \setcounter{tocsectioncount}0
  {\bf Appendices}\par
  \smallskip
  \def\tocsectionprefix{A}
}
\def\tocreferences#1{
  \medskip
  {\hyperlink{ln.\csname toc@references\endcsname}{{\bf References}\leaderfill#1}}\par
  \smallskip
}