summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/gurps/gurps.dtx
blob: 83a77e10c76e42c39e7839d931fef9ac07225c23 (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
% \iffalse meta-comment
% vim: textwidth=75
%<*internal>
\iffalse
%</internal>
%<*readme>
|        |                                                                 |
|-------:|------------------------------------------------------------------
|  gurps:| A LaTeX package for GURPS typesetting                           |
| Author:| Nathanael Farley                                                |
| E-mail:| nasfarley88@gmail.com                                           |
|License:| Released under the LaTeX Project Public License v1.3c or later  |
|    See:| http://www.latex-project.org/lppl.txt                           |

This package supports typesetting Generic Universal Role Playing System (GURPS) materials. It provides many convenience commands (e.g. `\gurps`, `\SJGamesOnlinePolicy`) as well as limited NPC building capabilities with a character environment.

The package requires the use of LuaLaTeX as several of the internal calculations are in Lua. 

----

Disclaimer:
The material presented here is the original creation of Nathanael Farley, intended for use with the <a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> system from <a href="http://www.sjgames.com/">Steve Jackson Games</a>. This material is not official and is not endorsed by Steve Jackson Games.

Notice:
<a href="http://www.sjgames.com/gurps/"><b><i>GURPS</i></b></a> is a registered trademark of Steve Jackson Games, and is copyrighted by Steve Jackson Games. All rights are reserved by SJ Games. This material is used here in accordance with the SJ Games <a href="http://www.sjgames.com/general/online_policy.html">online policy</a>.
%</readme>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
-------:| -----------------------------------------------------------------
  gurps:| A LaTeX package for GURPS typesetting
 Author:| Nathanael Farley
 E-mail:| nasfarley88@gmail.com
License:| Released under the LaTeX Project Public License v1.3c or later
    See:| http://www.latex-project.org/lppl.txt

\endpreamble
\postamble

Copyright (C) 2017 by Nathanael Farley <nasfarley88@gmail.com>

This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License (LPPL), either
version 1.3c of this license or (at your option) any later
version.  The latest version of this license is in the file:

http://www.latex-project.org/lppl.txt

This work is "maintained" (as per LPPL maintenance status) by
Nathanael Farley.

This work consists of the file gurps.dtx and a Makefile.
Running "make" generates the derived files README, gurps.pdf and gurps.sty.
Running "make inst" installs the files in the user's TeX tree.
Running "make install" installs the files in the local TeX tree.

\endpostamble

\usedir{tex/latex/gurps}
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/gurps}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\usedir{doc/latex/gurps}
\generate{
  \file{README.md}{\from{\jobname.dtx}{readme}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{gurps.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{gurps}
%<*package>
    [2018/02/14 v0.1.1 A LaTeX package for GURPS typesetting]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[a4paper,margin=25mm,left=50mm,nohead]{geometry}
\usepackage[numbered]{hypdoc}
\usepackage{\jobname}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{\jobname.dtx}
% \DoNotIndex{\newcommand,\newenvironment}
%
% \title{\textsf{gurps} --- A LaTeX package for GURPS typesetting\thanks{This file
% describes version \fileversion, last revised \filedate.}
%}
%\author{Nathanael Farley\thanks{E-mail: nasfarley88@gmail.com}}
%\date{Released \filedate}
%
%\maketitle
%
%\changes{v0.1}{2018/02/13}{First public release}
%\changes{v0.1.1}{2018/02/14}{Minor changes to CTAN upload}
%
% \begin{abstract}
%   \textit{\textbf{GURPS}} is an excellent RPG system. \LaTeX{} is an excellent
%   typesetting system. Together, they make excellent game aids. At least, they
%   can with this package!
% \end{abstract}
%
% \section{Usage}
%
% ==== Put descriptive text here. ====
%
% \DescribeMacro{\gurps}
% The SJGames online policy asks that \textbf{\textit{GURPS}} is always bold and
% italicised, so this command provides the correct
% formatting.
% 
% \DescribeEnv{character}
% Yep. Makes a character
%
%\StopEventually{^^A
%  \PrintChanges
%  \PrintIndex
%}
%
% \section{Implementation}
% Loading required libraries and the lua logic for this class.
%    \begin{macrocode}
%<*package>
\RequirePackage{xparse}
\RequirePackage{xspace}
\RequirePackage{etex}
\RequirePackage{luacode}

\RequirePackage{hyperref}

\luadirect{require("gurps.lua")}
%    \end{macrocode}
% \begin{macro}{\gurps}
% Steve Jackson Games asks that the name \textbf{\textit{GURPS}} is always in
% bold and italicised. This macro provides that.
%    \begin{macrocode}
\NewDocumentCommand{\gurps}{s}{%
    \IfBooleanTF#1
    % With star
    {\href{http://www.sjgames.com/gurps/}{\textbf{\textit{GURPS}}\xspace}}
    % Without star
    {\textbf{\textit{GURPS}}\xspace}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\dice}
% Notates dice in the \gurps way (e.g. drops the |6| from |d6|) and puts it in %
% an |\mbox|. First argument number of dice. Second argument is a modifier and
% optional. E.g.~|\dice{3}[1]|
% creates \mbox{3d+1}.
%    \begin{macrocode}
\NewDocumentCommand{\dice}{mO{0}}{%
  \luadirect{print_dice([[#1]], [[#2]])}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SteveJacksonGames}
%    \begin{macrocode}
\NewDocumentCommand{\SteveJacksonGames}{s}{%
    \IfBooleanTF#1%
    % With star
    {\href{http://www.sjgames.com/}{Steve~Jackson~Games\xspace}}%
    % Without star
    {Steve~Jackson~Games\xspace}%
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SJGamesOnlinePolicyDisclaimer}
%    \begin{macrocode}
\NewDocumentCommand{\SJGamesOnlinePolicyDisclaimer}{}{%
  The material presented here is my original creation, intended for use with the
  \gurps* system from \SteveJacksonGames*. This material is not official and is
  not endorsed by \SteveJacksonGames.
}
%    \end{macrocode}
% \end{macro}
% 
% \begin{macro}{\SJGamesOnlinePolicyDisclaimer}
% The disclaimer \emph{almost} as it appears on the online policy. The words
% `the art' have been removed since by default no art (including logos) are
% included in \LaTeX{} documents.
%    \begin{macrocode}
\NewDocumentCommand{\SJGamesOnlinePolicyNotice}{}{%
  \gurps* is a registered trademark of \SteveJacksonGames, and is copyrighted by
  \SteveJacksonGames. All rights are reserved by SJ Games. This material is used
  here in accordance with the SJ Games
  \href{http://www.sjgames.com/general/online_policy.html}{online policy}.
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SJGamesOnlinePolicyGameAid}
% This text is required for all game aid's produced for \textbf{\textit{GURPS}} but without an
% official license. It takes one argument: author name.
%    \begin{macrocode}
\NewDocumentCommand{\SJGamesOnlinePolicyGameAid}{m}{%
  \gurps is a trademark of \SteveJacksonGames, and its rules and art are
  copyrighted by \SteveJacksonGames. All rights are reserved by
  \SteveJacksonGames. This game aid is the original creation of #1 and
  is released for free distribution, and not for resale, under the
  permissions granted in the
  \href{http://www.sjgames.com/general/online_policy.html}%
        {\SteveJacksonGames Online Policy}.
}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\ST}
% Sets the strength of the current character
%    \begin{macrocode}
\NewDocumentCommand{\ST}{m}{\luadirect{_ARGS.ST = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\DX}
% Sets the dexterity of the current character
%    \begin{macrocode}
\NewDocumentCommand{\DX}{m}{\luadirect{_ARGS.DX = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\IQ}
% Sets the IQ of the current character
%    \begin{macrocode}
\NewDocumentCommand{\IQ}{m}{\luadirect{_ARGS.IQ = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\HT}
% Sets the health of the current character
%    \begin{macrocode}
\NewDocumentCommand{\HT}{m}{\luadirect{_ARGS.HT = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\HP}
% Sets the HP of the current character
%    \begin{macrocode}
\NewDocumentCommand{\HP}{m}{\luadirect{_ARGS.HP = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\Per}
% Sets the perception of the current character
%    \begin{macrocode}
\NewDocumentCommand{\Per}{m}{\luadirect{_ARGS.Per = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\Will}
% Sets the will of the current character
%    \begin{macrocode}
\NewDocumentCommand{\Will}{m}{\luadirect{_ARGS.Will = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\FP}
% Sets the FP of the current character
%    \begin{macrocode}
\NewDocumentCommand{\FP}{m}{\luadirect{_ARGS.FP = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\SM}
% Sets the SM of the current character
%    \begin{macrocode}
\NewDocumentCommand{\SM}{m}{\luadirect{_ARGS.SM = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\DR}
% Sets the DR of the current character
%    \begin{macrocode}
\NewDocumentCommand{\DR}{m}{\luadirect{_ARGS.DR = #1}}
%    \end{macrocode}
% \end{macro}

% \begin{environment}{character}
% This environment defines a `character' i.e.~anything with full stats.
%    \begin{macrocode}
\NewDocumentEnvironment{character}{}{%
%    \end{macrocode}
% \changes{v1.00a}{2017/12/04}{Added a spurious change log entry to show what a
% change \emph{within} an environment definition looks like.}
%
% The global lua variable |_ARGS| is created and then populated by commands
% inside the environment.
%    \begin{macrocode}
\luadirect{_ARGS = {
    advantages={},
    disadvantages={},
    skills={},
    spells={}
  }}
}{%
%    \end{macrocode}
% At the end of the environment, the character is initialised printed (via lua's
% |tex.print|).
%    \begin{macrocode}
  \luadirect{character = create_character(_ARGS)}
  \luadirect{print_character()}
}
%    \end{macrocode}
% \end{environment}
%
% \begin{environment}{lens}
% Like |character|, but it's a lens.
%    \begin{macrocode}
\newenvironment{lens}[1]{%
  \luadirect{character = create_character({#1})}%
}{%
  \luadirect{print_character_as_lens()}
}
%    \end{macrocode}
% \end{environment}
%
% \begin{macro}{\advantage}
% Adds an advantage to a character. NOTE: this only works in a |character| or
% |lens| environment.
%    \begin{macrocode}
\NewDocumentCommand{\advantage}{mO{}}{%
  \luadirect{_ARGS.advantages[ [[\unexpanded{#1}]] ] = trait(#2)}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\disadvantage}
% Adds a disadvantage to a character. NOTE: this only works in a |character| or
% |lens| environment.
%    \begin{macrocode}
\NewDocumentCommand{\disadvantage}{mO{}}{%
  \luadirect{_ARGS.disadvantages[ [[\unexpanded{#1}]] ] = trait(#2)}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\levelledadvantage}
% Adds an advantage to a character. NOTE: this only works in a |character| or
% |lens| environment.
%    \begin{macrocode}
% TODO finish this!
\NewDocumentCommand{\levelledadvantage}{mmO{nil}}{%
  \luadirect{_ARGS.advantages[ [[\unexpanded{#1}]] ] = valued_trait(#2, #3)}
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\levelleddisadvantage}
% Adds a disadvantage to a character. NOTE: this only works in a |character| or
% |lens| environment.
%    \begin{macrocode}
\NewDocumentCommand{\levelleddisadvantage}{mmO{nil}}{%
  \luadirect{_ARGS.disadvantages[ [[\unexpanded{#1}]] ] = valued_trait(#2, #3)}
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\skill}
%    \begin{macrocode}
\NewDocumentCommand\skill{mom}{%
  \IfNoValueTF{#2}
  {\luadirect{_ARGS.skills[ [[\unexpanded{#1}]] ] = {value=#3}}}
  {%
    \luadirect{
      _ARGS.skills[ [[\unexpanded{#1}]] ] = {value=#3, difficulty=[[#2]]}
    }
  }
}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\spell}
%    \begin{macrocode}
\NewDocumentCommand\spell{mom}{%
  \IfNoValueTF{#2}
  {\luadirect{_ARGS.spells[ [[\unexpanded{#1}]] ] = {value=#3}}}
  {%
    \luadirect{
      _ARGS.spells[ [[\unexpanded{#1}]] ] = {value=#3, difficulty=[[#2]]}
    }
  }
}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
\endinput
%</package>
%    \end{macrocode}
%\Finale