-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththeatre.cls
executable file
·596 lines (475 loc) · 15.7 KB
/
theatre.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
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
\ProvidesClass{theatre}[2015/10/03 v0.55 Script Format for stage plays]
\NeedsTeXFormat{LaTeX2e}
\LoadClass[12pt, oneside, a4paper, openright]{book}
%\@ifundefined{if@openright}{\newif\if@openright}{}
%\RequirePackage{cm-super} % for vectorized fonts
\RequirePackage[T1]{fontenc} % for bold small caps
\RequirePackage{etoolbox, environ} % for dynamic list of chars in each scene
\RequirePackage{xparse}
%\RequirePackage{fancyhdr}
%\RequirePackage{extramarks}
\RequirePackage{xspace} % add space after macro when appropriate
%\RequirePackage{tikz}
\RequirePackage{nameref}
%%%%%%%%%%%%%%%%%%%%%%% Options
\IfFileExists{silence.sty}{
\RequirePackage{silence}
\typeout{^^J^^J
SUPPRESSING ALL "MULTIPLY-DEFINED" WARNINGS
^^J^^J}
\WarningFilter{latex}{There were multiply-defined labels}
\WarningFilter{latex}{Label `act}
}{
\ClassWarningNoLine{theatre}{%
Large number of warnings incoming! \MessageBreak
To suppress warnings, use the 'silence'\MessageBreak
package%
}
}
\ProcessOptions\relax % ignore all options
% if mirror flag, turn all drawings upside down
% if drawing flag, turn off/on drawings and tikz dependency (remember the group chars brace!)
%%%%%%%%%%%%%%%%%%%%%%% Names (english)
\newcommand{\casttitlename}{Cast of Characters}
\newcommand{\acttitlename}{Act}
\newcommand{\scenetitlename}{Scene}
\newcommand{\scriptendlocalizedtext}{The End}
\newcommand{\draftlocalizedtext}{DRAFT}
\newcommand{\versionlocalizedtext}{VERSION}
%%%%%%%%%%%%%%%%%%%%%%% Names (multi-lang)
\AtBeginDocument{
\@ifpackagewith{babel}{english}{%
\addto\captionsitalian{%
\renewcommand*\casttitlename{Cast of Characters}%
\renewcommand*\acttitlename{Act}%
\renewcommand*\scenetitlename{Scene}%
\renewcommand*\scriptendlocalizedtext{The End}%
\renewcommand*\draftlocalizedtext{DRAFT}%
\renewcommand*\versionlocalizedtext{VERSION}%
}%
}{}
\@ifpackagewith{babel}{italian}{%
\addto\captionsitalian{%
\renewcommand*\casttitlename{Personaggi}%
\renewcommand*\acttitlename{Atto}%
\renewcommand*\scenetitlename{Scena}%
\renewcommand*\scriptendlocalizedtext{Fine}%
\renewcommand*\draftlocalizedtext{BOZZA}%
\renewcommand*\versionlocalizedtext{VERSION}%
}%
}{}
}
%%%%%%%%%%%%%%%%%%%%%%% Font styles
\parindent 0pt
\newcommand{\namefont}{\scshape}
\newcommand{\starfont}{\bf\namefont\large}
\newcommand{\actionfont}{\it}
\newcommand{\stagedirfont}{}
\newcommand{\titlestarfont}{\starfont\Huge}
\newcommand{\casttitlefont}{\scshape\Large}
\newcommand{\castfont}{\namefont}
\newcommand{\caststarfont}{\starfont\large}
\newcommand{\acttitlefont}{\scshape\Large}
\newcommand{\scenetitlefont}{\scshape\large}
\newcommand{\scenecastfont}{\namefont\small}
%%%%%%%%%%%%%%%%%%%%%%% Counters
\newcounter{castlistcounter}
\newcounter{totalcharcounter}
\newcounter{actcounter}
\newcounter{scenecounter}[actcounter]
\newcounter{entrancecounter}[scenecounter]
\newcounter{grouptemp}
\newcounter{casttemp}
\newcounter{charstemp}
%%%%%%%%%%%%%%%%%%%%%%% Flags
\newif\if@atleastonechar
\newif\if@thischarstar % checks if the current character is starred
%%%%%%%%%%%%%%%%%%%%%%% Temp files
\newwrite\titlecast
\immediate\openout\titlecast=\jobname-titlecast.tmp
%%%%%%%%%%%%%%%%%%%%%%% Title
% convert to internal functions
\newcommand{\draft}[1]{ \gdef\@draftno{#1}} % draft number
\newcommand{\version}[1]{ \gdef\@versionno{#1}} % version number (same as draft number)
\newcommand{\copyrightnotice}[1]{ \gdef\@crightnotice{#1}} % copyright
\newcommand{\address}[1]{ \gdef\@address{#1}} % physical address
\newcommand{\telephone}[1]{ \gdef\@telephone{#1}} % telephone number
\newcommand{\email}[1]{ \gdef\@email{#1}} % email address
% create title page
\renewcommand{\maketitle}{
\begin{titlepage}
\vspace*{\fill}
\center{\Huge \textsc{\@title}}
\par
\center{\Large \@author}
\par\vspace{1cm}
\ifdefined\@draftno{\small \MakeUppercase\draftlocalizedtext\ \@draftno}\fi%
\ifdefined\@versionno{\small \MakeUppercase\versionlocalizedtext\ \@versionno}\fi%
\vfill
\immediate\closeout\titlecast
{\titlestarfont\input{\jobname-titlecast.tmp}}
\vfill
\begin{flushright}
\ifdefined\@crightnotice{\copyright\ \@crightnotice\par}\fi
\ifdefined\@address{\@address\par}\fi
\ifdefined\@telephone{\@telephone\par}\fi
\ifdefined\@email{\@email}\fi
\end{flushright}
\end{titlepage}
}
%%%%%%%%%%%%%%%%%%%%%%% Characters
% \character[Timothy Williams][a young boy]{Timothy}{tim}
% \character[a young boy]{Timothy}{tim}
% \character{Timothy}{tim}
\NewDocumentCommand{\character}{s}{%
\IfBooleanTF{#1} % if starred, use special fonts
{\@thischarstartrue}
{\@thischarstarfalse}
\@ifnextchar[
{\char@cast} % has description, add to cast list
{\char@simplemacros} % no description, just create macros
}
\def\char@cast[#1]{
\@ifnextchar[
{\char@castfull{#1}}
{\char@castfull{}[#1]} % add empty [full name] if absent
}
\def\char@castfull#1[#2]#3#4{
\stepcounter{castlistcounter}
\stepcounter{totalcharcounter}
\if@thischarstar{ % add character to title page
\immediate\write\titlecast{#3\par}
}\fi
% use script name if full name is empty
\if\relax\detokenize{#1}\relax
\if@thischarstar{
\csgdef{persona@\Roman{castlistcounter}}{\caststarfont#3}
}\else{
\csgdef{persona@\Roman{castlistcounter}}{\castfont#3}
}\fi
\else
\if@thischarstar{
\csgdef{persona@\Roman{castlistcounter}}{\caststarfont#1}
}\else{
\csgdef{persona@\Roman{castlistcounter}}{\castfont#1}
}\fi
\fi
\@namedef{description@\Roman{castlistcounter}}{#2}
% first expand the totalcharcounter, then pass it as argument
\edef\@Romanchar{\Roman{totalcharcounter}}
\expandafter\char@fullmacros\expandafter{\@Romanchar}{#3}{#4}
}
%%%%%%%%%%%%%%%%%%%%%%% Character macros
\newcommand{\@ction}{do} % suffix for stage directions command, ex. \timdo
\def\char@simplemacros#1#2{ % args={Timothy}{tim}
\@namedef{#2}{
\begingroup
\catcode`\^^M=\active%
\formatdialogue{\namefont#1}%
}
\@namedef{#2\@ction}{
\begingroup
\catcode`\^^M=\active%
\formataction{\namefont#1\xspace}%
}
}
\def\char@fullmacros#1#2#3{ % args={\Roman{totalcharcounter}}{Timothy}{tim}
% specifies the name for this character
\csgdef{@char#1name}{\@nameuse{@char#1font}#2}
% specifies the script font and castlist font for this character
\if@thischarstar{
\csgdef{@char#1font}{\starfont}
}\else{
\csgdef{@char#1font}{\namefont}
}\fi
% defines \tim, expanding (just) the tokens that require totalcharcounter
\csgdef{#3}{%
% if it's the first time that the macro is called in the scene, create label
\@ifundefined{r@act\Roman{actcounter}scene\Roman{scenecounter}char#1}
{\refstepcounter{entrancecounter}
\label{act\Roman{actcounter}scene\Roman{scenecounter}char#1}}
{}
\begingroup
\catcode`\^^M=\active\relax%
\catcode`\(=\active\relax%
\catcode`\)=\active\relax%
\formatdialogue{\@nameuse{@char#1font}#2}%
}
% defines \timdo, expanding (just) the tokens that require totalcharcounter
\csgdef{#3\@ction}{
% if it's the first time that the macro is called in the scene, create label
\@ifundefined{r@act\Roman{actcounter}scene\Roman{scenecounter}char#1}
{\refstepcounter{entrancecounter}
\label{act\Roman{actcounter}scene\Roman{scenecounter}char#1}}
{}
\begingroup
\catcode`\^^M=\active\relax%
\formataction{\@nameuse{@char#1font}#2\space}%
}
\settowidth{\@thischarlength}{\@nameuse{@char#1font}#2\space} % get max length to properly indent
\ifnum\@thischarlength>\maxcharlength
\global\setlength{\maxcharlength}{\@thischarlength}
\fi
}
%%%%%%%%%%%%%%%%%%%%%%% Character macros (formataction, formatdialogue)
% Dialogue formatting
\begingroup
\catcode`\^^M=\active
\long\gdef\formatdialogue#1#2^^M{
\parindent-\maxcharlength % for indenting correctly the char name
\leftskip\maxcharlength
\begin{minipage}[l]{\maxcharlength}
\raggedright % for long charnames
%\leftmargini=0pt
#1
\end{minipage}%
%
#2
\endgroup
\par
}
\endgroup
% Action formatting
\begingroup
\catcode`\^^M=\active%
\long\gdef\formataction#1^^M{
\parindent 0pt
\leftskip 0.15\textwidth
\rightskip\leftskip
{\actionfont#1}
\endgroup
\par
}
\endgroup
%%%%%%%%%%%%%%%%%%%%%%% Group characters
% \chargroup[two young boys]{
% \gcharacter[Timothy Williams]{Timothy}{tim}
% \gcharacter{Eric}{eric}
% }
\NewDocumentCommand{\gcharacter}{s}{%
\IfBooleanTF{#1} % if starred, use special font
{\global\let\@thischarfont\starfont
\@thischarstartrue}
{\global\let\@thischarfont\namefont
\@thischarstarfalse}
\@ifnextchar[
{\gchar@cast}
{\gchar@cast[]} % add empty [full name] if absent
}
\newcommand\gchar@cast[3][]{
\stepcounter{group@\Roman{castlistcounter}}
\stepcounter{totalcharcounter}
\if@thischarstar{ % add character to title page
\immediate\write\titlecast{#2\par}}
\fi
% use script name if full name is empty
\if\relax\detokenize{#1}\relax
\if@thischarstar{
\csgdef{gpersona@\Roman{castlistcounter}@\roman{group@\Roman{castlistcounter}}}{{\caststarfont#2}}
}\else{
\csgdef{gpersona@\Roman{castlistcounter}@\roman{group@\Roman{castlistcounter}}}{{\castfont#2}}
}\fi
\else
\if@thischarstar{
\csgdef{gpersona@\Roman{castlistcounter}@\roman{group@\Roman{castlistcounter}}}{{\caststarfont#1}}
}\else{
\csgdef{gpersona@\Roman{castlistcounter}@\roman{group@\Roman{castlistcounter}}}{{\castfont#1}}
}\fi
\fi
% first expand the totalcharcounter, then pass it as argument
\edef\@Romanchar{\Roman{totalcharcounter}}
\expandafter\char@fullmacros\expandafter{\@Romanchar}{{\scshape#2}}{#3}
}
\newsavebox{\tbox}
\newenvironment{chargroup}[1][]{
\stepcounter{castlistcounter} % each group counts as one character
\csgdef{description@\Roman{castlistcounter}}{#1} % description
\newcounter{group@\Roman{castlistcounter}} % count characters within the group
\csgdef{persona@\Roman{castlistcounter}}{
\begin{lrbox}{\tbox}
\begin{minipage}[c]{\castnamewidth}\raggedright
\leftmargini=0pt
\begin{list}{}{\castlistoptions}
\@recursegroup
\end{list}
\end{minipage}
\end{lrbox}
\parbox{\castnamewidth}{
\hfuzz=\wd\tbox % ignore overfull warnings
\usebox{\tbox}% % comment to avoid spurious space
$\left.\rule{0pt}{\ht\tbox}\right\}$
}% % comment to avoid spurious space
}
}{}
% recursively generate group listing
\newcommand{\@recursegroup}{
\ifnum\value{grouptemp}<\value{group@\Roman{casttemp}}
\stepcounter{grouptemp}
\item\@nameuse{gpersona@\Roman{casttemp}@\roman{grouptemp}}\strut
\@recursegroup
\fi
\setcounter{grouptemp}{0} % cleanup
}
%%%%%%%%%%%%%%%%%%%%%%% Cast list
%%%%% Parameters %%%%%
\newlength{\beforecasttitleskip} \setlength{\beforecasttitleskip}{0pt}
\newlength{\aftercasttitleskip} \setlength{\aftercasttitleskip}{1cm}
\newlength{\castpageleftmargin} \setlength{\castpageleftmargin}{1.5cm}
\newlength{\castpagerightmargin} \setlength{\castpagerightmargin}{0pt}
\newlength{\castnamewidth} \setlength{\castnamewidth}{0.33\linewidth}
\newcommand{\castlistoptions}{ \itemsep=0pt
\itemindent=0cm
\topsep=0pt
\parsep=10pt
\listparindent=0cm}
%%%%% Functions %%%%%
\newcommand{\castlist}{
\if@openright \clearpage{\thispagestyle{empty}\cleardoublepage}
\else \clearpage
\fi
\thispagestyle{empty}
\@castlist
}
\newcommand{\@castlist}{
\phantomsection % for hyperref purposes
\addcontentsline{toc}{chapter}{\casttitlename}
\castlistmark{\casttitlename} % mark for headers
\vspace*{\beforecasttitleskip} % print title
{\centering\casttitlefont\casttitlename\par}
\par\nobreak\vskip\aftercasttitleskip
\begin{list}{}{ \leftmargin=\castpageleftmargin % create list of characters
\rightmargin=\castpagerightmargin
\castlistoptions}
\@recursecast
\end{list}
}
\newcommand{\@recursecast}{ % iterate over characters
\ifnum\value{casttemp}<\value{castlistcounter}
\stepcounter{casttemp}
\item{\begin{tabular} % full name, description as a table
{p{\castnamewidth}
p{\dimexpr \linewidth-\castnamewidth-4\tabcolsep}}
\@nameuse{persona@\Roman{casttemp}}\strut
&
\@nameuse{description@\Roman{casttemp}}\strut
\end{tabular}%
}
\@recursecast
\fi
\setcounter{casttemp}{0}
}
%%%%%%%%%%%%%%%%%%%%%%% Act
%%%%% Parameters %%%%%
\newlength{\beforeactskip} \setlength{\beforeactskip}{\baselineskip}
\newlength{\afteractskip} \setlength{\afteractskip}{\baselineskip}
\newcommand{\actseparator}{:\ }
%%%%% Functions %%%%%
\newcommand{\theact}{\Roman{actcounter}}
\newcommand{\act}[1][]{
\@openact
\@act{#1}
}
\newcommand\@openact{
\if@openright \clearpage{\cleardoublepage}%\thispagestyle{empty}\cleardoublepage}
\else \clearpage
\fi
% \thispagestyle{plain} % no header
}
\newcommand\@act[1]{
\refstepcounter{actcounter} % increment number of acts
\phantomsection % for hyperref
\actmark{\acttitlename\ \theact} % mark for headers
\if\relax\detokenize{#1}\relax
\addcontentsline{toc}{chapter}{\acttitlename\ \theact}
\else
\addcontentsline{toc}{chapter}{\acttitlename\ \theact\actseparator#1}
\fi
\@titleact{#1} % print the whole act title
\@afterindentfalse % prevent indentation after title
\@afterheading
}
\newcommand\@titleact[1]{
\vspace*{\beforeactskip}
{\parindent 0pt \parskip 0.25\baselineskip % zero indentation, some line skip
\centering\acttitlefont\acttitlename\ \theact % print "Act III"
% <---- do not remove the %!
\if\relax\detokenize{#1}\relax % print act name
\else
\actseparator\par\nobreak#1
\fi
\par\nobreak\vskip\afteractskip}
}
%%%%%%%%%%%%%%%%%%%%%%% Scene
%%%%% Parameters %%%%%
\newlength{\beforesceneskip} \setlength{\beforesceneskip}{0pt}
\newlength{\aftersceneskip} \setlength{\aftersceneskip}{\baselineskip}
\newcommand{\sceneseparator}{\ --\ }
%%%%% Functions %%%%%%
\newcommand{\thescene}{\arabic{scenecounter}}
\newcommand\scene[1][]{
\stepcounter{scenecounter}
\vskip 1.0\baselineskip
\@scene{#1}
\parskip 0.5\baselineskip
}
\newcommand\@scene[1]{
\phantomsection % for hyperref
\scenemark{\scenetitlename\ \thescene} % mark for headers
\if\relax\detokenize{#1}\relax
\addcontentsline{toc}{section}{\scenetitlename\ \thescene}
\else
\addcontentsline{toc}{section}{\scenetitlename\ \thescene\sceneseparator#1}
\fi
\@titlescene{#1} % print whole scene title
%\@afterindentfalse % prevent indentation after title
}
\newcommand\@titlescene[1]{
\vspace*{\beforesceneskip}
{\centering{\scenetitlefont\scenetitlename\ \thescene % print "Scene 24"
% <---- do not remove the %!
\if\relax\detokenize{#1}\relax % print scene name
\else
\sceneseparator#1
\fi}%
\par\nobreak{\recurse@scenecharlist}%
\par\nobreak\vskip\aftersceneskip}
}
\newcommand\recurse@scenecharlist{%
\stepcounter{charstemp}%
%
\@ifundefined{r@act\Roman{actcounter}scene\Roman{scenecounter}char\Roman{charstemp}}
{}
{\if@atleastonechar{,\ }\fi
{\@nameuse{@char\Roman{charstemp}name}}%
\@atleastonechartrue}%
%
\ifnum\value{charstemp}<\value{totalcharcounter}%
\recurse@scenecharlist
\fi
\setcounter{charstemp}{0}%
}
%%%%%%%%%%%%%%%%%%%%%%% Parentheticals
\def\@setupparen{ \catcode`\(=\active\relax
\catcode`\)=\active\relax
}
\def\@cleanupparen{ \catcode`\(=12\relax
\catcode`\)=12\relax
}
\@setupparen
\gdef(#1){{\char`\( \itshape#1\char`\) }}
\@cleanupparen
%%%%%%%%%%%%%%%%%%%%%%% Stage directions
%%%%%%%%%%%%%%%%%%%%%%% Opening and technical directions
%%%%%%%%%%%%%%%%%%%%%%% End of script
\AtEndDocument{
\vspace{1.6ex}
\centering
\textsc{\scriptendlocalizedtext}
}
%%%%%%%%%%%%%%%%%%%%%%% Helper functions
\providecommand\phantomsection{} % if hyperref does not exist
\newcommand\actmark[1]{}
\newcommand\scenemark[1]{}
\newcommand\castlistmark[1]{}
\newlength{\maxcharlength}\setlength{\maxcharlength}{0pt}
\newlength{\@thischarlength}