-
Notifications
You must be signed in to change notification settings - Fork 1
/
anecdote.cls
1732 lines (1487 loc) · 58.4 KB
/
anecdote.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
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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% A memoir-based documentclass with a contemporary style for books with a lighter content.
% (c) Gambhiro Bhikkhu, 2017
% gambhiro.bhikkhu.85@gmail.com
% (c) Pāladhammika Bhikkhu, 2022
% paladhammika@protonmail.com
% LPPL LaTeX Public Project Licence
% Use LaTeX2e format
\NeedsTeXFormat{LaTeX2e}
% Define the document class named "anecdote"
\ProvidesClass{anecdote}[2017/08/19 v0.11 A memoir-based documentclass with a contemporary style for books.]
% Define a conditional for the digital version
\newif\ifdigitalversion
\digitalversionfalse
% Define a conditional for the A5 version formatting
\newif\ifafiveversion
\afiveversionfalse
% Define a conditional for the 9x13 version formatting
\newif\ifninebythirteenversion
\ninebythirteenversionfalse
% Define a conditional for the B5 version formatting
\newif\ifbfiveversion
\bfiveversionfalse
% Load the pgfopts package, which provides a key-value interface for package options
\RequirePackage{pgfopts}
% Load the calc package, which provides advanced arithmetic operations for LaTeX
\RequirePackage{calc}
% Define pgfkeys for BOOK settings
\pgfkeys{
/BOOK/.cd,
% Default value for babelLanguage is 'british'
babelLanguage/.default=british,
% Store the value of babelLanguage in \BOOK@babelLanguage
babelLanguage/.store in=\BOOK@babelLanguage,
% Set digitalVersion to true if specified in options
digitalVersion/.code=\digitalversiontrue,
% Set A5 Version to true if specified in options
afiveVersion/.code=\afiveversiontrue,
% Set 9x13 Version to true if specified in options
ninebythirteenVersion/.code=\ninebythirteenversiontrue,
% Set B5 Version to true if specified in options
bfiveVersion/.code=\bfiveversiontrue,
}
% Pass all unknown options to the memoir class
\DeclareOption*{%
\PassOptionsToClass{\CurrentOption}{memoir}
}
% Process pgfkeys options under /BOOK
\ProcessPgfOptions{/BOOK}
% Process other package options
\ProcessOptions\relax
% Load the digital version
\ifdigitalversion
% Using 11pt font size, single-sided printing, and the use of old font commands
\LoadClass[11pt,oneside,oldfontcommands]{memoir}
\else
% Otherwise format with 11pt font size, double-sided printing, and the use of old font commands.
\LoadClass[11pt,twoside,oldfontcommands]{memoir}
\fi
% \raggedbottom stops these warnings:
%
% Underfull \vbox (badness 10000) has occurred while \output is active
%
% by not streching the glue in vertical spaces, such as before and after chapter
% and section headings. The bottom of the pages will be uneven.
%
% Default is \flushbottom. The small streches are good because an even page
% bottom is better. When it causes large streches, it is better to put in
% a \clearpage manually.
%
% NOTE use the 'bottom' footmisc option when using \raggedbottom.
% NOTE Using \raggedbottom in this book. There are many quotes and the pages
% frequently have to break early anyway.
\raggedbottom
% \raggedbottomsection only affects pages where the section header was moved to
% the next page.
\raggedbottomsection
% Load the silence package, which provides a way to suppress LaTeX warnings
% \RequirePackage{silence}
% Turn off warnings using the \WarningsOff command from the silence package
% \WarningsOff
% Load the babel package with the language specified by \BOOK@babelLanguage
\RequirePackage[\BOOK@babelLanguage]{babel}
% Load the nag package to warn about the usage of outdated LaTeX constructs
\RequirePackage{nag}
% Load the xparse package for defining document commands with complex arguments
\RequirePackage{xparse}
% Load the soul package for letter spacing, underlining, and highlighting text
\RequirePackage{soul}
% Load the ifsym package for additional symbols
\RequirePackage[geometry]{ifsym}
% Load the STIX font package
\RequirePackage{stix}
% Load the xcolor package for color support
\RequirePackage{xcolor}
% Load the xcoffins package for creating complex layouts
\RequirePackage{xcoffins}
% Load the graphicx package for including graphics
\RequirePackage{graphicx}
% Load the eso-pic package for adding pictures to every page
\RequirePackage{eso-pic}
% Load the ccicons package for Creative Commons icons
\RequirePackage{ccicons}
% Load the multicol package for multi-column layout
\RequirePackage{multicol}
% Load the multirow package for multi-row table cells
\RequirePackage{multirow}
% Load the footnote package for footnotes
\RequirePackage{footnote}
% Load the hyphenat package for more control over hyphenation
\RequirePackage{hyphenat}
% Load the ifthen package for conditional statements
\RequirePackage{ifthen}
% Load the titletoc package for controlling the format of table of contents entries
\RequirePackage{titletoc}
% Load the enumitem package for customizing lists
\RequirePackage{enumitem}
% Load the longtable package for tables that span multiple pages
\RequirePackage{longtable}
% Load the environ package for defining environments with body manipulations
\RequirePackage{environ}
% Load the pageslts package for access to page labels
\RequirePackage{pageslts}
% Load the array package for more flexible column formatting in tables
\RequirePackage{array}
% Load the ragged2e package for improved ragged text alignment
\RequirePackage{ragged2e}
% Load the tipa package for IPA (International Phonetic Alphabet) symbols
\RequirePackage{tipa}
% Load the float package for improved control over floating environments
\RequirePackage{float}
% Load the TikZ package for creating graphics programmatically
\RequirePackage{tikz}
% Load specific TikZ libraries
\usetikzlibrary{arrows.meta,bending,chains,positioning}
% Load the pgfornament package for drawing decorative ornaments
\RequirePackage[object=vectorian]{pgfornament}
% Load the rotating package for rotating elements, such as tables and figures
\RequirePackage{rotating}
% Load the makecell package for formatting cells in tables
\RequirePackage{makecell}
% Set the width of rotated column headings in tables
\settowidth\rotheadsize{{\small Compound}}
% Define a command for "Not Applicable" in tables
\newcommand{\NA}{---}
% Load the tabularray package for flexible tables
\RequirePackage{tabularray}
% Load the ninecolors package for defining color schemes
\RequirePackage{ninecolors}
% Load the syntonly package which checks the syntax without compiling the document
\RequirePackage{syntonly}
% \syntaxonly
\RequirePackage{pdflscape}
% Define the color for the main body text.
\definecolor{textbody}{gray}{0}% 100% for maximum contrast.
% Define the color for the rule separating footnotes.
\definecolor{footnoterule}{gray}{0.5}
% Define the color for headers.
\definecolor{header}{gray}{0}
% Define the color for footers.
\definecolor{footer}{gray}{0}
% Define the color for chapter numbers.
\definecolor{chapternum}{gray}{0.2}
% Define the color for chapter titles.
\definecolor{chaptertitle}{gray}{0.1}
% Define the color for chapter title footnotes.
\definecolor{chaptertitlefootnote}{gray}{0.4}
% Define the color for chapter authors.
\definecolor{chapterauthor}{gray}{0.3}
% Define the color for chapter notes.
\definecolor{chapternote}{gray}{0.3}
% Define the color for section headings.
\definecolor{section}{gray}{0.05}
% Define the color for the left side of the table of contents.
\definecolor{tocleftside}{gray}{0.5}
% Define the color for the left side of the table of contents for parts.
\definecolor{tocleftsidepart}{gray}{0.2}
% Define the color for the border of links.
\definecolor{linkborder}{rgb}{0.4,0.4,1}% light blue
% Define the color for links.
\definecolor{link}{rgb}{0.2,0.2,1}% not so light blue
% Define the color for instructional text or comments.
\definecolor{instruction}{gray}{0.3}
% Load the fontspec package for font handling in XeLaTeX or LuaLaTeX.
\RequirePackage{fontspec}
% Set default font features including ligatures and specify the font path.
\defaultfontfeatures{ Ligatures={TeX}, Path = {./assets/fonts/}, }
% If ligatures such as emdash and endash don't work for your font, use Renderer = Basic.
% Source: http://tex.stackexchange.com/questions/20580/how-to-enable-ligatures-for-emdash-endash-in-luatex
% Set the main font for the document.
\setmainfont[
ItalicFont = LibertinusSerif-Italic.otf,
BoldFont = LibertinusSerifX-Bold.ttf,
BoldItalicFont = LibertinusSerif-BoldItalic.otf,
]{LibertinusSerifX-Regular.ttf}
% Define a new font family named 'libertinusFont'.
\newfontfamily\libertinusFont[
ItalicFont = LibertinusSerif-Italic.otf,
BoldFont = LibertinusSerifX-Bold.ttf,
BoldItalicFont = LibertinusSerif-BoldItalic.otf,
]{LibertinusSerifX-Regular.ttf}
% Define a new font family named 'sbsFont'.
% Provides the font of the titlepage
\newfontfamily\sbsFont[
ItalicFont = palisbs.ttf,
BoldFont = palisbs.ttf,
BoldItalicFont = palisbs.ttf,
]{palisbs.ttf}
% Define commands to set font styles for headers, footers, and page numbers.
\newcommand\headerFont\libertinusFont
\newcommand\footerFont\headerFont
\newcommand\pageNumFont\headerFont
% Define font styles for chapter and section headings.
% Part
\newcommand\partNameFont\libertinusFont
\newcommand\partTitleFont\libertinusFont
% Chapter
\newcommand\chapterNameFont\libertinusFont
\newcommand\chapterTitleFont\libertinusFont
\newcommand\chapterNumberFont\libertinusFont
\newcommand\chapterAuthorFont\libertinusFont
\newcommand\chapterNoteFont\libertinusFont
% Section
\newcommand\sectionFont\libertinusFont
\newcommand\subSectionFont\libertinusFont
% Font style for instructional text or comments.
\newcommand\instructionFont\libertinusFont
% Define font style for the side rule in quotes.
\newcommand\sideruleQuoteFont\libertinusFont
% Define font styles for the Table of Contents.
% Font for the main Table of Contents entries.
\newcommand\tocFont\libertinusFont
% Font for the old page numbers in the Table of Contents.
\newcommand\tocFontOldNum\libertinusFont
% Define font sizes for different elements in the document.
% Chapter name size
\ifafiveversion\newcommand{\chapterNameSize}{\@setfontsize \chapterNameSize {22}{24}}\fi
\ifninebythirteenversion\newcommand{\chapterNameSize}{\@setfontsize \chapterNameSize {16}{18}}\fi
\ifbfiveversion\newcommand{\chapterNameSize}{\@setfontsize \chapterNameSize {16}{18}}\fi
% Chapter number size
\ifafiveversion\newcommand{\chapterNumberSize}{\@setfontsize \chapterNumberSize {20}{20}}\fi
\ifninebythirteenversion\newcommand{\chapterNumberSize}{\@setfontsize \chapterNumberSize {14}{14}}\fi
\ifbfiveversion\newcommand{\chapterNumberSize}{\@setfontsize \chapterNumberSize {16}{16}}\fi
% Chapter title size ie 'Recitation Schedule, Purpose and Benefits...'
\ifafiveversion\newcommand{\chapterTitleSize}{\@setfontsize \chapterTitleSize {19}{19}}\fi
\ifninebythirteenversion\newcommand{\chapterTitleSize}{\@setfontsize \chapterTitleSize {13}{13}}\fi
\ifbfiveversion\newcommand{\chapterTitleSize}{\@setfontsize \chapterTitleSize {22}{22}}\fi
% Chapter title footnote size
\ifafiveversion\newcommand{\chapterTitleFootnoteSize}{\@setfontsize \chapterTitleFootnoteSize {16}{30}}\fi
\ifninebythirteenversion\newcommand{\chapterTitleFootnoteSize}{\@setfontsize \chapterTitleFootnoteSize {11}{21}}\fi
\ifbfiveversion\newcommand{\chapterTitleFootnoteSize}{\@setfontsize \chapterTitleFootnoteSize {16}{21}}\fi
% Chapter author size
\ifafiveversion\newcommand{\chapterAuthorSize}{\@setfontsize \chapterAuthorSize {12}{14}}\fi
\ifninebythirteenversion\newcommand{\chapterAuthorSize}{\@setfontsize \chapterAuthorSize {8.5}{10}}\fi
\ifbfiveversion\newcommand{\chapterAuthorSize}{\@setfontsize \chapterAuthorSize {8.5}{10}}\fi
% Chapter note size
\ifafiveversion\newcommand{\chapterNoteSize}{\@setfontsize \chapterNoteSize {13}{15}}\fi
\ifninebythirteenversion\newcommand{\chapterNoteSize}{\@setfontsize \chapterNoteSize {9}{11}}\fi
\ifbfiveversion\newcommand{\chapterNoteSize}{\@setfontsize \chapterNoteSize {9}{11}}\fi
% Footer size
\ifafiveversion\newcommand{\footerSize}{\@setfontsize \footerSize {11}{8}}\fi
\ifninebythirteenversion\newcommand{\footerSize}{\@setfontsize \footerSize {8}{6}}\fi
\ifbfiveversion\newcommand{\footerSize}{\@setfontsize \footerSize {14}{8}}\fi
% Header size
\ifafiveversion\newcommand{\headerSize}{\@setfontsize \headerSize {11}{2}}\fi
\ifninebythirteenversion\newcommand{\headerSize}{\@setfontsize \headerSize {8}{1.5}}\fi
\ifbfiveversion\newcommand{\headerSize}{\@setfontsize \headerSize {13}{2}}\fi
% Table of Contents size
\ifafiveversion\newcommand{\tocSize}{\@setfontsize \tocSize {19}{14}}\fi
\ifninebythirteenversion\newcommand{\tocSize}{\@setfontsize \tocSize {25}{10}}\fi
\ifbfiveversion\newcommand{\tocSize}{\@setfontsize \tocSize {25}{10}}\fi
% Section font size in Table of Contents
% e.g. 'Dedication of Offerings'
\ifafiveversion\newcommand{\tocSectionSize}{\@setfontsize \tocSectionSize {12.5}{15}}\fi
\ifninebythirteenversion\newcommand{\tocSectionSize}{\@setfontsize \tocSectionSize {9}{11}}\fi
\ifbfiveversion\newcommand{\tocSectionSize}{\@setfontsize \tocSectionSize {15}{20}}\fi
% Subsection font size in Table of Contents
% e.g. 'Undertaking the Three Refuges'
\ifafiveversion\newcommand{\tocSubsectionSize}{\@setfontsize \tocSubsectionSize {11}{11}}\fi
\ifninebythirteenversion\newcommand{\tocSubsectionSize}{\@setfontsize \tocSubsectionSize {8}{8}}\fi
\ifbfiveversion\newcommand{\tocSubsectionSize}{\@setfontsize \tocSubsectionSize {12}{8}}\fi
% Define a command to make text smaller.
\ifafiveversion\newcommand{\smaller}{\@setfontsize \smaller {9}{11}}\fi
\ifninebythirteenversion\newcommand{\smaller}{\@setfontsize \smaller {6}{8}}\fi
\ifbfiveversion\newcommand{\smaller}{\@setfontsize\smaller{6}{8}}\fi
% Define font size for copyright notice.
\ifafiveversion\newcommand{\copyrightsize}{\@setfontsize \copyrightsize {9}{11}}\fi
\ifninebythirteenversion\newcommand{\copyrightsize}{\@setfontsize \copyrightsize {6}{8}}\fi
\ifbfiveversion\newcommand{\copyrightsize}{\@setfontsize \copyrightsize {6}{8}}\fi
% Redefine footnote size to be smaller.
\ifafiveversion\renewcommand{\footnotesize}{%
\@setfontsize\footnotesize{9}{11}%
\abovedisplayskip 8\p@ \@plus2\p@ \@minus4\p@
\abovedisplayshortskip \z@ \@plus\p@
\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
\def\@listi{\leftmargin\leftmargini
\topsep 4\p@ \@plus2\p@ \@minus2\p@
\parsep 2\p@ \@plus\p@ \@minus\p@
\itemsep \parsep
%% \itemindent\z@
}%
\belowdisplayskip \abovedisplayskip
}
\fi
\ifninebythirteenversion\renewcommand{\footnotesize}{%
\@setfontsize\footnotesize{6}{8}%
\abovedisplayskip 8\p@ \@plus2\p@ \@minus4\p@
\abovedisplayshortskip \z@ \@plus\p@
\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
\def\@listi{\leftmargin\leftmargini
\topsep 4\p@ \@plus2\p@ \@minus2\p@
\parsep 2\p@ \@plus\p@ \@minus\p@
\itemsep \parsep
%% \itemindent\z@
}%
\belowdisplayskip \abovedisplayskip
}
\fi
\ifbfiveversion\renewcommand{\footnotesize}{%
\@setfontsize\footnotesize{11}{13}%
\abovedisplayskip 8\p@ \@plus2\p@ \@minus4\p@
\abovedisplayshortskip \z@ \@plus\p@
\belowdisplayshortskip 4\p@ \@plus2\p@ \@minus2\p@
\def\@listi{\leftmargin\leftmargini
\topsep 4\p@ \@plus2\p@ \@minus2\p@
\parsep 2\p@ \@plus\p@ \@minus\p@
\itemsep \parsep
%% \itemindent\z@
}%
\belowdisplayskip \abovedisplayskip
}
\fi
% Load microtype package with options for final output and support for babel
\RequirePackage[final,babel=true]{microtype}
% Set tracking for uppercase section headings using LibertinusSerif-Regular font
\SetTracking[spacing={400,100,}]{encoding=*, family={LibertinusSerif-Regular.otf}}{20}
% Load hyperref package for hyperlinks and hyperxmp for XMP metadata
\RequirePackage{hyperref}
\RequirePackage{hyperxmp}
% Configure hyperref package settings
\hypersetup{
unicode=true, % Use Unicode encoded PDF strings
bookmarksopen=true, % Open bookmarks
bookmarksopenlevel=3, % Set depth of opened bookmarks
hypertexnames=false, % Prevent duplicate destination names
linktoc=all, % Set links in table of contents
plainpages=false, % Use PDF anchors with correct page numbers
raiselinks=true, % Raise up link boxes
breaklinks % Allow line breaks in hyperlinks
}
% Conditional statement based on a variable 'digitalversion'
\ifdigitalversion
% If digital version, set link colors to custom brown
\hypersetup{
colorlinks=true,
linkcolor=sbs-brown,
citecolor=sbs-brown,
filecolor=sbs-brown,
urlcolor=sbs-brown,
}
\else
% If print version, set link colors to text color
\hypersetup{
colorlinks=true,
linkcolor=textbody,
citecolor=textbody,
filecolor=textbody,
urlcolor=textbody,
}
\fi
% Load bookmark package with options to create bookmarks
\RequirePackage[
open, % Bookmarks will be shown
openlevel=2 % Initial level of bookmarks
]{bookmark}
% Color used for links and headers
\definecolor{sbs-brown}{HTML}{60291F}
% Color used for subtitle
\definecolor{sbs-brown2}{HTML}{573005}
% Color used for dividers
\definecolor{sbs-gold}{HTML}{aa6a1f}
% Fix for endnotes two-way link aiming too low
% Source: https://tex.stackexchange.com/questions/17057/hypertarget-seems-to-aim-a-line-too-low
% Memoir's more allowing penalies; allow some sloppiness in line breaking to avoid overly strict spacing
\midsloppy
% Set hyphenation parameters for British English
\renewcommand\britishhyphenmins{{3}{3}}
% Set penalties for hyphenation and line breaking
\hyphenpenalty=700 % Penalty for breaking lines at hyphens
\exhyphenpenalty=50 % Penalty for breaking lines after explicit hyphens
\doublehyphendemerits=900 % Demerits for consecutive line hyphens
% It is more effective to \mbox{...} the words to avoid hyphenation.
\brokenpenalty=5000 % penalty for page break after a hyphenated line
% NOTE: This package is best for prose text. Here it creates unexpected page breaks,
% and complicates the endnotes formatting.
% \RequirePackage[defaultlines=2,all]{nowidow}
% \hyphenation{season wisdom develop-ment respon-sible pheno-mena philo-sophical munindo amaravati thai-land}
% Define a new series of emphasis commands using the sodef package
\sodef\soTocChapter{}{.1em}{.5em plus.1em}{.1em plus.1em minus.1em}
\sodef\soSection{}{.07em}{.4em plus.1em}{.1em plus.1em minus.1em}
% Source: https://tex.stackexchange.com/questions/4839/raggedleft-paragraph-in-a-table
% Define new column types for left-aligned and right-aligned columns in tables
% Usage: \begin{tabular}{L{30mm}R{30mm}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
% Define a command to insert a divider rule in tables
\newcommand\dividerRule{%
{\centering\bigskip
{\color[gray]{0.6}\rule{0.6\linewidth}{0.2pt}}
\par\bigskip}%
}
% Define commands to insert empty pages
\newcommand\emptysheet{%
\cleardoublepage
\thispagestyle{empty}\mbox{}\newpage
\thispagestyle{empty}\mbox{}\newpage
}
% Alias for \emptysheet
\newcommand\emptydoublepage\emptysheet
% Define a command to insert a single empty page
\newcommand\emptypage{%
\clearpage
\thispagestyle{empty}\mbox{}\newpage
}
% Define a command to insert empty pages until the current page count is even
\newcommand{\emptyUntilEven}{%
\ifodd\thepage%
\clearpage\thispagestyle{empty}\null%
\fi%
}
% Define counters for page number manipulation
\newcounter{pageRem}
\newcounter{origPage}
% Add empty pages to achieve a total page count divisible by 8 without remainder
\newcommand{\emptyUntilModEight}{%
\setcounter{origPage}{\theCurrentPage}%
\setcounter{pageRem}{1 + 8 - ( \theCurrentPage - ( ( \theCurrentPage / 8 ) * 8) )}%
%\typeout{hey: \theCurrentPage, \theorigPage, \thepageRem}% NOTE only for debugging
\loop%
\addtocounter{pageRem}{-1}%
\ifnum\thepageRem>0%
\clearpage%
\thispagestyle{empty}\mbox{}%
%hey \theorigPage \space \thepageRem% NOTE only for debugging
\repeat%
}
% Define commands for document metadata
\newcommand*{\subtitle}[1]{\def\@thesubtitle{#1}}
\newcommand*{\editionInfo}[1]{\def\@theEditionInfo{#1}}
\newcommand*{\printedByInfo}[1]{\def\@thePrintedByInfo{#1}}
\newcommand*{\publisher}[1]{\def\@thePublisher{#1}}
\newcommand*{\ISBN}[1]{\def\@theISBN{#1}}
% Define commands to access document metadata
\newcommand\thesubtitle{\@thesubtitle}
\newcommand\theEditionInfo{\@theEditionInfo}
\newcommand\thePrintedByInfo{\@thePrintedByInfo}
\newcommand\thePublisher{\@thePublisher}
\newcommand\theISBN{\@theISBN}
% Define a savebox for quotepage environment
\newsavebox{\quotepagebox}
\newenvironment{quotepage}[1]
{\begin{lrbox}{\quotepagebox}\begin{minipage}{#1}
\setlength{\parskip}{0.6\baselineskip}
\setlength{\parindent}{0pt}}
{\end{minipage}\end{lrbox}%
\begin{tikzpicture}[remember picture,overlay]
\node at (current page.center) {\usebox{\quotepagebox}};
\end{tikzpicture}}
% Define custom environments with compact itemize and enumerate
\newenvironment{packeditemize}%
{\begin{itemize}[
itemindent=0pt,
leftmargin=15pt,
rightmargin=0pt,
itemsep=4pt,
topsep=0pt,
parsep=0pt,
partopsep=0pt,
]%
}{\end{itemize}}
\newenvironment{packedenumerate}%
{\begin{enumerate}[
itemindent=0pt,
leftmargin=15pt,
rightmargin=0pt,
itemsep=4pt,
topsep=0pt,
parsep=0pt,
partopsep=0pt,
]%
}{\end{enumerate}}
% If class option digitalVersion is used, show content in a paper sized
% minipage, empty page otherwise.
% Redefine \color{digitalcoverbg} to change page background color.
\newcommand\digitalCover[1]{%
\thispagestyle{empty}\mbox{}
\ifdigitalversion
\AddToShipoutPictureFG*{\put(0,0){%
\begin{minipage}[b][\paperheight][c]{\paperwidth}%
#1
\end{minipage}}}
\fi
\clearpage
}
% Define lengths for document layout
\newlength{\titleLength}% Length for the title
\newlength{\xheight}% Length for the x-height of the font
%%%%%%%%%%%%%%%% Quotes %%%%%%%%%%%%%%%%
% Define a length for the margin of block quotes
\newlength{\quoteMargin}
% Set the value of the quoteMargin length to 18 points
\setlength{\quoteMargin}{18pt}
% Redefine the verse environment for sutta verses and other short stanzas
\renewenvironment{verse}
{\begin{centering}% Begins centering environment for verse
\itshape% Sets verse in italics
}%
{\par\end{centering}}% Ends centering environment for verse
% Define a command for sutta references
\newcommand{\suttaRef}[1]{%
\ifbfiveversion
\vspace{-7pt}% Adjusts vertical spacing above sutta references
\else
\vspace{-6pt}% Adjusts vertical spacing above sutta references
\fi
\hfill {\ifafiveversion\fontsize{8}{16}\fi\ifninebythirteenversion\fontsize{6}{11}\fi\ifbfiveversion\fontsize{9.5}{19}\fi\selectfont #1\par}% Sets sutta reference in smaller font size
\vspace{-6pt}% Adjusts vertical spacing below sutta references
}
% Redefine the quote environment for longer sutta and book quotes
\renewenvironment{quote}%
{\list{}{% Begins a list for the quote environment
\itshape% Sets quote in italics
\ifninebythirteenversion\fontsize{8}{12}\selectfont\fi% Sets font size for quote title
% \ifbfiveversion\fontsize{9}{13}\selectfont\fi% Sets font size for quote title
\listparindent 0pt% Sets paragraph indentation within the list
\itemindent \listparindent% Sets item indentation within the list
\leftmargin \quoteMargin% Sets left margin for the quote
\rightmargin \quoteMargin% Sets right margin for the quote
\parsep 8pt% Sets paragraph separation within the list
\topsep 0pt% Sets spacing above the list
\partopsep 0pt}% Sets additional spacing above the list
\item[]}%
{\endlist}% Ends the list for the quote environment
% Define commands for including photos with full bleed
% \ifbfiveversion
\newcommand\photoFullBleed[1]{%
\AddToShipoutPictureFG*{%
\put(\LenToUnit{-3mm},\LenToUnit{-3mm}){%
\includegraphics[height={\paperheight + 6mm}]{#1}%
}%
}%
}
% \fi
% \ifninebythirteenversion
% \newcommand\photoFullBleed[1]{%
% \AddToShipoutPictureFG*{%
% \put(\LenToUnit{-3mm},\LenToUnit{-3mm}){%
% \includegraphics[height={\paperheight + 6mm}]{#1}%
% }%
% }%
% }
% \fi
% Define a command to set the graphics for a chapter opening page
\newcommand{\thechaptergraphics}{}
% Define a command to set the graphics for a chapter opening page
% #1: photo
\newcommand{\chapterOpeningPage}[1]{%
\renewcommand{\thechaptergraphics}{#1}
}
% Define a command for creating a section break
% \newcommand\sectionBreak{%
% \vspace{8pt \@plus 15pt \@minus 0pt}%
% \par%
% {%
% \centering%
% \libertinusFont%
% \ifafiveversion\fontsize{20}{20}\selectfont\fi%
% \ifninebythirteenversion\fontsize{14}{14}\selectfont\fi%
% \color[gray]{0.7}%
% *\quad*\quad*%
% \par}%
% \vspace{8pt \@plus 15pt \@minus 0pt}%
% }
% Breath mark is U+1D112. This character is often not included in typefaces.
% Since it's identical to a right single quote mark (U+2019), we'll use that.
% To distinguish it from a quote mark, we raise it higher, above the riser stems (such as d' or l').
\newcommand\breathmark{%
\ifafiveversion
\raisebox{-0.10\baselineskip}{\fontsize{18}{18}\bfseries\symbol{"2019}}%
\fi
\ifninebythirteenversion
\raisebox{-0.10\baselineskip}{\fontsize{12}{12}\bfseries\symbol{"2019}}%
\fi
\ifbfiveversion
\raisebox{-0.10\baselineskip}{\fontsize{20}{20}\bfseries\symbol{"2019}}%
\fi
}
% Same character as above but lowered for better diplay in abbreviations chapter.
\newcommand\abbrbreathmark{%
\ifafiveversion
\raisebox{-0.65em}{\fontsize{24}{8}\bfseries\symbol{"2019}}%
\fi
\ifninebythirteenversion
\raisebox{-0.65em}{\fontsize{18}{8}\bfseries\symbol{"2019}}%
\fi
\ifbfiveversion
\raisebox{-0.65em}{\fontsize{24}{8}\bfseries\symbol{"2019}}%
\fi
}
% Left angle bracket used for indicating the solo parts for the recitation leader.
\newcommand\anglebracketleft{%
\ifafiveversion
\raisebox{0.0\baselineskip}{\Large\symbol{"2329}}%
\fi
\ifninebythirteenversion
\raisebox{0.0\baselineskip}{\large\symbol{"2329}}%
\fi
\ifbfiveversion
\raisebox{0.0\baselineskip}{\LARGE\symbol{"2329}}%
\fi
}
% Right angle bracket used for indicating the solo parts for the recitation leader.
\newcommand\anglebracketright{%
\ifafiveversion
\raisebox{0.0\baselineskip}{\Large\symbol{"232A}}%
\fi
\ifninebythirteenversion
\raisebox{0.0\baselineskip}{\large\symbol{"232A}}%
\fi
\ifbfiveversion
\raisebox{0.0\baselineskip}{\LARGE\symbol{"232A}}%
\fi
}
% Define a command for generating a bottom navigation section
% #1: The label for the next section
\newcommand\bottomNav[1]{%
\vfill % Fill the vertical space
\ifdigitalversion % Check if the digital version is active
\begin{minipage}{\linewidth}%
% Hyperlink to the "schedule" section
\hyperref[schedule]{%
\textbf{\raggedright\textsc{\fontsize{13}{0}\textls*{Schedule}}}}
\hfill % Fill the space between elements
% Hyperlink to the next section specified by the argument
\hyperref[#1]{%
\textbf{\raggedleft\textsc{\fontsize{13}{0}\textls*{Next}}}}%
\end{minipage}%
\fi
}
% Define commands for storing color specifications
\newcommand\modelTmp{}% Temporary storage for color model
\newcommand\specTextbody{}% Store color specifications for text body
\newcommand\specChaptertitle{}% Store color specifications for chapter titles
\newcommand\specSection{}% Store color specifications for sections
\newcommand\specFootnote{}% Store color specifications for footnotes
\newcommand\specFooter{}% Store color specifications for footers
% Define a command to extract color specifications
\newcommand\extractSpecs{%
\extractcolorspecs{textbody}{\modelTmp}{\specTextbody}%
\extractcolorspecs{chaptertitle}{\modelTmp}{\specChaptertitle}%
\extractcolorspecs{section}{\modelTmp}{\specSection}%
\extractcolorspecs{footnote}{\modelTmp}{\specFootnote}%
\extractcolorspecs{footer}{\modelTmp}{\specFooter}%
}
% Define a command to print color specifications
% #1: Description title of specs, such as 'variation A, base colors'
\newcommand{\printSpecs}[1]{%
\cleartoverso % Start a new page
\mbox{}\vfill % Fill the vertical space
\thispagestyle{empty}% Remove page numbering and headers/footers
\extractSpecs % Extract color specifications
#1 % Print the description title
% Create a table to display color specifications
\begin{tabular}{@{} l l}
Chapter title & \specChaptertitle \\
Text body & \specTextbody \\
Section & \specSection \\
Footnote & \specFootnote \\
Footer & \specFooter \\
\end{tabular}%
\vfill\mbox{}% Fill the remaining vertical space
}
% Define commands to be executed when entering different parts of the document
% Append code to be executed when entering \mainmatter
\addtodef{\mainmatter}{}{%
% \addtocontents{toc}{\addvspace{5pt}}%
% \setcounter{chapter}{0}%
}
\addtodef{\appendix}{}{%
% Not adding vspace here because it interferes with the closing '.' of the
% section list. The vertical space is added in \titlecontents{appendix}.
\bookmarksetup{startatroot}%
}
% Append code to be executed when entering \backmatter
\addtodef{\backmatter}{}{%
\bookmarksetup{startatroot}%
}
% Define a command for formatting a reference in a quote
\newcommand\quoteref[1]{%
\par % Start a new paragraph
{\footnotesize #1}% Set the reference in footnotesize font
\par % End the paragraph
}
% adapted from base/latex.ltx
\def\footnoterule{%
\kern-3\p@
{\color{footnoterule}\rule{\columnwidth}{0.25pt}}%
\vspace*{7pt}%
\kern 2.6\p@}
% Redefine the name for the notes section
\renewcommand*{\notesname}{Endnotes}
\ifninebythirteenversion
% Redefine the title format for the notes section
\renewcommand*{\notedivision}{%
\chapter{\notesname}%
\vspace{-0.7em}%
}
\fi
\ifafiveversion
% Redefine the title format for the notes section
\renewcommand*{\notedivision}{%
\chapter{\notesname}%
\vspace{-0.4em}%
}
\fi
% Redefine the format for subheadings in page notes
\renewcommand*{\pagenotesubhead}[3]{}
% Redefine the format for note numbers in text
\renewcommand*{\notenumintext}[1]{\textsuperscript{\thinspace #1}}
% Redefine the format for the pre-note in notes
\renewcommand{\prenoteinnotes}{\par\noindent\hangindent=17pt}
%% http://tex.stackexchange.com/questions/36894/underline-omitting-the-descenders
%% http://tex.stackexchange.com/a/75406
% Load required packages and define a custom command for underlining with a colored outline
\RequirePackage[outline]{contour}% Load contour package with outline option
\RequirePackage[normalem]{ulem}% Load ulem package
% Define a command for underlining text with a colored outline
\newcommand\prul[1]{%
\begingroup%
\renewcommand{\ULdepth}{1.8pt}% Set depth of underline
\renewcommand{\ULthickness}{0.5pt}% Set thickness of underline
\contourlength{0.5pt}% Set contour length
\uline{\phantom{#1}}\llap{\contour{white}{#1}}% Underline text with colored outline
\endgroup%
}
%%%%%%%%%%%%%%%% Page Styles %%%%%%%%%%%%%%%%
% Disable automatic capitalization of headers
\nouppercaseheads
% Define a command for drawing a separator line
\newcommand{\sepline}{%
\hspace{6pt}% Horizontal space
\raisebox{-0.3\baselineskip}{\rule{0.2pt}{1.2\baselineskip}}% Rule for the line
\hspace{6pt}% Horizontal space
}
% Define a page style named "toponerow"
\makepagestyle{toponerow}
% Define header and footer for even pages
\makeevenhead{toponerow}{\headerFont\headerSize\color{header}\thepage}{}{\headerFont\headerSize\color{header}\textls*{\textsc{\leftmark}}}
\makeevenfoot{toponerow}{}{}{}
% Define header and footer for odd pages
\makeoddhead{toponerow}{\headerFont\headerSize\color{header}\textls*{\textsc{\leftmark}}}{}{\headerFont\headerSize\color{header}\thepage}
\makeoddfoot{toponerow}{}{}{}
% Set page marks for "toponerow"
\makepsmarks{toponerow}{%
\nouppercaseheads % Prevent uppercase conversion of headers
% Create marks for various document elements
\createmark{chapter}{left}{nonumber}{}{}
\createmark{section}{right}{nonumber}{}{}
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}
}
% Define a page style named "toponerow-frontmatter" for front matter pages
\makepagestyle{toponerow-frontmatter}
% Define header and footer for even pages
\makeevenhead{toponerow-frontmatter}{\headerFont\headerSize\color{header}\thepage}{}{\headerFont\headerSize\color{header}\textls*{\textsc{\leftmark}}}
\makeevenfoot{toponerow-frontmatter}{}{}{}
% Define header and footer for odd pages
\makeoddhead{toponerow-frontmatter}{\headerFont\headerSize\color{header}\textls*{\textsc{\leftmark}}}{}{\headerFont\headerSize\color{header}\thepage}
\makeoddfoot{toponerow-frontmatter}{}{}{}
% Set page marks for "toponerow-frontmatter"
\makepsmarks{toponerow-frontmatter}{%
\nouppercaseheads % Prevent uppercase conversion of headers
% Create marks for various document elements
\createmark{chapter}{left}{nonumber}{}{}
\createmark{section}{right}{nonumber}{}{}
\createplainmark{toc}{both}{\contentsname}
\createplainmark{lof}{both}{\listfigurename}
\createplainmark{lot}{both}{\listtablename}
\createplainmark{bib}{both}{\bibname}
\createplainmark{index}{both}{\indexname}
\createplainmark{glossary}{both}{\glossaryname}
}
% Define a page style named "bottomcorner" for pages with page numbers in the bottom corner
\makepagestyle{bottomcorner}
% Define header and footer for even pages
\makeevenhead{bottomcorner}{}{}{}
\makeevenfoot{bottomcorner}{%
\footerFont\footerSize%
\color{footer}%
\thepage\hspace*{1em}$\cdot$\hspace*{1em}\textit{\thetitle}%
}{}{}
% Define header and footer for odd pages
\makeoddhead{bottomcorner}{}{}{}
\makeoddfoot{bottomcorner}{}{}{%
\footerFont\footerSize%
\color{footer}%
\textit{\leftmark}\hspace*{1em}$\cdot$\hspace*{1em}\thepage%
}
% Define a page style named "bottomcenter" for pages with page numbers centered at the bottom
\makepagestyle{bottomcenter}
% Define header and footer for even pages
\makeevenhead{bottomcenter}{}{}{}
\makeevenfoot{bottomcenter}{}{%
\footerFont\footerSize%
\color{footer}%
\thepage%
}{}
% Define header and footer for odd pages
\makeoddhead{bottomcenter}{}{}{}
\makeoddfoot{bottomcenter}{}{%
\footerFont\footerSize%
\color{footer}%
\thepage%
}{}
% Alias the page styles into semantic names, indicating where they are used
% Alias the "toponerow" page style as "normalpage" for normal pages
\aliaspagestyle{normalpage}{toponerow}
% Alias the "bottomcenter" page style as "chapter" for chapter pages
\aliaspagestyle{chapter}{bottomcenter}
% Alias the "empty" page style for book parts and afterparts
\aliaspagestyle{book}{empty}
\aliaspagestyle{part}{empty}
\aliaspagestyle{afterpart}{empty}
% Set the default page style to "normalpage"
\pagestyle{normalpage}
% Set the maximum depth of the table of contents to include subsubsections
\maxtocdepth{subsubsection}
% Set the right margin for the table of contents
\contentsmargin{-5pt}
% Define the width of the left margin in the table of contents
\newlength\tocLeftWidth
\setlength\tocLeftWidth{0pt}
% Define commands to handle chapter and part numbering in the table of contents
\renewcommand\chapternumberline[1]{\numberline{#1}}
\renewcommand\partnumberline[1]{\numberline{#1}}
\let\ttll@appendix\ttll@chapter % Fixes undefined control sequence error
\newcommand*\l@chapternote{\@nodottedtocline{0}{\tocLeftWidth}{1pc}{1pc}}
\def\@nodottedtocline#1#2#3#4#5#6{%
\ifnum #1>\c@tocdepth \else