summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/dox/dox.dtx
blob: 7e2557820e1640a5dbbc401457cd24a5b797d668 (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
% \iffalse                                                 -*- mode: LaTeX -*-
%
% dox.dtx --- Doc file for the DoX package (code and documentation)
%
% Copyright (C) 2009 Didier Verna.
%
% Author:        Didier Verna <didier@lrde.epita.fr>
% Maintainer:    Didier Verna <didier@lrde.epita.fr>
% Created:       Thu Sep 10 21:11:32 2009
% Last Revision: Fri Sep 11 11:20:13 2009
%
% This file is part of DoX.
%
% DoX may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.1
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.1 or later is part of all distributions of LaTeX
% version 1999/06/01 or later.
%
% DoX consists of the files listed in the file `README'.
%
%
% Commentary:
%
% Contents management by FCM version 0.1.
%
%
% Code:
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage{xspace}
\makeatletter
  \def\@currname{dox}
  \def\@currext{inc}
\makeatother
\input{header.inc}
% \OnlyDescription
\CodelineIndex
% \RecordChanges
\begin{document}
\DocInput{dox.dtx}
\end{document}
%</driver>
%
% \fi
%
% \catcode`\¡=14
% \CheckSum{157}
% \GetFileInfo{dox.inc}
%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%
% \MakeShortVerb{\|}
%
% \makeatletter
% \def\ps@mystyle{
%   \def\@oddfoot{\hfil\thepage\hfil}
%   \def\@evenfoot{\hfil\thepage\hfil}
%   \def\@evenhead{\hfil\slshape\leftmark}
%   \def\@oddhead{\slshape\rightmark\hfil}}
% \makeatother
%
% \newcommand\dox{\textsf{DoX}\xspace}
% \newcommand\packagecopyright{%
%   Copyright \copyright{} 2009 Didier Verna}
%
% \pagestyle{mystyle}
% \markright{\hskip-.5\marginparwidth \dox \fileversion{} (\filedate)}
%
% \date{\texttt{\fileversion{} (\filedate)}}
% \title{\dox{} -- \textsf{\textbf Doc}, \textbf only e\textbf Xtended}
% \author{Didier Verna\\
%   \texttt{mailto:didier@lrde.epita.fr}\\
%   \texttt{http://www.lrde.epita.fr/\~{}didier/}}
% \maketitle
%
%
% \begin{abstract}
%   The \texttt{doc} package provides \LaTeX{} developers with means to
%   describe the usage and the definition of new macros and environments.
%   However, there is no simple way to extend this functionality to other
%   items (options or counters for instance). The \texttt{dox} package is
%   designed to circumvent this limitation.
% \end{abstract}
%
% ^^A \tableofcontents
%
% \section{Usage}
% \emph{Note: we assume that you know about \texttt{doc}'s \cs{DescribeMacro},
%   \cs{DescribeEnv} and all other associated commands and environments}.
%
% \medskip\noindent
% \DescribeMacro{\doxitem}\marg{funcsname}\marg{singular}\marg{plural}\\
% The \dox style provides a single user-level command to create new items with
% functionalities equivalent to what \texttt{doc} provides for macros and
% environments. Perhaps the simplest way to describe how it works is to give
% an example. Suppose you would like to describe package options. Here is what
% you need to do:
% \begin{verbatim}
% \usepackage{dox}
% \doxitem{Option}{option}{options}
% \end{verbatim}
% \dox then creates the following API for you:
% \begin{itemize}
% \item \cs{DescribeOption}
% \item the \texttt{option} environment
% \item \cs{PrintDescribeOption}
% \item \cs{PrintOptionName}
% \item \cs{SpecialMainOptionIndex}
% \item \cs{SpecialOptionIndex}
% \end{itemize}
%
% That's about it.
% \StopEventually{\vfill\hfill\small \packagecopyright{}.}
%
% \section{Implementation}
% \subsection{Preamble}
%    \begin{macrocode}
%<dox>\NeedsTeXFormat{LaTeX2e}
%<*header>
\ProvidesPackage{dox}[2009/09/11 v1.0 Extensions to the doc package]

%</header>
%    \end{macrocode}
% \subsection{Real job execution}
% \begin{macro}{\doxm@cro@}
%   \marg{item}\marg{contents}\\
%   In \texttt{doc.sty}, the macro and environment environments go through the
%   \cs{m@cro@} command which implements specific parts by testing a boolean
%   condition as its first argument. This mechanism is not extensible, so I
%   have to hack away a more generic version that would work for any new
%   \texttt{dox} item, only which looks pretty much like the original one:
%    \begin{macrocode}
%<*dox>
\long\def\doxm@cro@#1#2{%
  \endgroup%
  \topsep\MacroTopsep\trivlist
  \def\makelabel##1{\llap{##1}}%
  \if@inlabel
    \let\@tempa\@empty
    \count@\macro@cnt
    \loop\ifnum\count@>\z@
      \edef\@tempa{\@tempa\hbox{\strut}}\advance\count@\m@ne%
    \repeat
    \edef\makelabel##1{%
      \llap{\vtop to\baselineskip
	{\@tempa\hbox{##1}\vss}}}%
    \advance\macro@cnt\@ne
  \else
    \macro@cnt\@ne
  \fi
  \edef\@tempa{%
    \noexpand\item[%
%    \end{macrocode}
% That's the first modification:
%    \begin{macrocode}
      \expandafter\noexpand\csname Print#1Name\endcsname{\string#2}]}%
  \@tempa
  \global\advance\c@CodelineNo\@ne
%    \end{macrocode}
% And that's the second one:
%    \begin{macrocode}
  \@nameuse{SpecialMain#1Index}{#2}\nobreak
  \global\advance\c@CodelineNo\m@ne
  \ignorespaces}

%    \end{macrocode}
% \end{macro}
% \subsection{API creation}
% \begin{macro}{\doxitem}
%   \marg{funcsname}\marg{singular}\marg{plural}
%    \begin{macrocode}
\newcommand\doxitem[3]{%
%    \end{macrocode}
% The \cs{Print}\meta{item}\texttt{Name} macro:
%    \begin{macrocode}
  \@ifundefined{Print#1Name}{%
    \expandafter\def\csname Print#1Name\endcsname##1{%
      \strut\MacroFont\string##1\ }}{}
%    \end{macrocode}
% The \cs{SpecialMain}\meta{item}\texttt{Index} macro:
%    \begin{macrocode}
  \expandafter\def\csname SpecialMain#1Index\endcsname##1{%
    \@bsphack%
    \special@index{%
      ##1\actualchar{\string\ttfamily\space##1} (#2)\encapchar main}%
    \special@index{%
      #3:\levelchar##1\actualchar%
      {\string\ttfamily\space##1}\encapchar main}%
    \@esphack}
%    \end{macrocode}
% The \cs{PrintDescribe}\meta{item} macro:
%    \begin{macrocode}
  \@ifundefined{PrintDescribe#1}{%
    \expandafter\def\csname PrintDescribe#1\endcsname##1{%
      \strut\MacroFont##1\ }}{}
%    \end{macrocode}
% The \cs{Special}\meta{item}\texttt{Index} macro:
%    \begin{macrocode}
  \expandafter\def\csname Special#1Index\endcsname##1{\@bsphack
    \index{##1\actualchar{\protect\ttfamily##1}
      (#2)\encapchar usage}%
    \index{#3:\levelchar##1\actualchar{\protect\ttfamily##1}\encapchar
      usage}\@esphack}
%    \end{macrocode}
% The \cs{Describe@}\meta{item} macro:
%    \begin{macrocode}
  \expandafter\def\csname Describe@#1\endcsname##1{%
    \endgroup
    \marginpar{\raggedleft\@nameuse{PrintDescribe#1}{##1}}%
    \@nameuse{Special#1Index}{##1}\@esphack\ignorespaces}
%    \end{macrocode}
% The \cs{Describe}\meta{item} macro:
%    \begin{macrocode}
  \expandafter\def\csname Describe#1\endcsname{%
    \leavevmode\@bsphack\begingroup\MakePrivateLetters
    \@nameuse{Describe@#1}}
%    \end{macrocode}
% The \meta{item} environment:
%    \begin{macrocode}
  \expandafter\def\csname #2\endcsname{%
    \begingroup
      \catcode`\\12
      \MakePrivateLetters\doxm@cro@{#1}}
  \expandafter\let\csname end#2\endcsname\endtrivlist}

%</dox>
%    \end{macrocode}
% \end{macro}
% ^^A \PrintChanges
% ^^A \PrintIndex
% \Finale
%
% ^^A dox.dtx ends here