forked from rpgtex/DND-5e-LaTeX-Template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dnd.sty
185 lines (158 loc) · 5.02 KB
/
dnd.sty
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
% DND 5e LaTeX Style File
% Created by Evan Bergeron
% Modified by Christopher Liu December 2015
% Modified by Yannic Meyer Feb 2016
\ProvidesPackage{dnd}[2019/02/09 v0.7.0 Template for DnD 5e material]
%
% Prerequisite Packages
%
\PassOptionsToPackage{table}{xcolor} % Helps prevent option clash with other packages that include xcolor
\RequirePackage{array}
\RequirePackage{calc}
\RequirePackage{colortbl}
\RequirePackage{enumitem}
\RequirePackage{etoolbox}
\RequirePackage{geometry}
\RequirePackage{hang}
\RequirePackage{ifluatex}
\RequirePackage{keycommand}
\RequirePackage[autolanguage]{numprint}
\RequirePackage{tabularx}
\RequirePackage[breakable,skins,xparse]{tcolorbox}
\RequirePackage{tikz}
\RequirePackage{xcolor}
\RequirePackage{xkeyval}
\RequirePackage{xparse}
\ifluatex
\RequirePackage{luacolor}
\fi
% \dnd@deprecate{<command or environment>}{<version>}[<suggestion>]
\DeclareDocumentCommand{\dnd@deprecate}{m m o}{%
\PackageWarning{dnd}{#1 is deprecated and will be removed in version #2.\IfNoValueF{#3}{ #3}}
}
%
% Options
%
\newtoggle{bool-bg}
\newtoggle{bool-footer-scroll}
\DeclareOptionX{bg}[full]{%
% This macro call looks complicated, but simply sets up a case environment
% to process choices. Refer to the xkeyval documentation for details.
\XKV@cc*+[\val\index]{#1}{full,none,print}{%
\ifcase\index\relax
% full
\toggletrue{bool-bg}
\toggletrue{bool-footer-scroll}
\or
% none
\togglefalse{bool-bg}
\togglefalse{bool-footer-scroll}
\or
% print
\togglefalse{bool-bg}
\toggletrue{bool-footer-scroll}
\fi
}{%
\PackageWarning{dnd}{\val\ is not a valid choice for bg and was ignored}
}
}
% Legacy bg option variants.
\DeclareOptionX{bg-full}{%
\dnd@deprecate{bg-full}{0.8}[Use bg=full instead.]
\toggletrue{bool-bg}
\toggletrue{bool-footer-scroll}
}
\DeclareOptionX{bg-none}{%
\dnd@deprecate{bg-none}{0.8}[Use bg=none instead.]
\togglefalse{bool-bg}
\togglefalse{bool-footer-scroll}
}
\DeclareOptionX{bg-print}{%
\dnd@deprecate{bg-print}{0.8}[Use bg=print instead.]
\togglefalse{bool-bg}
\toggletrue{bool-footer-scroll}
}
% Toggle justification (official books are flush left).
\newtoggle{justified}
\DeclareOptionX{justified}{\toggletrue{justified}}
% Toggle multitoc.
\newtoggle{multitoc}
\settoggle{multitoc}{true}
\DeclareOptionX{nomultitoc}{\togglefalse{multitoc}}
% Adds boolean `layout` package option and \ifpkglayout if command.
\define@boolkey{dnd.sty}[pkg]{layout}[true]{}
% Default Settings
\ExecuteOptionsX{bg=full, layout=true}
\ProcessOptionsX\relax
\ifpkglayout
\RequirePackage{microtype} % Improve ragged2e hyphenation and overfull boxes
\RequirePackage{ragged2e}
% Set page geometry.
\geometry{%
bindingoffset=15pt, % .2in
hmargin=50pt, % .7in
top=40pt, % .55in
bottom=50pt, % .7in
footskip=30pt, % makes the footer text line up with the graphic
}
% Set paragraph and line spacing
\linespread{1.1}%
\setlength{\parindent}{1em}
\setlength{\RaggedRightRightskip}{0pt plus 1cm}
\setlength{\RaggedRightParindent}{\parindent}
\hyphenpenalty=1000 % Fewer hyphens
% Set left justification if not justified
\nottoggle{justified}{\RaggedRight}
%
% Style Parameters
%
% Disable space between paragraphs.
\setlength{\parskip}{0pt}
% Columns setup
\setlength{\columnsep}{25pt} % .35in
% Customize itemize environment.
\setlist{leftmargin=1em}
\setitemize{noitemsep,topsep=0.5ex}
\renewcommand{\labelitemi}{\raisebox{0.25ex}{\tiny{\( \bullet \)}}}
\fi % \ifpkglayout
% Fancy DnD 5e stat block rule
\newcommand{\dndline}{%
\noindent
\begin{tikzpicture}[]
\draw [rulered, fill=rulered] (0, 0) --(0,0.1) -- (\textwidth, 0.05);
\end{tikzpicture}%
\par%
}
\renewcommand{\hline}{%
\dnd@deprecate{redefined \noexpand\hline}{0.8}[Use \noexpand\dndline for stat block rules.]%
\dndline%
}
% Either hilariously, or infuriatingly, the \ifcommandkey
% implementation is buggy. Here is a re-implementation
% from tex.stackexchange.
\begingroup
\makeatletter
\catcode`\/=8 %
\@firstofone
{
\endgroup
\renewcommand{\ifcommandkey}[1]{%
\csname @\expandafter \expandafter \expandafter
\expandafter \expandafter \expandafter \expandafter
\kcmd@nbk \commandkey {#1}//{first}{second}//oftwo\endcsname
}
}
% Load other modules of this package after all dependencies to avoid load order
% conflicts (e.g., package options).
\RequirePackage{lib/compat} % compatibility definitions
\RequirePackage{lib/dndcolors} % color definitions
\RequirePackage{lib/dndfonts} % font definitions
\RequirePackage{lib/dndcomment} % \commentbox definition
\RequirePackage{lib/dndheader} % fancy headers and footers
\RequirePackage{lib/dndmonster} % \monsterbox definition
\RequirePackage{lib/dndpaperbox} % \paperbox definition
\RequirePackage{lib/dndquote} % \quotebox definition
\RequirePackage{lib/dndsections} % section styling
\RequirePackage{lib/dndspell} % \spell definition
\RequirePackage{lib/dndstrings} % Load document strings
\RequirePackage{lib/dndtable} % \dndtable definition