-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbapc.cls
517 lines (473 loc) · 15.4 KB
/
bapc.cls
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
%-------------------------------------------------------------------------------
% This is the file bapc.cls.
%
% It is a copy of the file bapc2016.cls, with only the file name changed and
% this line added.
%
% It provides a workable environment for typesetting ICPC-style programming
% contests. The Benelux Algorithm Programming Contest (BAPC) is a local
% preliminary contest, even before the regionals for Northwestern Europe.
%
% The entire class is based on the memoir class. Every option is immediately
% passed to memoir. The BAPC class doesn't provide any additional options.
%
% Authors: Josse van Dobben de Bruyn, Joris van Rantwijk, Ragnar Groot Koerkamp
%-------------------------------------------------------------------------------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{bapc}
\providecommand{\lang}{en}% fallback definition, should be defined as -usepretex to latexmk
\input{lang/\lang.tex}
%\RequirePackage{frcursive}
%-------------------------------------------------------------------------------
% ThisIsNotABlankPage: clears to an odd page. If a blank page is created, then
% it is decorated with the text "This is not a blank page".
%-------------------------------------------------------------------------------
\newcommand{\ThisIsNotABlankPage}{
\cleartooddpage[
\thispagestyle{empty}
\vfill
\begin{center}
\huge{%
\langblank{}%
}
%\includegraphics{images/blank-page-fr.png}
\end{center}
\vspace*{5.55cm} % slightly above vertical centre.
\vfill
]
}
\DeclareOption{web}{
\renewcommand{\ThisIsNotABlankPage}{\clearpage}
}
% Passes any class options to the underlying memoir class.
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{memoir}}
\ProcessOptions
% Load LaTeX's memoir class.
% (Joris: increase font size)
\LoadClass[a4paper,11pt,svgnames]{memoir}
% (Joris: increase line spacing)
\linespread{1.1}
% (Joris: add space between paragraphs)
\setlength{\parindent}{0pt}
\setlength{\medskipamount}{0pt} % Prevent spaces before/after lstlisting.
\nonzeroparskip
% Require some packages.
\RequirePackage{microtype}
\RequirePackage{eqparbox}
\RequirePackage{tabularx}
\RequirePackage{environ}
\RequirePackage{etoolbox}
\RequirePackage{float}
\RequirePackage{listingsutf8}
\RequirePackage{upquote}
\RequirePackage{tocloft}
\RequirePackage{xparse}
\RequirePackage{siunitx}
\sisetup{per-mode=symbol}
\RequirePackage[hidelinks,bookmarks=true,pdfusetitle]{hyperref}
\newcommand{\todo}[1]{{\color{red}[#1]}}
\newcommand{\timelimit}{\langtimelimitmissing{}}
\newcommand{\problemlabel}{} % Empty to hide activity chart
\newcommand{\problemyamlname}{\langproblemname{}}
\newcommand{\problemauthor}{\langproblemauthor{}}
\newcommand{\fullproblemtitle}{\problemlabel: \problemyamlname}
%-------------------------------------------------------------------------------
% Sectioning commands and list of problems.
%
% Creating a new list for the problems (instead of using the tableofcontents)
% turned out to be a lot easier in terms of custom formatting.
%-------------------------------------------------------------------------------
\renewcommand{\thesection}{\problemlabel}
\newcommand{\listofproblemsname}{\langproblems{}}
\newlistof{listofproblems}{lop}{\listofproblemsname}
\newlistentry{problem}{lop}{0}
\newcounter{SampleCount}
\newcounter{NextSample}
\renewcommand{\printloptitle}[1]{
\hfill
\sffamily
\Large
\eqmakebox[letter][c]{}
\quad
\eqmakebox[titel][l]{\huge\textbf{#1}}
\hfill
\vspace*{-1cm}
}
\renewcommand{\afterloptitle}{\thispagestyle{empty}\afterchaptertitle}
\setlength{\cftparskip}{0.45em}
\cftpagenumbersoff{section}
\renewcommand{\cftsectionleader}{}
\newcommand{\problemname}[1]{
\ThisIsNotABlankPage
\ifblank{#1}{
\section{\problemyamlname}
}{
\section{#1}
}
\vspace{-2.3em}
\hfill
\ifdefempty{\timelimit}{}{{\color{darkgray}\fontfamily{qcr}\langtimelimit{}: \timelimit{}s}}
\setcounter{SampleCount}{0}
\setcounter{NextSample}{1}
\setcounter{figure}{0}
\rmfamily
% Formatting the list of problems on the title page:
\cftaddtitleline{lop}{section}{
\vspace{.4pt}
\hfill
\sffamily
\Large
\eqmakebox[letter][c]{\thesection}
\quad
\ifblank{#1}{%
\eqmakebox[titel][l]{\problemyamlname}%
}{%
\eqmakebox[titel][l]{#1}%
}%
\hfill
}{}
}
%-------------------------------------------------------------------------------
% Setting headings.
%-------------------------------------------------------------------------------
\copypagestyle{bapc}{headings}
\makepsmarks{bapc}{
\createmark{section}{both}{shownumber}{\langproblem{} }{: }
}
\pagestyle{bapc}
\nouppercaseheads
%-------------------------------------------------------------------------------
% Environments for specifying Input, Output and Interaction
%-------------------------------------------------------------------------------
\newenvironment{Input}{
\subsection*{\langinput{}}
}{\par}
\newenvironment{Output}{
\subsection*{\langoutput{}}
}{\par}
\newenvironment{Interaction}{
\subsection*{\langinteraction{}}
}{\par}
\newenvironment{Explanation}{
\subsection*{\langexplanation{}}
}{\par}
%-------------------------------------------------------------------------------
% Environment for specifying Samples.
%
% In 2016 the BAPC jury will provide only one test case per file, instead of
% multiple test cases (as is customary at the BAPC). This calls for a different
% layout, and therefore a complete rewrite of parts of the LaTeX code. The
% following code was written specifically for BAPC 2016.
%
% We want to create an environment based upon the tabularx environment.
% Unfortunately, this is not so easy, as the code for the tabularx environment
% contains some strange hacks that are documented reasonably well.
%
% For more information, please refer to http://tex.stackexchange.com/a/42331 .
% It is worth mentioning that this is only part of the story. The documentation
% of the tabularx package reveals that this workaround only works if
% \endtabularx is the first token of the `end code' of the environment.
% However, we want to have a \hline before that, so this code is no good.
%
% A solution to this problem was found on http://tex.stackexchange.com/a/111488 .
%-------------------------------------------------------------------------------
\newcommand{\mySampleHeading}[1]{
\multicolumn{1}{l}{\large \bfseries\textrm{#1 \arabic{SampleCount}}}
}
\newcommand{\SampleListing}[1]{
\lstinputlisting[aboveskip=-0.7\baselineskip,belowskip=-0.9\baselineskip,inputencoding=utf8/latin1,basicstyle=\ttfamily]{#1}
}
\newcommand{\InteractiveSampleListing}[1]{
\lstinputlisting[aboveskip=-1.0\baselineskip,belowskip=-1\baselineskip,inputencoding=utf8/latin1,basicstyle=\ttfamily]{#1}
}
\newcommand{\SideBySideSample}[2]{
\par\bigskip\noindent%
\normalsize%
\stepcounter{SampleCount}%
\renewcommand\baselinestretch{1}\selectfont% <-- combining various lengths in order
\setlength{\extrarowheight}{2.5pt}% to set the top and bottom padding; see
\begin{tabularx}{\textwidth}{|X|X|}% http://tex.stackexchange.com/a/31704
\mySampleHeading{\langinputsample{}} & \mySampleHeading{\langoutputsample{}} \\
\hline
\SampleListing{#1}
&
\SampleListing{#2}
\\
\hline
\end{tabularx}%
\rmfamily
}
\newcommand{\FullWidthSample}[2]{
\par\bigskip\noindent%
\normalsize%
\stepcounter{SampleCount}%
\renewcommand\baselinestretch{1}\selectfont% <-- combining various lengths in order
\setlength{\extrarowheight}{2.5pt}% to set the top and bottom padding; see
\begin{tabularx}{\textwidth}{|X|}% http://tex.stackexchange.com/a/31704
\mySampleHeading{\langinput{}} \\
\hline
\SampleListing{#1} \\
\hline
\end{tabularx}%
\nopagebreak
\par
\noindent
\begin{tabularx}{\textwidth}{|X|}%
\mySampleHeading{\langoutput{}} \\
\hline
\SampleListing{#2} \\
\hline
\end{tabularx}%
\rmfamily
}
\newcommand{\SideBySideSampleNoHeading}[2]{
\normalsize%
\renewcommand\baselinestretch{1}\selectfont% <-- combining various lengths in order
\setlength{\extrarowheight}{2.5pt}% to set the top and bottom padding; see
\begin{tabularx}{\textwidth}{|X|X|}% http://tex.stackexchange.com/a/31704
\hline
\SampleListing{#1}
&
\SampleListing{#2}
\\
\hline
\end{tabularx}%
\rmfamily
}
\newcommand{\FullWidthSampleNoHeading}[2]{
\normalsize%
\renewcommand\baselinestretch{1}\selectfont% <-- combining various lengths in order
\setlength{\extrarowheight}{2.5pt}% to set the top and bottom padding; see
\begin{tabularx}{\textwidth}{|X|}% http://tex.stackexchange.com/a/31704
\hline
\SampleListing{#1} \\
\hline
\end{tabularx}%
\nopagebreak
\par
\noindent
\begin{tabularx}{\textwidth}{|X|}%
\hline
\SampleListing{#2} \\
\hline
\end{tabularx}%
\rmfamily
}
\newlength{\PS@idealwidth}
\setlength{\PS@idealwidth}{0.5\textwidth}
\newsavebox{\PS@inputbox}
\newsavebox{\PS@outputbox}
\newlength{\PS@inputwidth}
\newlength{\PS@outputwidth}
\newcommand{\Sample}[2]{
\savebox{\PS@inputbox}{\SampleListing{#1}}
\savebox{\PS@outputbox}{\SampleListing{#2}}
\settowidth{\PS@inputwidth}{\usebox{\PS@inputbox}}
\settowidth{\PS@outputwidth}{\usebox{\PS@outputbox}}
% Check if too wide for side-by-side
\ifdim\PS@inputwidth<\PS@idealwidth
\ifdim\PS@outputwidth<\PS@idealwidth
% If both input and output are small enough, print side-by-side.
\SideBySideSample{#1}{#2}
\else
% If output width is too large, print full-width.
\FullWidthSample{#1}{#2}
\fi
\else
% If input width is too large, print full-width.
\FullWidthSample{#1}{#2}
\fi
}
\newcommand{\SampleNoHeading}[2]{
\savebox{\PS@inputbox}{\SampleListing{#1}}
\savebox{\PS@outputbox}{\SampleListing{#2}}
\settowidth{\PS@inputwidth}{\usebox{\PS@inputbox}}
\settowidth{\PS@outputwidth}{\usebox{\PS@outputbox}}
% Check if too wide for side-by-side
\ifdim\PS@inputwidth<\PS@idealwidth
\ifdim\PS@outputwidth<\PS@idealwidth
% If both input and output are small enough, print side-by-side.
\SideBySideSampleNoHeading{#1}{#2}
\else
% If output width is too large, print full-width.
\FullWidthSampleNoHeading{#1}{#2}
\fi
\else
% If input width is too large, print full-width.
\FullWidthSampleNoHeading{#1}{#2}
\fi
}
\newcommand{\MultipassSampleHeading}{
\stepcounter{SampleCount}
\par%
\begin{tabularx}{0.983\textwidth}{X}%
\centering \large\bfseries\textrm{\langsamplecase{} \arabic{SampleCount}}%
\end{tabularx}
\par%
\nopagebreak[4]%
}
\newcommand{\SamplePass}[3]{%
\begin{samepage}%
\begin{tabularx}{0.983\textwidth}{XXX}%
\large\bfseries\textrm{\langinput{}} \hfill%
& %
\centering \large\bfseries\textrm{\langpass{} #1}%
& %
\hfill \large\bfseries\textrm{\langoutput{}}\\%
\end{tabularx}
\\%
\SampleNoHeading{#2}{#3}%
\end{samepage}%
}
\newcommand{\InteractiveSampleHeading}{
\par\bigskip\noindent%
\normalsize%
\stepcounter{SampleCount}%
\begin{tabularx}{0.983\textwidth}{XXX}%
\large\bfseries\textrm{\langread{}} \hfill%
& %
\centering \large\bfseries\textrm{\langsampleinteraction{} \arabic{SampleCount}}%
& %
\hfill \large\bfseries\textrm{\langwrite{}}\\%
\end{tabularx}
\nopagebreak
\vspace{-1.0em}
\par
}
\newcommand{\InteractiveWrite}[1]{
\noindent
\normalsize
\ttfamily
\frenchspacing% to prevent extra spaces after punctuation. https://tex.stackexchange.com/q/118455/43242
\hfill\framebox[0.55\textwidth][l]{%
\parbox[t]{\dimexpr0.55\textwidth-2\fboxsep-2\fboxrule\relax}{
\vspace{-.4em}%
\strut%
\InteractiveSampleListing{#1}
\vspace{-.4em}%
\strut%
}
}
\nopagebreak
\vspace{-0.4em}
\par
}
\newcommand{\InteractiveRead}[1]{
\noindent
\normalsize
\ttfamily
\frenchspacing% to prevent extra spaces after punctuation. https://tex.stackexchange.com/q/118455/43242
\framebox[0.55\textwidth][l]{%
\parbox[t]{\dimexpr0.55\textwidth-2\fboxsep-2\fboxrule\relax}{
\vspace{-.4em}%
\strut%
\InteractiveSampleListing{#1}
\vspace{-.4em}%
\strut%
}
}
\nopagebreak
\vspace{-0.4em}
\par%
}
\newcommand{\InteractivePass}[1]{
\par\bgroup\bigskip\noindent%
\centering\large\bfseries\textrm{\langpass{} #1}
\nopagebreak
\vspace{-1.0em}
\par\egroup
}
%-------------------------------------------------------------------------------
% Command to automatically include samples in order.
% The tooling has to define the commands \Sample1{},...\Sample<n>{}
%-------------------------------------------------------------------------------
\newcommand{\nextsample}{%
\expandafter\csname Sample\theNextSample\endcsname%
\expandafter\let\csname Sample\theNextSample\endcsname\undefined%
\stepcounter{NextSample}%
}
\newcommand{\remainingsamples}{%
\ifcsname Sample\theNextSample\endcsname%
\nextsample%
\remainingsamples%
\fi%
}
%-------------------------------------------------------------------------------
% The following are required for the overall layout:
%-------------------------------------------------------------------------------
\let\sffamilyFB\sffamily% Prevent error if babel fr loads \sffamilyFB in cache
\let\ttfamilyFB\ttfamily
\let\rmfamilyFB\rmfamily
\usepackage[\langbabel]{babel}
\usepackage[none]{hyphenat} % Disable hyphenation with language [none]
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{courier}
\usepackage[T1]{fontenc} % Standard
\usepackage[utf8]{inputenc} % UTF-8 support
% https://tex.stackexchange.com/questions/270557/undefined-control-sequence-on-onehalfspacing
\DisemulatePackage{setspace}
\usepackage{setspace}
%-------------------------------------------------------------------------------
% The following are required for most problems:
%-------------------------------------------------------------------------------
\usepackage{amsmath,amssymb}
\usepackage{wrapfig}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\usetikzlibrary{backgrounds}
\usetikzlibrary{patterns}
\usetikzlibrary{positioning}
\usetikzlibrary{scopes}
\usetikzlibrary{shapes.geometric}
\usepackage{enumitem} % [noitemsep] for smaller lists
\usepackage{textcomp} % textquotesingle: '
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
%-------------------------------------------------------------------------------
% Set margins (using commands from memoir.cls).
%-------------------------------------------------------------------------------
\setlrmarginsandblock{27mm}{27mm}{*} % left and right margins
\setulmarginsandblock{*}{40mm}{0.8} % upper and lower margins
\checkandfixthelayout
%-------------------------------------------------------------------------------
% Change figure numbering.
%
% Taken from http://tex.stackexchange.com/a/116820 .
%-------------------------------------------------------------------------------
\makeatletter
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\@addtoreset{figure}{section} % Added from https://tex.stackexchange.com/a/45931:
\@addtoreset{table}{section} % Makes sure that hyperlinks go to correct problem
\renewcommand\@memfront@floats{}
\renewcommand\@memmain@floats{}
\renewcommand\@memback@floats{}
\makeatletter
\newcommand{\illustration}[3]{
\begin{wrapfigure}{r}{#1\textwidth}
\vspace{-10pt}
\includegraphics[width=#1\textwidth]{#2}
\ifstrempty{#3}{
\vspace{-25pt}
}{
\begin{flushright}
\vspace{-9pt}
\tiny #3
\end{flushright}
\vspace{-15pt}
}
\end{wrapfigure}
%\par
%\noindent
}
%% Number figures as A.1 A.2... B.1 B.2...
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
%-------------------------------------------------------------------------------
% Reduce font size of figure captions.
%-------------------------------------------------------------------------------
\captionnamefont{\small}
\captiontitlefont{\small}
\endinput