disable outlines (we do not yet have those)
[PyX/mjg.git] / faq / glifaq.dtx
blobb18a06e2ba7b4b7ffaa2d2b380fe1b9502f80758
1 % \iffalse
2 %<package>\NeedsTeXFormat{LaTeX2e}
3 %<*driver>
4 \def\fileversion{0.2}
5 \def\filedate{2003/11/16}
6 \ProvidesFile{glifaq.drv}
7 %</driver>
8 %<package>\ProvidesPackage{glifaq}
9            [2003/11/16 Style for PyX FAQ (gli) v0.2]
10 %<*driver>
11 \documentclass{ltxdoc}
12 \usepackage{url}
13 \EnableCrossrefs
14 \CodelineIndex
15 \RecordChanges
16 \newcommand\PyX{P\kern-.3em\lower.5ex\hbox{Y}\kern-.18em X}
17 \newcommand{\acro}[1]{\textsc{#1}}
18 \begin{document}
19    \DocInput{glifaq.dtx}
20 \end{document}
21 %</driver>
22 % \fi
24 % \CharacterTable
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         \~}
40 % \CheckSum{229}
43 % \title{The \texttt{glifaq} package}
45 % \author{Gert-Ludwig Ingold\\\small\url{<gert.ingold@physik.uni-augsburg.de>}}
46 % \date{(v.\fileversion\ -- \filedate)}
47 % \maketitle
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.
54 % \section{Usage}
55 % \label{sec:usage}
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. 
59 %  
60 % The options of the package \texttt{glifaq} mostly control the kind of 
61 % questions which will be typeset. There are four kinds of questions:
62 % \begin{center}
63 % \begin{tabular}{ll}
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)
68 % \end{tabular}
69 % \end{center}
70 % The following options are recognized by the package:
71 % \begin{description}
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 
78 %            formulated yet
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
83 % \end{description}
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
90 % \begin{quote}
91 % |\question{|\meta{status}|}{|\meta{title}|}{|\meta{comment}|}{|^^A
92 %    \meta{answer}|}|
93 % \end{quote}
94 % to handle the typesetting of questions and their answers. As indicated, this 
95 % command takes four arguments:
96 % \begin{center}
97 % \begin{tabular}{ll}
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
103 % \end{tabular}
104 % \end{center}
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.
119 % \DescribeMacro\toc
120 % The macro |\toc| replaces the usual |\tableofcontents| to allow for control
121 % via the |notoc| option.
123 % \DescribeMacro\PyX
124 % The macro |\PyX| defines the \PyX{} logo as employed by the developers of 
125 % \PyX{} in their manual.
127 % \DescribeMacro\cs
128 % In some places, a backslash cannot be used verbatim, in particular in an
129 % argument of the |\question| macro. Using
130 % \begin{quote}
131 % \verb*+\cs +\meta{command name}
132 % \end{quote}
133 % will result in a backslash followed directly by the command name.
135 % \DescribeMacro\us
136 % The macro |\us| can be used to produce an underscore if there is no more
137 % direct way to do so.
139 % \DescribeMacro\hat
140 % Sometimes it may also be difficult to produce a hat character. In such cases, 
141 % |\hat| can be useful.
143 % \DescribeMacro\cb
144 % The last macro of this type is |\cb| which allows to enclose an argument in
145 % curly braces.
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 
150 % \acro{ctan} root.
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 
154 % \acro{faq}.
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}
163 % \StopEventually
165 % We first define a few new switches:
166 % \begin{center} 
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
174 % \end{tabular}
175 % \end{center}
176 % By default, we print all questions and the table of contents but no comments.
177 %    \begin{macrocode}
178 \newif\if@a \@atrue
179 \newif\if@c \@ctrue
180 \newif\if@o \@otrue
181 \newif\if@t \@ttrue
182 \newif\ifc@mments \c@mmentsfalse
183 \newif\ift@c \t@ctrue
184 %    \end{macrocode}
185 % Now we define the various options and set the switches according to the
186 % options' definition given in section~\ref{sec:usage}.
187 %    \begin{macrocode}
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
197 %    \end{macrocode}
198 % Next, we load some needed packages if they have not been loaded before. 
199 %    \begin{macrocode}
200 \RequirePackage{ifthen}
201 \RequirePackage{remreset}
202 \RequirePackage{pifont}
203 %    \end{macrocode}
204 % The following macro will put a large cross in the margin to mark comments or
205 % questions with ``to do'' status.
206 %    \begin{macrocode}
207 \newcommand{\put@ding}{\mbox{}\marginpar{\Huge\ding{56}}}
208 %    \end{macrocode}
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
213 % or not.
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. 
225 %    \begin{macrocode}
226 \newif\if@print
227 \newif\if@marg 
228 \newif\if@outdated
229 %    \end{macrocode}
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.
237 %    \begin{macrocode}
238 \newcounter{question}[section]
239 \setcounter{question}{0}
240 %    \end{macrocode}
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} 
246 % title.
247 %    \begin{macrocode}
248 \let\save@sizesubsection\size@subsection
249 %    \end{macrocode}
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|.
256 %    \begin{macrocode}
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}{}%
263 %    \end{macrocode}
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|.
281 %    \begin{macrocode}
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}%
290       {}%
291   }{}
292 %    \end{macrocode}
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 
302 % 4, is typeset.
303 %    \begin{macrocode}
304   \if@print%
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
308    \ifc@mments
309     \ifthenelse{\equal{}{#3}}{}
310     {\put@ding{\sffamily\small#3}\par}%
311    \else\fi
312     #4
313   \else\fi}
314 %    \end{macrocode}  
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.
323 %    \begin{macrocode}
324 \newenvironment{progcode}
325   {\list{}{\leftmargin\parindent\rightmargin\z@}%
326          \ttfamily\small%
327          \catcode`\~=13%
328          \def~{\strut\ }%
329          \item\relax}
330         {\endlist}
331 %    \end{macrocode}
332 % To facilitate references preceded by a $\uparrow$ we define |\uaref| which
333 % works like the standard |\ref|.
334 %    \begin{macrocode}
335 \DeclareRobustCommand\uaref[1]{$\uparrow$\ref{#1}}
336 %    \end{macrocode}
337 % The option \texttt{notoc} only works if instead of |\tableofcontents| the
338 % command |\toc| defined here is used.
339 %    \begin{macrocode}
340 \DeclareRobustCommand\toc[0]{\ift@c\tableofcontents\else\fi}
341 %    \end{macrocode}
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.
345 %    \begin{macrocode}
346 \DeclareRobustCommand\PyX[0]{\texorpdfstring%
347            {P\kern-.3em\lower.5ex\hbox{Y}\kern-.18em X}{PyX}%
348           }
349 %    \end{macrocode}  
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.
353 %    \begin{macrocode}
354 \DeclareRobustCommand\cs[1]{%
355     \texorpdfstring{\texttt{\char`\\}}{\textbackslash}#1%
356     }
357 %    \end{macrocode}
358 % In order to avoid problems with verbatim code, we define |\us| and |\hat|
359 % to produce an underscore and a hat, respectively.
360 %    \begin{macrocode}
361 \DeclareRobustCommand\us[0]{\texttt{\char`\_}}
362 \DeclareRobustCommand\hat[0]{\texttt{\char`\^}}
363 %    \end{macrocode}
364 % The macro |\cb| encloses its argument in curly braces and should be used
365 % when verbatim code does not work.
366 %    \begin{macrocode}
367 \DeclareRobustCommand\cb[1]{\texttt{\char`\{#1\char`\}}}
368 %    \end{macrocode}
369 % For files on \acro{ctan}, we define the macro |\ctan| which is used as follows
370 % \begin{quote}
371 % |\ctan{|\meta{file location relative to CTAN root}|}|
372 % \end{quote}
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.
378 %    \begin{macrocode}
379 \def\ftpCTAN{ftp://ctan.tug.org/tex-archive/}
380 \DeclareRobustCommand\ctan[1]{%
381     \href{\ftpCTAN#1}{\path{CTAN:#1}}%
383 %    \end{macrocode}
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.
388 %    \begin{macrocode}
389 \DeclareRobustCommand\new[0]{\texorpdfstring%
390            {\quad\raisebox{0.3ex}{\fbox{\tiny\normalfont NEW}}}{}
391           }
392 \DeclareRobustCommand\changed[0]{\texorpdfstring%
393            {\quad\raisebox{0.3ex}{\fbox{\tiny\normalfont CHANGED}}}{}
394           }
395 %    \end{macrocode}
396 % Outdated questions should be marked also in the \acro{pdf} bookmarks. 
397 %    \begin{macrocode}
398 \DeclareRobustCommand\outd@ted[0]{\texorpdfstring%
399            {\quad\colorbox{black}{\color{white}\small OUTDATED}}
400                       {~(outdated)}
401           }
402 %    \end{macrocode}
403 % \Finale
404 \endinput