Debian Codegraph @

texmf-dist/source/latex/gamebook/gamebook.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2011 by Andr\'e Miede, http://www.miede.de
4 % -------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3 or later is part of all distributions of LaTeX
14 % version 2005/12/01 or later.
15 %
16 % \fi
17 %
18 % \iffalse
19 %<*driver>
20 \ProvidesFile{gamebook.dtx}
21 %</driver>
22 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
23 %<package>\ProvidesPackage{gamebook}
24 %<*package>
25 [2011/11/29 v1.0 Style for gamebooks/interactive novels]
26 %</package>
27 %
28 %<*driver>
29 \documentclass{ltxdoc}
30 \usepackage[debug]{gamebook}[2011/11/29]
31 \usepackage{hyperref}
32 \EnableCrossrefs
33 \CodelineIndex
34 \RecordChanges
35 \begin{document}
36 \DocInput{gamebook.dtx}
37 \PrintChanges
38 \PrintIndex
39 \end{document}
40 %</driver>
41 % \fi
42 %
43 % \CheckSum{0}
44 %
45 % \CharacterTable
46 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
47 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
48 % Digits \0\1\2\3\4\5\6\7\8\9
49 % Exclamation \! Double quote \" Hash (number) \#
50 % Dollar \$ Percent \% Ampersand \&
51 % Acute accent \' Left paren \( Right paren \)
52 % Asterisk \* Plus \+ Comma \,
53 % Minus \- Point \. Solidus \/
54 % Colon \: Semicolon \; Less than \<
55 % Equals \= Greater than \> Question mark \?
56 % Commercial at \@ Left bracket \[ Backslash \\
57 % Right bracket \] Circumflex \^ Underscore \_
58 % Grave accent \` Left brace \{ Vertical bar \|
59 % Right brace \} Tilde \~}
60 %
61 %
62 % \changes{v1.0}{2011/06/12}{Initial version}
63 %
64 % \GetFileInfo{gamebook.dtx}
65 %
66 % \DoNotIndex{\newcommand,\newenvironment}
67 %
68 %
69 % \title{The \textsf{gamebook} package\thanks{This document
70 % corresponds to \textsf{gamebook}~\fileversion, dated \filedate.}}
71 % \author{Andr\'e Miede \\ \url{http://www.miede.de}}
72 %
73 % \maketitle
74 %
75 % \section*{Introduction}
76 %
77 % This package provides the means to layout gamebooks with \LaTeX.
78 % If you do not know what a gamebook is, just have a look at the informative
79 % Wikipedia article \url{http://en.wikipedia.org/wiki/Gamebook} or check
80 % out Demian's very good overview website, where you can find tons of information
81 % about gamebooks: \url{http://www.gamebooks.org}.
82 %
83 % A simple gamebook example is included with this package, teaching you how to
84 % use the package in no time.
85 %
86 % If you created a gamebook using this package, please drop me an e-mail
87 % (ideally, send an PDF of the gamebook along). Thanks in advance.
88 %
89 %
90 % \section*{Package Loading}
91 %
92 % You can load the |gamebook| package easily together with the typical
93 % \LaTeX-classes:
94 % \begin{center}
95 % |\usepackage|\oarg{optional arguments}|{gamebook}|
96 % \end{center}
97 % With respect to the \emph{optional arguments}, you have the following ones
98 % available:
99 % \begin{itemize}
100 % \item\texttt{debug}: Print the label ids of the referenced sections each
101 % time you refer to a section.
102 % \item\texttt{draft}: Print drafting information (time etc.) on each page.
103 % \end{itemize}
104 %
105 % The available commands and environments are described in the following.
106 %
107 % \section*{Usage}
108 % \DescribeMacro{\gbsection}
109 % The |\gbsection|\marg{id} macro is the core of the package, defining the different
110 % (numbered) sections of the gamebook. It takes one mandatory argument that
111 % specifies the reference id (just as you would with a |\label| command.
112 %
113 % \DescribeMacro{\gbturn}
114 % \noindent The |\gbturn|\marg{id} macro prints a link to a numbered section of the
115 % gamebook.
116 % It takes one mandatory argument that specifies the reference id of the respective
117 % section (as defined using the |\gbsection| macro). By default, there is a text
118 % before the link: ``turn~to''. You can change this text to your liking by using the
119 % following:
120 % \begin{center}
121 % |\renewcommand{\gbturntext}|\marg{my new text}
122 % \end{center}
123 %
124 % \DescribeEnv{gbturnoptions}
125 % \noindent If there are many options for the reader at the end of one section, you
126 % can use the environment |gbturnoptions| for printing an indented list of these
127 % options. Please note that the items of such a list are declared by using the
128 % \DescribeMacro{\gbitem} |\gbitem| macro.
129 %
130 % \DescribeMacro{\gbvillain}
131 % As in any good gamebook, there is the need for villains and opponents. These are
132 % typeset using the following command:
133 %\begin{center}
134 %|\gbvillain|\marg{villain's name}\marg{skill}\marg{skill level}\marg{life}\marg{life level}
135 %\end{center}
136 %
137 % \DescribeMacro{\gbheader}
138 % In order to have both the first and the last numbered section in the headline of the
139 % page, use the command |\gbheader|. This changes the page style accordingly. It is also
140 % possible to put some text at the opposite side of the header (default ``Gamebook''):
141 %\begin{center}
142 % |\renewcommand{\gbheadtext}|\marg{my new text}
143 %\end{center}
144 %
145 % This is only the formal documentation of the commands, a live example is included with
146 % the package. Please refer to this for details.
147 %
148 % \section*{Todo}
149 % It would be nice to have random figures in the text or fixed figures on a whole left
150 % page (belonging to a certain section on the right page).
151 %
152 % Also, it would be good to customize the layout of sections and references to them
153 % (|\fbox| etc.).
154 %
155 %
156 % \StopEventually{}
157 % \section*{Implementation}
158 % This describes the source code for |gamebook.sty|. The first snippet deals with
159 % the available options and how to process them.
160 % \begin{macrocode}
161 \RequirePackage{ifthen}
162 \newboolean{@debug}
163 \newboolean{@drafting}
164
165 \DeclareOption{debug}{\setboolean{@debug}{true}}
166 \DeclareOption{draft}{\setboolean{@drafting}{true}}
167 \ProcessOptions\relax
168 % \end{macrocode}
169 %
170 % \begin{macro}{\gbheader}
171 % The packages |fancyhdr| and |extramarks| are used to get the headlines
172 % right, i.e., to print both the first and last numbered section for
173 % navigation within the gamebook. |extramarks| is an add-on for
174 % |fancyhdr| providing commands such as |\firstmark| etc.
175 % |\gbheadtext| is printed on the opposite side of the section numbers
176 % and can be changed as shown in the documentation above.
177 % \begin{macrocode}
178 \RequirePackage{fancyhdr}
179 \RequirePackage{extramarks}
180 \newcommand{\gbheadtext}{Gamebook}
181 \newcommand{\gbheader}{%
182 \pagestyle{fancy}%
183 \renewcommand{\sectionmark}[1]{\markboth{\thesection}{\thesection}}%
184 \fancyhead{}% clear all header fields
185 \fancyhead[LO,RE]{\small\gbheadtext}
186 \fancyhead[RO,LE]{\small\ifthenelse{\equal{\firstleftmark}%
187 {\leftmark}}{\leftmark}{\firstleftmark~--~\leftmark}}%
188 %\fancyfoot{} % clear all footer fields
189 }
190 % \end{macrocode}
191 % \end{macro}
192 %
193 %
194 % For debugging purposes, the reference ids of each section or
195 % reference can be printed (using the |debug| option). This command
196 % should only be used internally, |\gbdebugx| for section headers,
197 % printing the reference id in the margin and |\gbdebug| for all
198 % other places.
199 % \begin{macrocode}
200 \newcommand{\gbdebug}[1]{\protect{\ifthenelse{\boolean{@debug}}%
201 {~\texttt{\scriptsize(#1)}}{\relax}}}
202 \newcommand{\gbdebugx}[1]{\protect{\ifthenelse{\boolean{@debug}}%
203 {\marginpar{\texttt{\scriptsize(#1)}}}{\relax}}}
204 % \end{macrocode}
205 %
206 %
207 % \begin{macro}{\gbsection}
208 % The layout of the numbered sections is achieved using the |titlesec|
209 % package. A section then starts with a boxed, bold number. If you would
210 % like to change this, redefine |\titleformat{\section}| accordingly.
211 %
212 % Based on this, the command |\gbsection| is defined, consisting of an
213 % empty, but numbered section that contains a label (which is the
214 % mandatory parameter of |\gbsection|).
215 % \begin{macrocode}
216 \RequirePackage{titlesec}
217 \titleformat{\section}[block]{%
218 \centering\bfseries}{\fbox{\thesection}}{1em}{\relax}
219 \newcommand{\gbsection}[1]{\section{\label{#1}}\gbdebugx{#1}}
220 % \end{macrocode}
221 % \end{macro}
222 %
223 %
224 % \begin{macro}{\gbturn}
225 % References to numbered sections are typeset using |\gbturn|, which puts the
226 % text defined in |\gbturntext| before the reference. Change |\gbturntext|
227 % for having a different or no text before the reference. The layout of these
228 % references can be changed by redefining |\gbturn|.
229 % \begin{macrocode}
230 \newcommand{\gbturntext}{turn~to~}
231 \newcommand{\gbturn}[1]{\gbturntext{\bfseries\ref{#1}}\gbdebug{#1}}%\fbox
232 % \end{macrocode}
233 % \end{macro}
234 %
235 %
236 % \begin{macro}{\gbvillain}
237 % Villains and other kinds of opponents are typeset within a special
238 % tabbing environment.
239 % \begin{macrocode}
240 \newenvironment{gbtabbing}
241 {\setlength{\topsep}{0pt}%
242 \setlength{\tabbingsep}{0pt}%
243 \setlength{\partopsep}{0pt}%
244 \tabbing}%
245 {\endtabbing}
246
247 \newcommand{\gbvillain}[5]{%
248 \hfill\begin{gbtabbing}%
249 \hspace{\parindent}\= Sehr sehr langer Name %
250 \= Sehr langer Skill + Wert \= Sehr langer Skill + Wert \kill%
251 \> \textsc{#1} \> #2~#3 \> #4~#5 \\%
252 \end{gbtabbing}%
253 }%
254 % \end{macrocode}
255 % \end{macro}
256 %
257 %
258 % \begin{environment}{gbturnoptions}
259 % In order to offer multiple options as some kind of itemized list, a
260 % special environment (including a dedicated item macro) is created.
261 % \begin{macrocode}
262 \RequirePackage{enumitem}
263 \newlist{gbturnoptions}{itemize}{1}
264 \setlist[gbturnoptions]{%
265 leftmargin=\parindent,labelindent=\parindent,label=} % noitemsep
266 \newcommand{\gbitem}[2]{\item #1\hfill\gbturn{#2}}
267 % \end{macrocode}
268 % \end{environment}
269 %
270 %
271 % In order to print drafting information on each page (if the option |draft| is
272 % enabled, certain configurations are made here. This is probably not useful
273 % for most users and is likely to be removed in future versions.
274 % \begin{macrocode}
275 \ifthenelse{\boolean{@drafting}}{%
276 \RequirePackage{draftwatermark}%
277 \SetWatermarkLightness{0.9}
278 \SetWatermarkScale{.5}
279 % \SetWatermarkText{\today\ at \thistime}
280 \SetWatermarkText{Draft}
281 \RequirePackage{scrtime} % time access
282 \PassOptionsToPackage{draft}{prelim2e}
283 \RequirePackage{prelim2e}
284 \renewcommand{\PrelimWords}{\relax}
285 \renewcommand{\PrelimText}%
286 {\footnotesize[\,\today\ at \thistime\,]}}{\relax}
287 % \end{macrocode}
288 % That's all, folks.
289 % \Finale
290 \endinput