Ian Jauslin
summaryrefslogtreecommitdiff
blob: 538a108c8f09c1ce849a6e82bf644260dbb31c2d (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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
%%
%% Ian's class file
%%

%% TeX format
\NeedsTeXFormat{LaTeX2e}[1995/12/01]

%% class name
\ProvidesClass{ian}[2017/09/29]

%% boolean to signal that this class is being used
\newif\ifianclass

%% options
% no section numbering in equations
\DeclareOption{section_in_eq}{\sectionsineqtrue}
\DeclareOption{section_in_fig}{\sectionsinfigtrue}
\DeclareOption{section_in_theo}{\PassOptionsToPackage{\CurrentOption}{iantheo}}
\DeclareOption{section_in_all}{\sectionsineqtrue\sectionsinfigtrue\PassOptionsToPackage{section_in_theo}{iantheo}}
\DeclareOption{subsection_in_eq}{\subsectionsineqtrue}
\DeclareOption{subsection_in_fig}{\subsectionsinfigtrue}
\DeclareOption{subsection_in_theo}{\PassOptionsToPackage{\CurrentOption}{iantheo}}
\DeclareOption{subsection_in_all}{\subsectionsineqtrue\subsectionsinfigtrue\PassOptionsToPackage{subsection_in_theo}{iantheo}}
\DeclareOption{no_section_in_eq}{\sectionsineqfalse}
\DeclareOption{no_section_in_fig}{\sectionsinfigfalse}
\DeclareOption{no_section_in_theo}{\PassOptionsToPackage{\CurrentOption}{iantheo}}
\DeclareOption{no_section_in_all}{\sectionsineqfalse\sectionsinfigfalse\PassOptionsToPackage{no_section_in_theo}{iantheo}}
\DeclareOption{no_subsection_in_eq}{\subsectionsineqfalse}
\DeclareOption{no_subsection_in_fig}{\subsectionsinfigfalse}
\DeclareOption{no_subsection_in_theo}{\PassOptionsToPackage{\CurrentOption}{iantheo}}
\DeclareOption{no_subsection_in_all}{\subsectionsineqfalse\subsectionsinfigfalse\PassOptionsToPackage{no_subsection_in_theo}{iantheo}}
% reset point
\DeclareOption{point_reset_at_section}{\PassOptionsToPackage{reset_at_section}{point}}
\DeclareOption{point_no_reset_at_section}{\PassOptionsToPackage{no_reset_at_section}{point}}
\DeclareOption{point_reset_at_theo}{\PassOptionsToPackage{reset_at_theo}{point}}
\DeclareOption{point_no_reset_at_theo}{\PassOptionsToPackage{no_reset_at_theo}{point}}

\def\ian@defaultoptions{
  \ExecuteOptions{section_in_all, no_subsection_in_all}
  \ProcessOptions

  %% required packages
  \RequirePackage{iantheo}
  \RequirePackage{point}
  \RequirePackage{color}
  \RequirePackage{marginnote}
  \RequirePackage{amssymb}
  \PassOptionsToPackage{hidelinks}{hyperref}
  \RequirePackage{hyperref}
}

%% paper dimensions
\setlength\paperheight{297mm}
\setlength\paperwidth{210mm}

%% fonts
\input{size11.clo}
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}

%% text dimensions
\hoffset=-50pt
\voffset=-72pt
\textwidth=460pt
\textheight=704pt


%% remove default indentation
\parindent=0pt
%% indent command
\def\indent{\hskip20pt}

%% something is wrong with \thepage, redefine it
\gdef\thepage{\the\c@page}

%% array lines (to use the array environment)
\setlength\arraycolsep{5\p@}
\setlength\arrayrulewidth{.4\p@}


%% correct vertical alignment at the end of a document
\AtEndDocument{
  \vfill
  \eject
}


%% 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}}%
}

%% can call commands even when they are not defined
\def\safe#1{%
  \ifdefined#1%
    #1%
  \else%
    {\color{red}\bf?}%
  \fi%
}

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

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


%% make a custom link at any given location in the document
\def\makelink#1#2{%
  \hrefanchor%
  \outdef{label@#1}{#2}%
}


%% section command
% counter
\newcounter{sectioncount}
% space before section
\newlength\secskip
\setlength\secskip{40pt}
% a prefix to put before the section number, e.g. A for appendices
\def\sectionprefix{}
% define some lengths
\newlength\secnumwidth
\newlength\sectitlewidth
\def\section#1{
  % reset counters
  \stepcounter{sectioncount}
  \setcounter{subsectioncount}{0}
  \ifsectionsineq
    \setcounter{seqcount}0
  \fi
  \ifsectionsinfig
    \setcounter{figcount}0
  \fi

  % space before section (if not first)
  \ifnum\thesectioncount>1
    \vskip\secskip
    \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

  %space
  \par\penalty10000
  \bigskip\penalty10000
}

%% subsection
% counter
\newcounter{subsectioncount}
% space before subsection
\newlength\subsecskip
\setlength\subsecskip{30pt}
\def\subsection#1{
  % counters
  \stepcounter{subsectioncount}
  \setcounter{subsubsectioncount}{0}
  \ifsubsectionsineq
    \setcounter{seqcount}0
  \fi
  \ifsubsectionsinfig
    \setcounter{figcount}0
  \fi

  % space before subsection (if not first)
  \ifnum\thesubsectioncount>1
    \vskip\subsecskip
    \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

  % space
  \par\penalty10000
  \medskip\penalty10000
}

%% subsubsection
% counter
\newcounter{subsubsectioncount}
% space before subsubsection
\newlength\subsubsecskip
\setlength\subsubsecskip{20pt}
\def\subsubsection#1{
  % counters
  \stepcounter{subsubsectioncount}

  % space before subsubsection (if not first)
  \ifnum\thesubsubsectioncount>1
    \vskip\subsubsecskip
    \penalty-500
  \fi

  % hyperref anchor
  \hrefanchor
  % define tag (for \label)
  \xdef\tag{\sectionprefix\thesectioncount.\thesubsectioncount.\thesubsubsectioncount}

  % get widths
  \def\@secnum{{\bf\hskip1.cm\sectionprefix\thesectioncount.\thesubsectioncount.\thesubsubsectioncount.\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@subsubsec.\thesectioncount.\thesubsectioncount.\thesubsubsectioncount\endcsname{\thelncount}}
    \write\tocoutput{\noexpand\tocsubsubsection{#1}{\thepage}}
  \fi

  % space
  \par\penalty10000
  \medskip\penalty10000
}

%% itemize
\newlength\itemizeskip
% left margin for items
\setlength\itemizeskip{20pt}
\newlength\itemizeseparator
% space between the item symbol and the text
\setlength\itemizeseparator{5pt}
% penalty preceding an itemize
\newcount\itemizepenalty
\itemizepenalty=0
% counter counting the itemize level
\newcounter{itemizecount}

% item symbol
\def\itemizept#1{
  \ifnum#1=1
    \textbullet
  \else
    $\scriptstyle\blacktriangleright$
  \fi
}


\newlength\current@itemizeskip
\setlength\current@itemizeskip{0pt}
\def\itemize{%
  \par\expandafter\penalty\the\itemizepenalty\medskip\expandafter\penalty\the\itemizepenalty%
  \addtocounter{itemizecount}{1}%
  \addtolength\current@itemizeskip{\itemizeskip}%
  \leftskip\current@itemizeskip%
}
\def\enditemize{%
  \addtocounter{itemizecount}{-1}%
  \addtolength\current@itemizeskip{-\itemizeskip}%
  \par\expandafter\penalty\the\itemizepenalty\leftskip\current@itemizeskip%
  \medskip\expandafter\penalty\the\itemizepenalty%
}
\newlength\itempt@total
\def\item{
  \settowidth\itempt@total{\itemizept\theitemizecount}
  \addtolength\itempt@total{\itemizeseparator}
  \par
  \medskip
  \hskip-\itempt@total\itemizept\theitemizecount\hskip\itemizeseparator
}


%% prevent page breaks after itemize
\newcount\previtemizepenalty
\def\nopagebreakafteritemize{
  \previtemizepenalty=\itemizepenalty
  \itemizepenalty=10000
}
%% back to previous value
\def\restorepagebreakafteritemize{
  \itemizepenalty=\previtemizepenalty
}

%% enumerate
\newcounter{enumerate@count}
\def\enumerate{
  \setcounter{enumerate@count}0
  \let\olditem\item
  \let\olditemizept\itemizept
  \def\item{
    % counter
    \stepcounter{enumerate@count}
    % set header
    \def\itemizept{\theenumerate@count.}
    % hyperref anchor
    \hrefanchor
    % define tag (for \label)
    \xdef\tag{\theenumerate@count}
    \olditem
  }
  \itemize
}
\def\endenumerate{
  \enditemize
  \let\item\olditem
  \let\itemizept\olditemizept
}


%% equation numbering
% counter
\newcounter{seqcount}
% booleans (write section or subsection in equation number)
\newif\ifsectionsineq
\newif\ifsubsectionsineq
\def\seqcount{
  \stepcounter{seqcount}
  % the output
  \edef\seqformat{\theseqcount}
  % add subsection number
  \ifsubsectionsineq
    \let\tmp\seqformat
    \edef\seqformat{\thesubsectioncount.\tmp}
  \fi
  % add section number
  \ifsectionsineq
    \let\tmp\seqformat
    \edef\seqformat{\sectionprefix\thesectioncount.\tmp}
  \fi
  % define tag (for \label)
  \xdef\tag{\seqformat}
  % write number
  \marginnote{\hfill(\seqformat)}
}
%% equation environment compatibility
\def\equation{\hrefanchor$$\seqcount}
\def\endequation{$$\@ignoretrue}


%% figures
% counter
\newcounter{figcount}
% booleans (write section or subsection in equation number)
\newif\ifsectionsinfig
\newif\ifsubsectionsinfig
% width of figures
\newlength\figwidth
\setlength\figwidth\textwidth
\addtolength\figwidth{-2.5cm}
% caption
\def\defcaption{
  \long\def\caption##1{
    \stepcounter{figcount}

    % hyperref anchor
    \hrefanchor

    % the number of the figure
    \edef\figformat{\thefigcount}
    % add subsection number
    \ifsubsectionsinfig
      \let\tmp\figformat
      \edef\figformat{\thesubsectioncount.\tmp}
    \fi
    % add section number
    \ifsectionsinfig
      \let\tmp\figformat
      \edef\figformat{\sectionprefix\thesectioncount.\tmp}
    \fi

    % define tag (for \label)
    \xdef\tag{\figformat}

    % write
    \hfil fig \figformat: \parbox[t]{\figwidth}{\leavevmode\small##1}

    % space
    \par\bigskip
  }
}
%% short caption: centered
\def\captionshort#1{
  \stepcounter{figcount}

  % hyperref anchor
  \hrefanchor

  % the number of the figure
  \edef\figformat{\thefigcount}
  % add section number
  \ifsectionsinfig
  \let\tmp\figformat
  \edef\figformat{\sectionprefix\thesectioncount.\tmp}
  \fi

  % define tag (for \label)
  \xdef\tag{\figformat}

  % write
  \hfil fig \figformat: {\small#1}

  %space
  \par\bigskip
}

%% environment
\def\figure{
  \par
  \vfil\penalty100\vfilneg
  \bigskip
}
\def\endfigure{
  \par
  \vfil\penalty100\vfilneg
  \bigskip
}


%% 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}
}


%% bibliography
% size of header
\newlength\bibheader
\def\thebibliography#1{
  \hrefanchor

  % 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

  % write
  {\bf \LARGE References}\par\penalty10000\bigskip\penalty10000
  % width of header
  \settowidth\bibheader{[#1]}
  \leftskip\bibheader
}
% end environment
\def\endthebibliography{
  \par\leftskip0pt
} 

%% bibitem command
\def\bibitem[#1]#2{%
  \hrefanchor%
  \outdef{label@cite#2}{#1}%
  \hskip-\bibheader%
  \makebox[\bibheader]{\cite{#2}\hfill}%
}

%% cite command (adapted from latex.ltx)
% @tempswa is set to true when there is an optional argument
\newif\@tempswa
\def\cite{%
  % check whether there is an optional argument (if there is none, add on empty '[]')
  \@ifnextchar [{\@tempswatrue\@citex}{\@tempswafalse\@citex[]}%
}
% command with optional argument
\def\@citex[#1]#2{\leavevmode%
  % initialize loop
  \let\@citea\@empty%
  % format
  \@cite{%
    % loop over ',' separated list
    \@for\@citeb:=#2\do{%
      % text to add at each iteration of the loop (separator between citations)
      \@citea\def\@citea{,\ }%
      % add entry to citelist
      \@writecitation{\@citeb}%
      \ref{cite\@citeb}%
    }%
  }%
  % add optional argument text (as an argument to '\@cite')
  {#1}%
}
\def\@cite#1#2{%
  [#1\if@tempswa , #2\fi]%
}
%% add entry to citelist after checking it has not already been added
\def\@writecitation#1{%
  \ifcsname if#1cited\endcsname%
  \else%
    \expandafter\newif\csname if#1cited\endcsname%
    \immediate\write\@auxout{\string\citation{#1}}%
  \fi%
}

%% table of contents
% boolean
\newif\iftoc
\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
\newcounter{tocsectioncount}
\def\tocsection #1#2{
  \stepcounter{tocsectioncount}
  \setcounter{tocsubsectioncount}{0}
  \setcounter{tocsubsubsectioncount}{0}
  % write
  \smallskip\hyperlink{ln.\csname toc@sec.\thetocsectioncount\endcsname}{{\bf \tocsectionprefix\thetocsectioncount}.\hskip5pt {\color{blue}#1}\leaderfill#2}\par
}
\newcounter{tocsubsectioncount}
\def\tocsubsection #1#2{
  \stepcounter{tocsubsectioncount}
  \setcounter{tocsubsubsectioncount}{0}
  % write
  {\hskip10pt\hyperlink{ln.\csname toc@subsec.\thetocsectioncount.\thetocsubsectioncount\endcsname}{{\bf \thetocsubsectioncount}.\hskip5pt {\color{blue}\small #1}\leaderfill#2}}\par
}
\newcounter{tocsubsubsectioncount}
\def\tocsubsubsection #1#2{
  \stepcounter{tocsubsubsectioncount}
  % write
  {\hskip20pt\hyperlink{ln.\csname toc@subsubsec.\thetocsectioncount.\thetocsubsectioncount.\thetocsubsubsectioncount\endcsname}{{\bf \thetocsubsubsectioncount}.\hskip5pt {\color{blue}\small #1}\leaderfill#2}}\par
}
\def\tocappendices{
  \medskip
  \setcounter{tocsectioncount}0
  {\bf Appendices}\par
  \smallskip
  \def\tocsectionprefix{A}
}
\def\tocreferences#1{
  \medskip
  {\hyperlink{ln.\csname toc@references\endcsname}{{\color{blue}\bf References}\leaderfill#1}}\par
  \smallskip
}


%% definitions that must be loaded at begin document
\let\ian@olddocument\document
\def\document{
  \ian@olddocument

  \deflabel
  \defcaption
}

%% end
\ian@defaultoptions
\endinput