2 %<package>\NeedsTeXFormat{LaTeX2e}
5 \def\filedate{2003/11/16}
6 \ProvidesFile{glifaq.drv}
8 %<package>\ProvidesPackage{glifaq}
9 [2003/11/16 Style for PyX FAQ (gli) v0.2]
11 \documentclass{ltxdoc}
16 \newcommand\PyX{P\kern-.3em\lower.5ex\hbox{Y}\kern-.18em X}
17 \newcommand{\acro}[1]{\textsc{#1}}
25 % {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
26 % 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
27 % Digits \0\1\2\3\4\5\6\7\8\9
28 % Exclamation \! Double quote \" Hash (number) \#
29 % Dollar \$ Percent \% Ampersand \&
30 % Acute accent \' Left paren \( Right paren \)
31 % Asterisk \* Plus \+ Comma \,
32 % Minus \- Point \. Solidus \/
33 % Colon \: Semicolon \; Less than \<
34 % Equals \= Greater than \> Question mark \?
35 % Commercial at \@ Left bracket \[ Backslash \\
36 % Right bracket \] Circumflex \^ Underscore \_
37 % Grave accent \` Left brace \{ Vertical bar \|
38 % Right brace \} Tilde \~}
43 % \title{The \texttt{glifaq} package}
45 % \author{Gert-Ludwig Ingold\\\small\url{<gert.ingold@physik.uni-augsburg.de>}}
46 % \date{(v.\fileversion\ -- \filedate)}
49 % \section{Introduction}
50 % The \texttt{glifaq} package has been developed to typeset the \acro{faq} of
51 % the \PyX{} graphics package for \acro{Python}. It might contain a few
52 % commands which are useful for other \acro{faq}s as well.
56 % The package \texttt{glifaq} is intended for use with the \texttt{scrartcl}
57 % class which is part of \acro{KOMA-Script}. \texttt{scrartcl} should therefore
58 % be chosen as document class.
60 % The options of the package \texttt{glifaq} mostly control the kind of
61 % questions which will be typeset. There are three kinds of questions:
64 % |a| & answered question\\
65 % |c| & question where the answer has been checked by an expert\\
66 % |o| & outdated question\\
67 % |t| & question not fully answered yet (= to do)
70 % The following options are recognized by the package:
72 % \item[all] prints all questions
73 % \item[answered] prints only questions which have no ``to do'' status, i.e.
74 % they have a satisfying answer and might even have been checked
75 % \item[checked] prints only questions where the answers have been checked
76 % \item[outdated] prints only questions and answers which are outdated
77 % \item[todo] prints all questions where no satisfying answer has been
79 % \item[unchecked] prints all questions which have not been checked yet
80 % \item[comments] if comments exist, they will be printed as well and a
81 % special mark will be put in the margin
82 % \item[notoc] the table of contents will not be printed
84 % By default, all questions and the table of contents but no comments will be
85 % printed. If questions with ``to do'' status are printed, a special mark will
86 % be put in the margin.
88 % \DescribeMacro\question
89 % The most important task of the package \texttt{glifaq} is to define a command
91 % |\question{|\meta{status}|}{|\meta{title}|}{|\meta{comment}|}{|^^A
94 % to handle the typesetting of questions and their answers. As indicated, this
95 % command takes four arguments:
98 % 1: & class of the question according to the table given above\\
99 % & allowed values: |a|, |c|, |o|, |t|\\
100 % 2: & title of the question\\
101 % 3: & comments related to this question\\
102 % 4: & the answer to the question
106 % \DescribeEnv{progcode}
107 % For the typesetting of code snippets, an environment |progcode| has been
108 % defined which will use a fixed space font. Unfortunately, verbatim code
109 % cannot be used in arguments as is the case here in macro |\question|.
110 % To guarantee proper spaces and in particular indenting, a tilde has to
111 % used instead of a space.
113 % In addition, there exist a few simple definitions which may be useful:
115 % \DescribeMacro\uaref
116 % The macro |\uaref| acts like the usual |\ref| command but puts an $\uparrow$
117 % (|\uparrow|) in front of the reference.
120 % The macro |\toc| replaces the usual |\tableofcontents| to allow for control
121 % via the |notoc| option.
124 % The macro |\PyX| defines the \PyX{} logo as employed by the developers of
125 % \PyX{} in their manual.
128 % In some places, a backslash cannot be used verbatim, in particular in an
129 % argument of the |\question| macro. Using
131 % \verb*+\cs +\meta{command name}
133 % will result in a backslash followed directly by the command name.
136 % The macro |\us| can be used to produce an underscore if there is no more
137 % direct way to do so.
140 % Sometimes it may also be difficult to produce a hat character. In such cases,
141 % |\hat| can be useful.
144 % The last macro of this type is |\cb| which allows to enclose an argument in
147 % \DescribeMacro\ctan
148 % For references to files on \acro{ctan}, the macro |\ctan| can be used where
149 % the single argument should be the location of the file relative to the
151 % \DescribeMacro\ftpCTAN
152 % One of the \acro{ctan} ftp servers is coded into the package via the
153 % |\ftpCTAN| macro for direct reference from the \acro{pdf} version of the
156 % \DescribeMacro\new\DescribeMacro\changed
157 % Finally, the two macros |\new| and |\changed| allow to mark questions as
158 % new or changed with respect to an earlier version of the \acro{faq}. These
159 % macros should be used in the second argument of |\question| just behind the
160 % text defining the title of a question.
162 % \section{The Description of the Package Code}
165 % We first define a few new switches:
167 % \begin{tabular}{ll}
168 % |\if@a|& print answered questions if true\\
169 % |\if@c|& print corrected questions if true\\
170 % |\if@o|& print outdated questions if true\\
171 % |\if@t|& print unanswered or not fully answered questions if true\\
172 % |\ifc@mments|& print comments if true\\
173 % |\ift@c|& insert table of contents if true
176 % By default, we print all questions and the table of contents but no comments.
182 \newif\ifc@mments \c@mmentsfalse
183 \newif\ift@c \t@ctrue
185 % Now we define the various options and set the switches according to the
186 % options' definition given in section~\ref{sec:usage}.
188 \DeclareOption{all}{\@atrue \@ctrue \@otrue \@ttrue}
189 \DeclareOption{answered}{\@atrue \@ctrue \@ofalse \@tfalse}
190 \DeclareOption{checked}{\@afalse \@ctrue \@ofalse \@tfalse}
191 \DeclareOption{outdated}{\@afalse \@cfalse \@otrue \@tfalse}
192 \DeclareOption{todo}{\@afalse \@cfalse \@ofalse \@ttrue}
193 \DeclareOption{unchecked}{\@atrue \@cfalse \@ofalse \@ttrue}
194 \DeclareOption{comments}{\c@mmentstrue}
195 \DeclareOption{notoc}{\t@cfalse}
196 \ProcessOptions\relax
198 % Next, we load some needed packages if they have not been loaded before.
200 \RequirePackage{ifthen}
201 \RequirePackage{remreset}
202 \RequirePackage{pifont}
204 % The following macro will put a large cross in the margin to mark comments or
205 % questions with ``to do'' status.
207 \newcommand{\put@ding}{\mbox{}\marginpar{\Huge\ding{56}}}
210 % Now comes the most important part of this package, the macro |\question|.
211 % This macro has to decide on the basis of the first argument and the
212 % options used with the package whether the current question is to be printed
215 % It is assumed that in the section hierarchy, the question can take the role
216 % of a subsection or a subsubsection. Therefore, a mechanism has to be
217 % provided which tells the question its place in the hierarchy. Independent
218 % of whether the question acts like a subsection or subsubsection, the layout
219 % of the question title should be the one of a subsubsection.
221 % We introduce three switches: |\@printtrue| indicates that the question has
222 % to be printed while |\@margtrue| requests a mark to be put into the margin
223 % to indicate a question with ``to do'' status and |\@outdatedtrue| will mark a
224 % question as outdated.
230 % Below we will need to find out which level a question corresponds to. If the
231 % value of the counter \texttt{question} is not equal to 0, the level is
232 % already known. A value of 1 indicates that the questions are on the level
233 % of a \texttt{subsection} while a value of 2 implies that the questions are
234 % on the \texttt{subsubsection} level. Whenever a new section is started, we
235 % will need to find out the level of the questions in this section. Therefore,
236 % we reset the counter \texttt{question} whenever a new section is started.
238 \newcounter{question}[section]
239 \setcounter{question}{0}
241 % Since we want to set the title of a question always in the fontsize of a
242 % \texttt{subsubsection}, we might need to temporarily change the fontsize
243 % of the \texttt{subsection} title. In order to be able to restore the original
244 % value, we save the value of |\size@subsection| which is used in the
245 % \acro{KOMA-Script} classes to define the fontsize of the \texttt{subsection}
248 \let\save@sizesubsection\size@subsection
251 % Now we are ready to define the |\question| macro. First, defaults are set
252 % not to print the question and not to print a mark in the margin. If the status
253 % of the question corresponds to one asked for by the option passed to the
254 % package, we change the print switch to |\@printtrue|. A ``to do'' question
255 % will in addition ask to print a mark in the margin by setting |\@margtrue|.
257 \newcommand{\question}[4]%
258 {\@printfalse\@margfalse\@outdatedfalse%
259 \ifthenelse{\equal{a}{#1}\and\boolean{@a}}{\@printtrue}{}%
260 \ifthenelse{\equal{c}{#1}\and\boolean{@c}}{\@printtrue}{}%
261 \ifthenelse{\equal{o}{#1}\and\boolean{@o}}{\@printtrue\@outdatedtrue}{}%
262 \ifthenelse{\equal{t}{#1}\and\boolean{@t}}{\@printtrue\@margtrue}{}%
264 % If the \texttt{question} counter has the value 0, we need to determine the
265 % level of the question. The question should at least be on
266 % \texttt{subsubsection} level if not higher. So we first assume it to be
267 % of this level and make corrections later on if necessary. The counter
268 % \texttt{question} is set to a level different from 0 (in this case to a
269 % value of 2 although this is nowhere exploited in the code). This counter
270 % will now be reset not only by a |\section| but also by a |\subsection|.
271 % Finally, we set the command |\questi@n| which will typeset the question title
272 % as \texttt{subsubsection}.
274 % In a second step, we check whether the question is on |\subsection| level
275 % instead of |\subsubsection| level as was assumed before. In this case,
276 % the counter \texttt{question} is set to 1 (again it is only important that
277 % the value is different from 0). This counter should no longer be reset
278 % by a |\subsection| so we remove the corresponding entry from the reset list.
279 % Finally, the command |\questi@n| typesetting the title of the question is
280 % set to |\subsection|.
282 \ifthenelse{\value{question} = 0}{%
283 \setcounter{question}{2}%
284 \@addtoreset{question}{subsection}%
285 \let\questi@n\subsubsection%
286 \ifthenelse{\value{subsection} = 0}%
287 {\setcounter{question}{1}%
288 \@removefromreset{question}{subsection}%
289 \let\questi@n\subsection}%
293 % Now we are ready to typeset the question if this is what the options passed
294 % to the package ask for. Before typesetting the question title, we temporarily
295 % set the fontsize of the |\subsection| title to the fontsize of the
296 % |\subsubsection| just in case we are on the |\subsection| level. |\questi@n|
297 % does the typesetting of the title and a mark is put into the margin if
298 % requested by |\@margtrue|.
300 % After the title, a comment, if present and asked for, is typeset in sans
301 % serif and small fontsize. Finally, the answer, i.e. the contents of argument
305 \let\size@subsection\size@subsubsection
306 \questi@n{#2 \if@outdated\outd@ted\fi}\if@marg\put@ding\else\fi%
307 \let\size@subsection\save@sizesubsection
309 \ifthenelse{\equal{}{#3}}{}
310 {\put@ding{\sffamily\small#3}\par}%
316 % Since it is not possible to use verbatim code in macro arguments, we cannot
317 % typeset code snippets in an answer by using a \texttt{verbatim} environment.
318 % We therefore define the environment \texttt{progcode}. In order to ensure
319 % proper indentation, we make the tilde an active character and define
320 % it as space preceded by a |\strut| so that the space is not ignored.
321 % In addition, several layout parameters are set like a global indentation
322 % of the code and the use of a small fixed space font.
324 \newenvironment{progcode}
325 {\list{}{\leftmargin\parindent\rightmargin\z@}%
332 % To facilitate references preceded by a $\uparrow$ we define |\uaref| which
333 % works like the standard |\ref|.
335 \DeclareRobustCommand\uaref[1]{$\uparrow$\ref{#1}}
337 % The option \texttt{notoc} only works if instead of |\tableofcontents| the
338 % command |\toc| defined here is used.
340 \DeclareRobustCommand\toc[0]{\ift@c\tableofcontents\else\fi}
342 % The definition of the \PyX{} logo is copied from the code used by the \PyX{}
343 % developers in their manual. Here, we also provide the simple string ``PyX''
344 % for use in the \acro{pdf} bookmarks.
346 \DeclareRobustCommand\PyX[0]{\texorpdfstring%
347 {P\kern-.3em\lower.5ex\hbox{Y}\kern-.18em X}{PyX}%
350 % When a backslash character is needed as part of a verbatim command name,
351 % but verbatim code cannot be used, the macro |\cs| can be employed.
352 % Again, we take care of the requirements of the \acro{pdf} bookmarks.
354 \DeclareRobustCommand\cs[1]{%
355 \texorpdfstring{\texttt{\char`\\}}{\textbackslash}#1%
358 % In order to avoid problems with verbatim code, we define |\us| and |\hat|
359 % to produce an underscore and a hat, respectively.
361 \DeclareRobustCommand\us[0]{\texttt{\char`\_}}
362 \DeclareRobustCommand\hat[0]{\texttt{\char`\^}}
364 % The macro |\cb| encloses its argument in curly braces and should be used
365 % when verbatim code does not work.
367 \DeclareRobustCommand\cb[1]{\texttt{\char`\{#1\char`\}}}
369 % For files on \acro{ctan}, we define the macro |\ctan| which is used as follows
371 % |\ctan{|\meta{file location relative to CTAN root}|}|
373 % In order for the link to connect to a \acro{ctan} server, |\ftpCTAN| contains
374 % the URL of one of the \acro{ctan} servers which is chosen quite arbitrarily
375 % and could be replaced by another \acro{ctan} server. Note that we use
376 % |\path| instead of |\url| to avoid that a link is created to the second
377 % argument instead of the first one.
379 \def\ftpCTAN{ftp://ctan.tug.org/tex-archive/}
380 \DeclareRobustCommand\ctan[1]{%
381 \href{\ftpCTAN#1}{\path{CTAN:#1}}%
384 % In order to mark questions as new or changed with respect to a previous
385 % release of the \acro{faq}, we define the macros |\new| and |\changed| which
386 % are intended to be used at the end of the second argument of |\question|.
387 % No output is generated for \acro{pdf} bookmarks.
389 \DeclareRobustCommand\new[0]{\texorpdfstring%
390 {\quad\raisebox{0.3ex}{\fbox{\tiny\normalfont NEW}}}{}
392 \DeclareRobustCommand\changed[0]{\texorpdfstring%
393 {\quad\raisebox{0.3ex}{\fbox{\tiny\normalfont CHANGED}}}{}
396 % Outdated questions should be marked also in the \acro{pdf} bookmarks.
398 \DeclareRobustCommand\outd@ted[0]{\texorpdfstring%
399 {\quad\colorbox{black}{\color{white}\small OUTDATED}}