| 1 |
%\iffalse |
| 2 |
%<*dtx> |
| 3 |
\ProvidesFile |
| 4 |
%======================================================================== |
| 5 |
{MAKEBST.DTX} |
| 6 |
%======================================================================== |
| 7 |
%</dtx> |
| 8 |
%% Copyright 1993-2003 Patrick W Daly |
| 9 |
%% Max-Planck-Institut f\"ur Sonnensystemforschung |
| 10 |
%% Max-Planck-Str. 2 |
| 11 |
%% D-37191 Katlenburg-Lindau |
| 12 |
%% Germany |
| 13 |
%% E-mail: [email protected] |
| 14 |
%% |
| 15 |
%% With additions by Arthur Ogawa |
| 16 |
%% E-mai: [email protected] |
| 17 |
%% |
| 18 |
%% This program can be redistributed and/or modified under the terms |
| 19 |
%% of the LaTeX Project Public License Distributed from CTAN |
| 20 |
%% archives in directory macros/latex/base/lppl.txt; either |
| 21 |
%% version 1 of the License, or any later version. |
| 22 |
%% |
| 23 |
%% This is a contributed file to the LaTeX2e system. |
| 24 |
%% ------------------------------------------------- |
| 25 |
% This is a (La)TeX program that generates docstrip batch jobs |
| 26 |
% that may be used to produce customized bibliographic style files. |
| 27 |
% Docstrip options available: |
| 28 |
% program - to generate the program file, makebst.tex |
| 29 |
% optlist - (with program) to list unused options in .dbj file |
| 30 |
% optverbose - (with program and optlist) to add verbose comments to .dbj file |
| 31 |
% driver - to produce a LaTeX2e driver file to print the documentation |
| 32 |
% Installation: |
| 33 |
% LaTeX this file: ==> docstrip installation file makebst.ins |
| 34 |
% AND the (LaTeX2e) documentation |
| 35 |
% (La)TeX makebst.ins: ==> `program' file makebst.tex |
| 36 |
% (makebst.ins may be edited as needed) |
| 37 |
%------------------------------------------------------------------- |
| 38 |
%<program>\def\ProvidesFile#1 [#2 #3 #4]{\def\filename{#1}% |
| 39 |
%<program> \def\fileversion{#3}\def\filedate{#2}} |
| 40 |
%<*program> |
| 41 |
%\fi |
| 42 |
\ProvidesFile{makebst} |
| 43 |
[2003/09/08 4.1 (PWD, AO)] |
| 44 |
%\iffalse |
| 45 |
% Here follows abbreviated usage description for the stripped version |
| 46 |
% This file is to be run under TeX (or even LaTeX) |
| 47 |
% It interactively asks questions about the bibliographic style file |
| 48 |
% that you want to produce. When it is finished, it writes a docstrip |
| 49 |
% driver file that produces that .bst file from the generic .mbs that |
| 50 |
% you specified; optionally, it will call the docstrip run immediately. |
| 51 |
% For details, read the documentation in the source file makebst.dtx. |
| 52 |
%-------------------------------------------------------------------- |
| 53 |
%</program> |
| 54 |
%\fi |
| 55 |
% \changes{1.0}{1993 Aug 17}{Initial version} |
| 56 |
% \changes{1.1}{1994 May 25}{Change extensions to avoid \LaTeXe\ conflicts} |
| 57 |
% \changes{2.0}{1994 Jul 01}{Update documentation to \LaTeXe} |
| 58 |
% \changes{2.1}{1994 Dec 29}{Add the \texttt{optlist} option} |
| 59 |
% \changes{2.1}{1995 Jan 2}{Read \texttt{.opt} file only exceptionally} |
| 60 |
% \changes{3.0}{1995 Mar 15}{Allow \texttt{.mbs} files more freedom, to |
| 61 |
% include other files, for example} |
| 62 |
% \changes{3.1}{1997 Apr 29}{Conform (optionally) to \texttt{docstrip} 2.4g} |
| 63 |
% \changes{3.2}{1999 Feb 24}{Update copyright notice} |
| 64 |
% \changes{4.0}{1999 Jul 20}{AO: show all choices in output file} |
| 65 |
% \changes{4.1}{2003 Sep 8}{PWD: Conform to \texttt{docstrip} 2.4} |
| 66 |
% |
| 67 |
% \CheckSum{698} |
| 68 |
% \CharacterTable |
| 69 |
% {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 |
| 70 |
% 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 |
| 71 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 72 |
% Exclamation \! Double quote \" Hash (number) \# |
| 73 |
% Dollar \$ Percent \% Ampersand \& |
| 74 |
% Acute accent \' Left paren \( Right paren \) |
| 75 |
% Asterisk \* Plus \+ Comma \, |
| 76 |
% Minus \- Point \. Solidus \/ |
| 77 |
% Colon \: Semicolon \; Less than \< |
| 78 |
% Equals \= Greater than \> Question mark \? |
| 79 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 80 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 81 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 82 |
% Right brace \} Tilde \~} |
| 83 |
% |
| 84 |
%\iffalse |
| 85 |
%<*install> |
| 86 |
%^^A ============================================= |
| 87 |
%^^A Here is the docstrip installation file |
| 88 |
%^^A It is written on first LaTeX run |
| 89 |
%^^A ============================================= |
| 90 |
\begin{filecontents}{makebst.ins} |
| 91 |
% Simply TeX or LaTeX this file to extract various files from |
| 92 |
% the source file `makebst.dtx' |
| 93 |
|
| 94 |
% This installation file works with docstrip 2.4 or later. |
| 95 |
|
| 96 |
\input docstrip |
| 97 |
|
| 98 |
\preamble |
| 99 |
============================================= |
| 100 |
IMPORTANT NOTICE: |
| 101 |
This is a generated file. |
| 102 |
|
| 103 |
It is subject to the same copyright conditions (see below) |
| 104 |
as in the original file: \inFileName. |
| 105 |
It may not be distributed without \inFileName. |
| 106 |
|
| 107 |
Full documentation can be obtained by LaTeXing that original file. |
| 108 |
Only a few abbreviated comments remain here to describe the usage. |
| 109 |
============================================= |
| 110 |
\endpreamble |
| 111 |
\postamble |
| 112 |
<<<<< End of generated file <<<<<< |
| 113 |
\endpostamble |
| 114 |
\keepsilent |
| 115 |
\askforoverwritefalse |
| 116 |
|
| 117 |
\generate{\file{makebst.tex}{\from{makebst.dtx}{program,% |
| 118 |
% Three variants on makebst.tex; select following options. |
| 119 |
% 1. the .dbj file contains by default only the list of selected options |
| 120 |
% (Select none of the following) |
| 121 |
% 2. the .dbj file contains by default a list of all offered options, |
| 122 |
% with the non-selected ones commented out, add next option. |
| 123 |
optlist,% |
| 124 |
% 3. as above but with full comments added for each option, add next option. |
| 125 |
% optverbose% |
| 126 |
}}} |
| 127 |
|
| 128 |
\preamble |
| 129 |
============================================ |
| 130 |
This is the driver file to produce the LaTeX documentation |
| 131 |
from the original source file \inFileName. |
| 132 |
|
| 133 |
Make changes to it as needed. (Never change the file \inFileName!) |
| 134 |
============================================ |
| 135 |
\endpreamble |
| 136 |
\postamble |
| 137 |
|
| 138 |
End of documentation driver file. |
| 139 |
\endpostamble |
| 140 |
|
| 141 |
\generate{\file{makebst.drv}{\from{makebst.dtx}{driver}}} |
| 142 |
\endbatchfile |
| 143 |
|
| 144 |
\obeyspaces |
| 145 |
\Msg{******************************************}% |
| 146 |
\Msg{* For documentation, process makebst.dtx *}% |
| 147 |
\Msg{* or the driver file makebst.drv *}% |
| 148 |
\Msg{******************************************} |
| 149 |
\end{filecontents} |
| 150 |
%</install> |
| 151 |
%<*driver> |
| 152 |
\NeedsTeXFormat{LaTeX2e} |
| 153 |
\documentclass{ltxdoc} |
| 154 |
%<driver>%\EnableCrossrefs %Comment out when .ind file ready |
| 155 |
\DisableCrossrefs %May stay; zapped by \EnableCrossrefs |
| 156 |
%<driver>%\RecordChanges %Comment out when .gls file ready |
| 157 |
%<driver>%\CodelineIndex %Comment out when .ind file ready |
| 158 |
\CodelineNumbered %May stay |
| 159 |
%<driver>%\OnlyDescription |
| 160 |
\begin{document} |
| 161 |
\DocInput{makebst.dtx} |
| 162 |
\end{document} |
| 163 |
%</driver> |
| 164 |
%\fi |
| 165 |
% |
| 166 |
% \DoNotIndex{\begin,\CodelineIndex,\CodelineNumbered,\def,\DisableCrossrefs} |
| 167 |
% \DoNotIndex{\DocInput,\documentclass,\EnableCrossrefs,\end,\GetFileInfo} |
| 168 |
% \DoNotIndex{\NeedsTeXFormat,\OnlyDescription,\RecordChanges,\usepackage} |
| 169 |
% \DoNotIndex{\ProvidesClass,\ProvidesPackage,\ProvidesFile,\RequirePackage} |
| 170 |
% \DoNotIndex{\LoadClass,\PassOptionsToClass,\PassOptionsToPackage} |
| 171 |
% \DoNotIndex{\DeclareOption,\CurrentOption,\ProcessOptions,\ExecuteOptions} |
| 172 |
% \DoNotIndex{\AtEndOfClass,\AtEndOfPackage,\AtBeginDocument,\AtEndDocument} |
| 173 |
% \DoNotIndex{\InputIfFileExists,\IfFileExists,\ClassError,\PackageError} |
| 174 |
% \DoNotIndex{\ClassWarning,\PackageWarning,\ClassWarningNoLine} |
| 175 |
% \DoNotIndex{\PackageWarningNoLine,\ClassInfo,\PackageInfo,\MessageBreak} |
| 176 |
% \DoNotIndex{\space,\protect,\DeclareRobustCommand,\CheckCommand} |
| 177 |
% \DoNotIndex{\newcommand,\renewcommand,\providecommand,\newenvironment} |
| 178 |
% \DoNotIndex{\renewenvironment,\newif,\newlength,\newcounter,\setlength} |
| 179 |
% \DoNotIndex{\setcounter,\if,\ifx,\ifcase,\ifnum,\ifdim,\else,\fi} |
| 180 |
% \DoNotIndex{\texttt,\textbf,\textrm,\textsl,\textsc} |
| 181 |
% \DoNotIndex{\textup,\textit,\textmd,\textsf,\emph} |
| 182 |
% \DoNotIndex{\ttfamily,\rmfamily,\sffamily,\mdseries,\bfseries,\upshape} |
| 183 |
% \DoNotIndex{\slshape,\scshape,\itshape,\em,\LaTeX,\LaTeXe} |
| 184 |
% \DoNotIndex{\filename,\fileversion,\filedate,\let,\empty} |
| 185 |
% \DoNotIndex{\%,\(,\),\{,\},\@,\@@end,\^,\batchfile,\begingroup,\catcode} |
| 186 |
% \DoNotIndex{\closein,\closeout,\csname,\day,\divide,\edef,\endcsname} |
| 187 |
% \DoNotIndex{\endgroup,\endinput,\endpostamble,\endpreamble,\expandafter} |
| 188 |
% \DoNotIndex{\from,\gdef,\generateFile,\generate,\global,\hours,\ifeof,\immediate} |
| 189 |
% \DoNotIndex{\input,\keepsilent,\loop,\month,\multiply,\newcount} |
| 190 |
% \DoNotIndex{\newlinechar,\newread,\newwrite,\number,\openin,\openout} |
| 191 |
% \DoNotIndex{\or,\par,\postamble,\preamble,\read,\relax,\repeat,\string} |
| 192 |
% \DoNotIndex{\temp,\time,\undefined,\write,\year} |
| 193 |
% \DoNotIndex{\advance,\today,\minutes,\aftergroup,\askforoverwrite} |
| 194 |
% \DoNotIndex{\endbatchfile} |
| 195 |
% |
| 196 |
% \setcounter{IndexColumns}{2} |
| 197 |
% \setlength{\IndexMin}{10cm} |
| 198 |
% \setcounter{StandardModuleDepth}{1} |
| 199 |
% |
| 200 |
% \GetFileInfo{makebst} |
| 201 |
% \newcommand\theprog{\texttt{\filename}} |
| 202 |
% |
| 203 |
% \title{\bfseries Customizing Bibliographic Style Files} |
| 204 |
% |
| 205 |
% \author{Patrick W. Daly} |
| 206 |
% |
| 207 |
% \date{This paper describes program \theprog\\ |
| 208 |
% version \fileversion{} from \filedate |
| 209 |
% \thanks{Work on \texttt{custom-bib}~4.00 was supported by the |
| 210 |
% American Physical Society}\\[1ex] |
| 211 |
% (including additions by Arthur Ogawa, \texttt{[email protected]}) |
| 212 |
% } |
| 213 |
% |
| 214 |
% \maketitle |
| 215 |
% |
| 216 |
%^^A In order to keep all marginal notes on the one (left) side: |
| 217 |
%^^A (otherwise they switch sides disastrously with twoside option) |
| 218 |
% \makeatletter \@mparswitchfalse \makeatother |
| 219 |
% |
| 220 |
% \pagestyle{myheadings} |
| 221 |
% \markboth{P. W. DALY}{CUSTOMIZING BIBLIOGRAPHIES} |
| 222 |
% |
| 223 |
% \newcommand{\btx}{\textsc{Bib}\TeX} |
| 224 |
% \newcommand{\dtx}{\textsf{docstrip}} |
| 225 |
% |
| 226 |
% \parskip=1ex \parindent=0pt |
| 227 |
% |
| 228 |
% \section{Introduction} |
| 229 |
% This \TeX{} program is meant to be used together with generic |
| 230 |
% bibliographic style files to produce customized \texttt{.bst} files for |
| 231 |
% running with \btx. The generic, or master file, can be processed by |
| 232 |
% \dtx{} with selected options to achieve the desired bibliographic |
| 233 |
% style. To this end, a \dtx{} batch job should be made up. |
| 234 |
% However, because of the large number of options available, an |
| 235 |
% interactive, dialogue system would be more convenient. |
| 236 |
% |
| 237 |
% This program, \theprog, accomplishes this goal. |
| 238 |
% It defines macros to establish such a \dtx{} batch job file, and |
| 239 |
% to organize a menu of options. The menu information is contained, |
| 240 |
% however, in the master file itself, since the two are intimately related. |
| 241 |
% Thus different master files with totally different option structures may |
| 242 |
% be accommodated. |
| 243 |
% |
| 244 |
% The batch job could in fact be made up with an editor without calling |
| 245 |
% \theprog, but this program does simplify the task. |
| 246 |
% |
| 247 |
% Incidentally, the \dtx{} run can only be carried out by means of |
| 248 |
% a batch job. Running \dtx{} interactively inserts default pre- and |
| 249 |
% postambles in the text, the latter including an |\endinput| command that |
| 250 |
% \btx{} will not understand. |
| 251 |
% |
| 252 |
% \section{The Master File} |
| 253 |
% The master file is a \btx{} bibliographic style file containing |
| 254 |
% alternative coding depending on \dtx{} options. The options are |
| 255 |
% selected when \dtx{} is run, either interactively or through a |
| 256 |
% batch job. |
| 257 |
% |
| 258 |
% Suppose that one of the options is called \texttt{xyz}. Then the following |
| 259 |
% alternatives are possible: |
| 260 |
% \begin{quote} |
| 261 |
% |%<xyz> | \em one line of coding |
| 262 |
% \end{quote} |
| 263 |
% \emph{includes} the single line of coding; |
| 264 |
% \begin{quote} |
| 265 |
% |%<!xyz> | \em one line of coding |
| 266 |
% \end{quote} |
| 267 |
% \emph{excludes} the single line; |
| 268 |
% \begin{quote} |
| 269 |
% |%<*xyz> | \\ |
| 270 |
% \emph{several lines of coding}\\ |
| 271 |
% |%</xyz> | |
| 272 |
% \end{quote} |
| 273 |
% \emph{includes} all the bracketed lines; |
| 274 |
% \begin{quote} |
| 275 |
% |%<*!xyz> | \\ |
| 276 |
% \emph{several lines of coding}\\ |
| 277 |
% |%</!xyz> | |
| 278 |
% \end{quote} |
| 279 |
% \emph{excludes} all the bracketed lines. |
| 280 |
% |
| 281 |
% Options may be logically combined: the symbol \verb!|! is a logical |
| 282 |
% \textsf{or}, |&| a logical \textsf{and}, |!| a logical \textsf{not}; |
| 283 |
% parentheses \texttt{(} and \texttt{)} may be used to group options. |
| 284 |
% |
| 285 |
% \subsection{Using with \dtx} |
| 286 |
% (The \dtx\ command syntax shown here is that for version~2.4 and later, |
| 287 |
% released December, 1996.) |
| 288 |
% |
| 289 |
% In order to generate a true \btx{} style file with selected options from |
| 290 |
% the master file, it is necessary to run a \dtx{} batch job. |
| 291 |
% Suppose that the master file is named \texttt{master.mbs}, the |
| 292 |
% resulting \btx{} style file is to be \texttt{silly.bst}, and the batch job |
| 293 |
% file itself is called \texttt{silly.dbj}. To produce this with options, say, |
| 294 |
% \texttt{xyz} and \texttt{abc}, the batch job would look something like: |
| 295 |
% \begin{quote}\begin{verbatim} |
| 296 |
% \input docstrip |
| 297 |
% |
| 298 |
% \preamble |
| 299 |
% This is for Journal of Silly Results |
| 300 |
% \endpreamble |
| 301 |
% |
| 302 |
% \postamble |
| 303 |
% End of customized bst file |
| 304 |
% \endpostamble |
| 305 |
% |
| 306 |
% \keepsilent |
| 307 |
% |
| 308 |
% \askforoverwritefalse |
| 309 |
% |
| 310 |
% \generate{\file{silly.bst}{\from{master.mbs}{xyz,abc}}} |
| 311 |
% \endbatchfile |
| 312 |
% \end{verbatim} |
| 313 |
% \end{quote} |
| 314 |
% A preamble is not necessary, although it is advisable to include some |
| 315 |
% statement about the application of the bibliographic style. A postamble |
| 316 |
% \emph{is} vital, otherwise the default will add |\endinput| at the end |
| 317 |
% of the file, something that \btx{} will not understand. The |\keepsilent| |
| 318 |
% is optional and just suppresses \dtx{} output during processing. |
| 319 |
% Similarly the |\askforoverwritefalse| suppresses the warning that a file of |
| 320 |
% the same name is to be overwritten. |
| 321 |
% |
| 322 |
% \subsection{The Menu File} |
| 323 |
% This program, \theprog, simplifies the creation of the batch job file. To |
| 324 |
% do that, it needs information on the available options. This information |
| 325 |
% must be stored in a special format, in the master file itself. |
| 326 |
% Alternatively, that information may be extracted and stored in a file |
| 327 |
% with the same root name but extension \texttt{.opt}. \textsl{This feature |
| 328 |
% is not recommended since it can lead to inconsistencies!} |
| 329 |
% The format of the menu information is illustrated below in |
| 330 |
% Section~\ref{sec:menu}. |
| 331 |
% |
| 332 |
% In the master file, this information must be enclosed within \dtx{} |
| 333 |
% options |%<*options>| \dots\ |%</options>| and \emph{must} be ended by an |
| 334 |
% |\endoptions| command. It may also include any number of comments. |
| 335 |
% The rest of the file must be enclosed within |%<*!options>| \dots\ |
| 336 |
% |%</!options>| to exclude it when the menu information is extracted |
| 337 |
% with \dtx. |
| 338 |
% |
| 339 |
% A sample menu in the master file to select one or none of options |
| 340 |
% \texttt{xyz} \emph{or} \texttt{zyx} would look thus: |
| 341 |
% \begin{quote}\begin{verbatim} |
| 342 |
% %<*options> |
| 343 |
% \mes{Select one of these} |
| 344 |
% \optdef{f}{xyz}{Option forword}{to do forward stuff} |
| 345 |
% \optdef{r}{zyx}{Option reverse}{to do reverse stuff} |
| 346 |
% \optdef{*}{}{None of the above}{} |
| 347 |
% \getans |
| 348 |
% \endoptions |
| 349 |
% %</options> |
| 350 |
% %<*!options> |
| 351 |
% . . . . . . |
| 352 |
% %</!options> |
| 353 |
% \end{verbatim} |
| 354 |
% \end{quote} |
| 355 |
% An explanation of these commands is to be found in Section~\ref{sec:menu}. |
| 356 |
% |
| 357 |
% The menu information may be extracted from the master file by means of |
| 358 |
% \dtx{} and stored in a file with extension \texttt{.opt}. If this |
| 359 |
% file is present, \theprog{} offers to read it instead of the master file, |
| 360 |
% although this is \emph{not} recommended, as explained above. |
| 361 |
% |
| 362 |
% |
| 363 |
% \section{The Program \protect\theprog} |
| 364 |
% |
| 365 |
% \subsection{Installing \protect\theprog} |
| 366 |
% |
| 367 |
% The \theprog\ program comes as a documented source file named |
| 368 |
% \theprog\texttt{.dtx}, which needs to be processed by \dtx\ to extract the |
| 369 |
% actual `program' file \theprog\texttt{.tex}. The easiest way to do this is |
| 370 |
% simply to process the installation batch file \theprog\texttt{.ins} with |
| 371 |
% \TeX\ or \LaTeX, as |
| 372 |
% \begin{quote} |
| 373 |
% \texttt{tex} \theprog\texttt{.ins}\\ |
| 374 |
% \hspace*{2em} or\\ |
| 375 |
% \texttt{latex} \theprog\texttt{.ins} |
| 376 |
% \end{quote} |
| 377 |
% |
| 378 |
% There are in fact three variants of \theprog\ that may be extracted: the |
| 379 |
% basic one lists by default only those options that have been selected; the |
| 380 |
% more refined one (and the default) lists all options offered with the |
| 381 |
% rejected ones commented out; the third version also adds more detailed |
| 382 |
% comments. Even in the first two versions, the user will be asked |
| 383 |
% interactively if s/he wants the additional features of the others. |
| 384 |
% |
| 385 |
% One can select the variant by editing \theprog\texttt{.ins}. |
| 386 |
% |
| 387 |
% Another choice that can be made is whether the \texttt{.dbj} files are to |
| 388 |
% conform to \dtx\ version~2.4 syntax or not. By default, |
| 389 |
% \theprog\texttt{.ins} tests the current version and automatically |
| 390 |
% configures \theprog\texttt{.tex} to write the correct syntax. This too may |
| 391 |
% be overridden by editing \theprog\texttt{.ins}. (Note that the older syntax |
| 392 |
% is still understood by the newer version of \dtx.) |
| 393 |
% |
| 394 |
% Reminder: the older syntax requires |\def\batchfile|\marg{filename} as |
| 395 |
% the first line in a \dtx\ batch job, where \emph{filename} is the name of |
| 396 |
% the batch file itself. The newer syntax does not need this line, but |
| 397 |
% requires |\endbatchfile| at the very end instead. The advantage of the new |
| 398 |
% syntax is that one can edit and rename such a file without having to change |
| 399 |
% its name in the first line. The old syntax leads to great frustration if |
| 400 |
% one forgets to change \emph{filename}. |
| 401 |
% |
| 402 |
% Another difference in the syntaxes (actually introduced in version~2.3 in |
| 403 |
% June, 1996) is the use of the command |\generate| instead of |
| 404 |
% |\generateFile|. Its advantage is that it permits multiple files to be |
| 405 |
% extracted in one pass, something that is not exploited at all by \theprog. |
| 406 |
% |
| 407 |
% \subsection{Running \protect\theprog} |
| 408 |
% This is actually a \TeX{} program, although it will also run under \LaTeX. |
| 409 |
% In that sense, it is like \dtx{} itself. |
| 410 |
% Thus run the program with (something like) |
| 411 |
% \begin{quote} |
| 412 |
% \texttt{tex} \theprog\\ |
| 413 |
% \hspace*{2em} or\\ |
| 414 |
% \texttt{latex} \theprog |
| 415 |
% \end{quote} |
| 416 |
% |
| 417 |
% The program first asks for the name of the master file. This is |
| 418 |
% the file containing all possible bibliographic style commands, with |
| 419 |
% \dtx{} options for selective output. A default name is offered, as well |
| 420 |
% as a default extension (\texttt{.mbs}). |
| 421 |
% |
| 422 |
% Next, the program asks for the name of the output file, the \texttt{.bst} |
| 423 |
% file. The extension here is optional, defaulting to \texttt{.bst}. This name |
| 424 |
% also determines the name of the batch job file, which will have the same |
| 425 |
% root name with the extension \texttt{.dbj}, for the \emph{\dtx{} batch job}. |
| 426 |
% |
| 427 |
% The actual interrogation then begins. All the information for the menus |
| 428 |
% is contained in the master bibliographic style file. The reason for this |
| 429 |
% is that the menu information must conform to the available options in the |
| 430 |
% master file, so it makes sense that one file should contain both. The |
| 431 |
% master file is only read up to the |\endoptions| command. |
| 432 |
% |
| 433 |
% Finally, the batch job file is closed, and the user is asked if it should |
| 434 |
% be run. If he does not take up this |
| 435 |
% offer, or if he later edits the batch job, then it may be run manually |
| 436 |
% with (something like) |
| 437 |
% \begin{quote}\texttt{tex} \emph{bstname}\texttt{.dbj}\end{quote} |
| 438 |
% |
| 439 |
% |
| 440 |
% \section{The Menu Information\label{sec:menu}} |
| 441 |
% The set of questions in the interrogation must fit the available |
| 442 |
% options in the master file. For this reason, the menu information is |
| 443 |
% contained in the master file itself. The program \theprog{} supplies the |
| 444 |
% macros that are used in the menu file to simplify writing and processing |
| 445 |
% menu information. |
| 446 |
% |
| 447 |
% \DescribeMacro{\mes} |
| 448 |
% To print a message to the terminal, use |\mes|\marg{text}. A new line |
| 449 |
% may be forced within \emph{text} by means of |^^J|. |
| 450 |
% |
| 451 |
% \DescribeMacro{\ask} |
| 452 |
% To interrogate the user for a response, use |\ask{\|\emph{com}|}|\marg{text}, |
| 453 |
% which writes \emph{text} to the terminal, and puts the |
| 454 |
% response in the command |\|\emph{com}. |
| 455 |
% |
| 456 |
% \DescribeMacro{\optdef} |
| 457 |
% Almost all interrogations will consist of a list of mutually exclusive |
| 458 |
% options, one of which is the default. For each item in the list, one must |
| 459 |
% specify the keyboard response that is to select it, the actual name of |
| 460 |
% the \dtx{} option that realizes it, and two pieces of explanatory |
| 461 |
% text. For example, |
| 462 |
% \begin{quote} |
| 463 |
% |\optdef{a}{abr}{Abbreviations}{of such words}| |
| 464 |
% \end{quote} |
| 465 |
% means that \texttt{abr} is the true \dtx{} option name that is |
| 466 |
% selected by typing \texttt{a}. The two explanatory texts are written to the |
| 467 |
% terminal immediately as part of the menu, but only the first text is |
| 468 |
% echoed when the selection is made (for confirmation) and is also written |
| 469 |
% to the batch job file (as comment). |
| 470 |
% |
| 471 |
% The default option must have the response |*|. |
| 472 |
% |
| 473 |
% A menu is written to the terminal, first with a |\mes| command to state |
| 474 |
% the subject matter, and then with a sequence of |\optdef| statements, |
| 475 |
% each of which also writes the texts to the terminal. |
| 476 |
% \DescribeMacro{\getans} |
| 477 |
% The response is then read in and processed with |\getans|, which writes |
| 478 |
% the reply to the command |\ans| and writes the appropriate \dtx{} |
| 479 |
% option to the batch job file. If the response does not correspond to any |
| 480 |
% of those in the menu list, it is set to {\tt*}; if there is no {\tt*} |
| 481 |
% in the list, then |\ans| is set to the last entry. The command |\ans| |
| 482 |
% is still available afterwards for any extra testing that might be needed. |
| 483 |
% |
| 484 |
% An example menu appears as follows: |
| 485 |
% \begin{quote}\begin{verbatim} |
| 486 |
% \mes{^^JJOURNAL VOLUME NUMBER:} |
| 487 |
% \optdef{*}{}{Volume plain}{as vol(num)} |
| 488 |
% \optdef{i}{vol-it}{Volume italic}% |
| 489 |
% {as {\string\em\space vol}(num)} |
| 490 |
% \optdef{b}{vol-bf}{Volume bold}% |
| 491 |
% {as {\string\bf\space vol}(num)} |
| 492 |
% \optdef{d}{vol-2bf}{Volume and number bold}% |
| 493 |
% {as {\string\bf\space vol(num)}} |
| 494 |
% \getans |
| 495 |
% \end{verbatim} |
| 496 |
% \end{quote} |
| 497 |
% |
| 498 |
% \DescribeMacro{\beginoptiongroup} |
| 499 |
% Further structure for the interrogation is provided by the |
| 500 |
% |\beginoptiongroup| \dots |\endoptiongroup| sequence, |
| 501 |
% which should act as a container for the |\mes| \dots |
| 502 |
% |\optdef| \dots |\getans| commands described above. |
| 503 |
% For example: |
| 504 |
% \begin{quote} |
| 505 |
% \begin{verbatim} |
| 506 |
% \beginoptiongroup{JOURNAL VOLUME NUMBER:}{} |
| 507 |
% \optdef{*}{}{Volume plain}{as vol(num)} |
| 508 |
% \optdef{i}{vol-it}{Volume italic}% |
| 509 |
% {as {\string\em\space vol}(num)} |
| 510 |
% \optdef{b}{vol-bf}{Volume bold}% |
| 511 |
% {as {\string\bf\space vol}(num)} |
| 512 |
% \optdef{d}{vol-2bf}{Volume and number bold}% |
| 513 |
% {as {\string\bf\space vol(num)}} |
| 514 |
% \getans |
| 515 |
% \endoptiongroup |
| 516 |
% \end{verbatim} |
| 517 |
% \end{quote} |
| 518 |
% presents the same effect as the previous example. |
| 519 |
% The virtue of the option group is in providing a single markup for all |
| 520 |
% interrogations and having a consistent appearance in the generated file. |
| 521 |
% |
| 522 |
% This feature has been added with version~4.0 of \theprog. |
| 523 |
% |
| 524 |
% |
| 525 |
% \section{More Complex Batch Jobs} |
| 526 |
% Version 3.0 of \theprog{} allows the master file to define more |
| 527 |
% sophisticated batch jobs, such as additional master files with their own |
| 528 |
% options. This is made possible because the options are not written |
| 529 |
% directly in the |\generate| command, as in earlier versions, but to a |
| 530 |
% command |\MBopts|. The batch file then contains something like: |
| 531 |
% \begin{quote} |
| 532 |
% |\def\MBopts{\from|\marg{source.ext}|{%|\\ |
| 533 |
% \hspace*{1em}\emph{lines from menu session}\\ |
| 534 |
% | }}|\\ |
| 535 |
% |\generate{\file|\marg{output.ext}|{\MBopts}}| |
| 536 |
% \end{quote} |
| 537 |
% |
| 538 |
% Normally the \emph{lines from menu session} contain just the \dtx{} |
| 539 |
% options. However, the master file could add other things to the |
| 540 |
% definition of |\MBopts|, even closing it and starting a new definition. |
| 541 |
% It just has to make sure that the braces are balanced. |
| 542 |
% |
| 543 |
% \DescribeMacro{\MBaskfile} |
| 544 |
% A number a macros are provided, which are used by \theprog{} itself, to |
| 545 |
% simplify making complex menus. To ask for the name of a file |
| 546 |
% interactively, |
| 547 |
% \begin{quote} |
| 548 |
% |\MBaskfile|\marg{Prompting text}\parg{root.ext}\marg{io}|\|\emph{fname} |
| 549 |
% \end{quote} |
| 550 |
% may be given, where \emph{root.ext} is the default name of the file, |
| 551 |
% \emph{io} is \texttt{i} (for input) if the file must already exist, and |
| 552 |
% |\|\emph{fname} is the command that receives the file name. The root name |
| 553 |
% will be in |\froot|, the extension in |\fext|. |
| 554 |
% |
| 555 |
% \DescribeMacro{\wr} |
| 556 |
% Text is written to the batch job file with |
| 557 |
% \begin{quote} |
| 558 |
% |\wr|\marg{text} |
| 559 |
% \end{quote} |
| 560 |
% Any commands in \emph{text} that are to be written literally must be |
| 561 |
% preceded by |\string|. |
| 562 |
% |
| 563 |
% \DescribeMacro{\MBswitch} |
| 564 |
% Since any braces in \emph{text} must be balanced, something special must |
| 565 |
% be done to permit them to be printed as normal characters. The command |
| 566 |
% |\MBswitch| accomplishes this; the parentheses \texttt{( )} replace |{ }| |
| 567 |
% as the delimiters. This should always be given within |\begingroup| \dots |
| 568 |
% |\endgroup|. |
| 569 |
% |
| 570 |
% As an example, suppose the master file contains only half the coding for |
| 571 |
% the \texttt{.bst} file, the other half being in one of several other |
| 572 |
% master files. We must prompt for this second file, include it for its |
| 573 |
% options, and make sure that |\MBopts| knows about it. The following code |
| 574 |
% in the master file will do this. |
| 575 |
% \begin{quote} |
| 576 |
% |\MBaskfile{Name of second master file}(aa.mbs)i\xfile|\\ |
| 577 |
% |\begingroup\MBswitch|\\ |
| 578 |
% |\wr(\string\MBopta})|\\ |
| 579 |
% |\wr(\string\from{\xfile}{\string\MBoptb}})|\\ |
| 580 |
% |\wr(\string\def\string\MBopta{\pc)|\\ |
| 581 |
% |\endgroup|\\ |
| 582 |
% \emph{regular menu information for first file}\\ |
| 583 |
% |\begingroup\MBswitch|\\ |
| 584 |
% |\wr(}\string\def\string\MBoptb{\pc)|\\ |
| 585 |
% |\endgroup|\\ |
| 586 |
% |\input\xfile\relax|\\ |
| 587 |
% |\begingroup\MBswitch|\\ |
| 588 |
% |\wr({\pc)|\\ |
| 589 |
% |\endgroup|\\ |
| 590 |
% |\endoptions| |
| 591 |
% \end{quote} |
| 592 |
% |
| 593 |
% The resulting \texttt{.dbj} file contains |
| 594 |
% \begin{quote} |
| 595 |
% |\def\MBopts{\from{first.mbs}{%|\\ |
| 596 |
% |\MBopta}|\\ |
| 597 |
% |\from{second.mbs}{\MBoptb}}|\\ |
| 598 |
% |\def\MBopta{%|\\ |
| 599 |
% \emph{first set of options}\\ |
| 600 |
% |}\def\MBoptb{%|\\ |
| 601 |
% \emph{second set of options}\\ |
| 602 |
% |{%|\\ |
| 603 |
% | }}|\\ |
| 604 |
% |\generate{\file{sample.bst}{\MBopts}}| |
| 605 |
% \end{quote} |
| 606 |
% |
| 607 |
% \StopEventually{\PrintIndex\PrintChanges} |
| 608 |
% |
| 609 |
% \section{Coding} |
| 610 |
% This section presents and explains the actual coding of the macros. |
| 611 |
% It is nested between |%<*program>| and |%</program>|, which |
| 612 |
% are indicators to \dtx{} that this coding belongs to the program |
| 613 |
% file. |
| 614 |
% |
| 615 |
% \subsection{Preliminaries} |
| 616 |
% The first thing is to open up i/o devices for communicating with the |
| 617 |
% terminal and files. (Some of this has been borrowed from \dtx{}.) |
| 618 |
% The terminal input and output are |\ttyin| and |\ttyout| |
| 619 |
% respectively, while the output file if |\outfile|. |
| 620 |
% \begin{macrocode} |
| 621 |
%<*program> |
| 622 |
\newwrite\outfile |
| 623 |
\newread\ttyin |
| 624 |
\newread\infile |
| 625 |
\newwrite\ttyout |
| 626 |
% \end{macrocode} |
| 627 |
% \begin{macro}{\mes}\begin{macro}{\wr}\begin{macro}{\umes} |
| 628 |
% \changes{4.0}{1999 July 20}{AO: define \cs{umes}} |
| 629 |
% The commands for outputting text are defined: |\mes| writes to the |
| 630 |
% terminal, |\wr| writes it argument directly to the output file, |
| 631 |
% while |\umes| writes to the terminal and adds its argument as a comment |
| 632 |
% to the output file. |
| 633 |
% \begin{macrocode} |
| 634 |
\def\mes{\immediate\write\ttyout} |
| 635 |
\def\wr#1{\immediate\write\outfile{#1}} |
| 636 |
\def\umes#1{\mes{^^J#1}\wr{\pc#1}}% |
| 637 |
% \end{macrocode} |
| 638 |
% \end{macro}\end{macro}\end{macro} |
| 639 |
% |
| 640 |
% To assist inserting new lines in the middle of text, define a newline |
| 641 |
% symbol. |
| 642 |
% \begin{macrocode} |
| 643 |
\newlinechar=`\^^J |
| 644 |
% \end{macrocode} |
| 645 |
% |
| 646 |
% \begin{macro}{\MBswitch} |
| 647 |
% \changes{3.0}{1995 Feb 5}{Add macro} |
| 648 |
% There are times when we need to write a line of code to the output file |
| 649 |
% with unbalanced braces in that line. (They are balanced in another line.) |
| 650 |
% Such lines are written with |\wr{...}|. If the braces in the argument are |
| 651 |
% not balanced, then there will be trouble. To get around this, change the |
| 652 |
% category codes of the braces to `other' and let parentheses take their |
| 653 |
% place. |
| 654 |
% \begin{macrocode} |
| 655 |
\def\MBswitch{\catcode`\{=12 \catcode`\}=12 |
| 656 |
\catcode`\(=1 \catcode`\)=2\relax} |
| 657 |
% \end{macrocode} |
| 658 |
% The way to employ this is as |
| 659 |
% \begin{quote}\begin{verbatim} |
| 660 |
% \begingroup\MBswitch |
| 661 |
% \wr(..{..) |
| 662 |
% \endgroup |
| 663 |
% \end{verbatim} |
| 664 |
% \end{quote} |
| 665 |
% \end{macro} |
| 666 |
% |
| 667 |
% \begin{macro}{\ask} |
| 668 |
% To get a response from the terminal, use |\ask|. However, there are some |
| 669 |
% complications here. If only carriage-return is pressed, then the response |
| 670 |
% command is equal to |\par|; for anything else, a typed-in text includes a |
| 671 |
% trailing blank. We must test for |\par| and remove the blank if it is |
| 672 |
% there. |
| 673 |
% \begin{macrocode} |
| 674 |
\def\defpar{\par} |
| 675 |
\def\remblk#1 @@{#1} |
| 676 |
\def\ask#1#2{\mes{#2}\read\ttyin to #1\ifx#1\defpar\def#1{}\else |
| 677 |
\edef#1{\expandafter\remblk#1@@}\fi} |
| 678 |
% \end{macrocode} |
| 679 |
% \end{macro} |
| 680 |
% |
| 681 |
% \begin{macro}{\getroot} |
| 682 |
% \begin{macro}{\getext} |
| 683 |
% To parse the name of a file into root and extension, use commands |
| 684 |
% |\getroot| and |\getext|. |
| 685 |
% \begin{macrocode} |
| 686 |
\def\groot#1.#2@@{#1} |
| 687 |
\def\getroot#1{\expandafter\groot#1.@@} |
| 688 |
\def\gext#1.#2.#3@@{#2} |
| 689 |
\def\getext#1{\expandafter\gext#1..@@} |
| 690 |
% \end{macrocode} |
| 691 |
% \end{macro}\end{macro} |
| 692 |
% |
| 693 |
% \begin{macro}{\MBaskfile} |
| 694 |
% \changes{3.0}{1995 Feb 5}{Add macro to get a file name} |
| 695 |
% Several times it is necessary to ask for a file name interactively, and |
| 696 |
% maybe test if it exists. This might even be done in the \texttt{.mbs} |
| 697 |
% file, so provide a macro to simplify this task. The syntax is |
| 698 |
% \begin{quote} |
| 699 |
% |\MBaskfile|\marg{Prompting text}\parg{root.ext}\marg{io}|\|\emph{fname} |
| 700 |
% \end{quote} |
| 701 |
% where \emph{root.ext} is the default name for the file sought, and |
| 702 |
% |\|\emph{fname} is the command that contains the final file name. The |
| 703 |
% commands |\froot| and |\fext| will contain the root and extensions of the |
| 704 |
% file name, if they are needed for further parsing. If |
| 705 |
% \emph{io}=\texttt{i} (for input), then the resulting file must already |
| 706 |
% exist, else the macro loops again. If \emph{root} is blank, then only the |
| 707 |
% extension is given as default, but a file root name must be entered. |
| 708 |
% \begin{macrocode} |
| 709 |
\def\MBaskfile#1(#2.#3)#4#5{% |
| 710 |
\loop |
| 711 |
\def\ans{#2.#3} |
| 712 |
\if!#2! |
| 713 |
\if!#3!\ask{#5}{#1}\fi |
| 714 |
\ask{#5}{#1 (default extension=#3)}\else |
| 715 |
\ask{#5}{#1 (default=\ans)} |
| 716 |
\fi |
| 717 |
\ifx#5\empty \edef#5{\ans}\fi |
| 718 |
\edef\froot{\getroot#5} |
| 719 |
\edef\fext{\getext#5} |
| 720 |
\ifx\fext\empty \def\fext{#3}\fi |
| 721 |
\edef#5{\froot.\fext} |
| 722 |
\if#4i |
| 723 |
\def\temp{Cannot find file `#5'} |
| 724 |
\openin\infile#5\relax |
| 725 |
\ifeof\infile \def\ans{}\fi \closein\infile |
| 726 |
\else |
| 727 |
\def\temp{There is no default} |
| 728 |
\ifx\froot\empty \def\ans{}\fi |
| 729 |
\fi |
| 730 |
\ifx\ans\empty \mes{*** \temp} |
| 731 |
\repeat} |
| 732 |
% \end{macrocode} |
| 733 |
% \end{macro} |
| 734 |
% |
| 735 |
% \begin{macro}{\pc}\begin{macro}{\pcpc}\begin{macro}{\spsp} |
| 736 |
% Now for some special commands to simplify outputting \% signs and double |
| 737 |
% spaces to the output file. |
| 738 |
% \begin{macrocode} |
| 739 |
{\catcode`\%=12 |
| 740 |
\gdef\pc{%} |
| 741 |
\gdef\pcpc{%% } |
| 742 |
} |
| 743 |
\def\spsp{\space\space} |
| 744 |
% \end{macrocode} |
| 745 |
% \end{macro}\end{macro}\end{macro} |
| 746 |
% |
| 747 |
% \begin{macro}{\Now} |
| 748 |
% \changes{2.0}{1994 Jul 1}{Make \cmd{\today} output YYYY/MM/DD} |
| 749 |
% In order to date-and-time-stamp the resulting batch job file, we need |
| 750 |
% macros to produce the current date and time. (In \TeX{} there is no |
| 751 |
% |\today| command.) |
| 752 |
% \begin{macrocode} |
| 753 |
\newcount\hours |
| 754 |
\newcount\minutes |
| 755 |
\def\SetTime{\hours=\time |
| 756 |
\global\divide\hours by 60 |
| 757 |
\minutes=\hours |
| 758 |
\multiply\minutes by 60 |
| 759 |
\advance\minutes by-\time |
| 760 |
\global\multiply\minutes by-1 } |
| 761 |
\SetTime |
| 762 |
\def\now{\number\hours:\ifnum\minutes<10 0\fi\number\minutes} |
| 763 |
\def\today{\number\year/\ifnum\month<10 0\fi\number\month |
| 764 |
/\ifnum\day<10 0\fi\number\day} |
| 765 |
\def\Now{\today\space at \now} |
| 766 |
% \end{macrocode} |
| 767 |
% \end{macro} |
| 768 |
% |
| 769 |
% |
| 770 |
% \subsection{Menu Macros} |
| 771 |
% \begin{macro}{\optdef} |
| 772 |
% \changes{4.0}{1999 July 20}{AO: save all of \cs{optdef}'s arguments} |
| 773 |
% For each menu, a general text is written with |\mes|, followed by a list |
| 774 |
% of available options. The information that will be needed is |
| 775 |
% \begin{enumerate} |
| 776 |
% \item the response letter to select the option, |
| 777 |
% \item the actual \dtx{} option name, as defined in the master |
| 778 |
% bibliographic style file, |
| 779 |
% \item a piece of text that is printed in the menu list, to be echoed |
| 780 |
% in confirmation of the choice, and also to be written to batch job file |
| 781 |
% as a comment, |
| 782 |
% \item a second piece of text that is only written to the menu, to enhance |
| 783 |
% the explanation. |
| 784 |
% \end{enumerate} |
| 785 |
% The true option name and the two pieces of text are stored as commands |
| 786 |
% prefixed by |\opt@|, |\txt@|, and |\cmt@| respectively, followed by the response |
| 787 |
% letter. Each option response letter is also stored in a list |\optlist| |
| 788 |
% which is initialized to empty. The commands |
| 789 |
% |\nxtopt| and |\rstopt| are used to extract the next and remaining |
| 790 |
% options from the list. |
| 791 |
% \begin{macrocode} |
| 792 |
\def\optdef#1#2#3#4{% |
| 793 |
\expandafter\def\csname opt@#1\endcsname{#2}% |
| 794 |
\expandafter\def\csname txt@#1\endcsname{#3}% |
| 795 |
\expandafter\def\csname cmt@#1\endcsname{#4}% |
| 796 |
\edef\optlist{\optlist#1,}% |
| 797 |
\def\OptAns{#1}% |
| 798 |
\mes{(#1) #3\space #4}% |
| 799 |
} |
| 800 |
\def\optlist{} |
| 801 |
\def\nxtopt#1,#2@@{#1} \def\rstopt#1,#2@@{#2} |
| 802 |
% \end{macrocode} |
| 803 |
% \end{macro} |
| 804 |
% |
| 805 |
% \begin{macro}{\getans} |
| 806 |
% \changes{2.1}{1994 Dec 29}{Allow for \texttt{optlist} option} |
| 807 |
% \changes{4.0}{1999 July 20}{AO: review \cs{optlist} forwards (FIFO)} |
| 808 |
% The user selection is read in with |\getans|, into the command |\ans|. |
| 809 |
% It then processes the response by first checking if there is an option |
| 810 |
% corresponding to it; if not, the response |\ans| is set to the default |*|. |
| 811 |
% If no star response exists, then it takes the last one entered as the default |
| 812 |
% response. It then calls |\wropt| to write the necessary \dtx{} option |
| 813 |
% and explanatory comment to the batch job file. Finally, it uses the |
| 814 |
% option list |\optlist| to clear all the |\opt@| commands. This last step |
| 815 |
% is necessary to avoid conflicts with previous menus: without it, a |
| 816 |
% response that is not in the current list might however exist from an |
| 817 |
% earlier menu. |
| 818 |
% |
| 819 |
% Note that prior to version~4.0 of this code, the |\optlist| was built |
| 820 |
% via head accretion and traversed from the head back, that is, in LIFO order. |
| 821 |
% As of version~4.0 it is processed in FIFO order. |
| 822 |
% This way, the comments in the |.dbj| file are in the same order as |
| 823 |
% the |\optdef| statements in the master file. |
| 824 |
% The flag character (to terminate parsing the |\optlist|) is now |
| 825 |
% a |%|$_{12}$, which cannot be entered as a response by the user, and is |
| 826 |
% appended to the list at the beginning of |\getans| processing. |
| 827 |
% \begin{macrocode} |
| 828 |
\newif\ifsw |
| 829 |
\def\getans{% |
| 830 |
\edef\optlist{\optlist\pc,}% |
| 831 |
\ask{\ans}{\spsp Select:}% |
| 832 |
\expandafter\ifx\csname opt@\ans\endcsname\relax |
| 833 |
\def\ans{*}% |
| 834 |
\fi |
| 835 |
\expandafter\ifx\csname opt@\ans\endcsname\relax |
| 836 |
\let\ans\OptAns |
| 837 |
\fi |
| 838 |
\edef\ansx{\csname opt@\ans\endcsname} |
| 839 |
\swtrue \loop |
| 840 |
\edef\temp{\expandafter\nxtopt\optlist@@}% |
| 841 |
\edef\optlist{\expandafter\rstopt\optlist@@}% |
| 842 |
\if\temp\pc\swfalse\else |
| 843 |
\if\temp\ans |
| 844 |
\wropt\ans |
| 845 |
\else |
| 846 |
\ifoptlist\wrxopt\temp\fi |
| 847 |
\fi |
| 848 |
\expandafter\let\csname opt@\temp\endcsname\relax |
| 849 |
\fi |
| 850 |
\ifsw \repeat |
| 851 |
\def\optlist{}% |
| 852 |
\ifoptverbose |
| 853 |
\wr{\pc------\string\ans=\ans (==\ansx)-------}% |
| 854 |
\else |
| 855 |
\ifoptlist |
| 856 |
\wr{\pc--------------------}% |
| 857 |
\fi |
| 858 |
\fi |
| 859 |
} |
| 860 |
% \end{macrocode} |
| 861 |
% \end{macro} |
| 862 |
% |
| 863 |
% A special request from Frank Mittelbach asks if a list of unused options |
| 864 |
% cannot be added to the batch job file, to assist editing it by hand. In |
| 865 |
% this way, one knows what the \dtx{} options are immediately without having to |
| 866 |
% search for them in the \texttt{.mbs} documentation. |
| 867 |
% |
| 868 |
% This feature was added in version~2.1, but by means of a \dtx\ option, so it |
| 869 |
% could be turned off if necessary. Thus the extracted \theprog\texttt{.tex} |
| 870 |
% file produced either the full list or only the selected options. Here `full |
| 871 |
% list' means only those options that were offered. Any options that were |
| 872 |
% conditionally offered, depending on previous selections, could be missing. |
| 873 |
% |
| 874 |
% For version~4.0, Arthur Ogawa changed this so that the full option list is |
| 875 |
% switched on with the |\ifoptlist| flag, and not by an option at \dtx\ |
| 876 |
% extraction time. He also added an |\ifoptverbose| flag to include even more |
| 877 |
% comments in the \texttt{.dtx} file. The user is asked at run time if s/he |
| 878 |
% wants to activate these features. |
| 879 |
% |
| 880 |
% Furthermore, one can use the |\beginoptiongroup| \dots |\endoptiongroup| |
| 881 |
% idiom to handle cases where options should be offered only contingent upon |
| 882 |
% some condition. By doing so, the unused options are still presented |
| 883 |
% as comments in the batch job file, along with a comment showing the |
| 884 |
% dependency and a matching comment showing the scope. |
| 885 |
% |
| 886 |
% Finally, there are still \dtx\ options \texttt{optlist} and |
| 887 |
% \texttt{optverbose} which produce \theprog\texttt{.tex} with the |
| 888 |
% corresponding flags already set, in which case the features are always |
| 889 |
% activated and the user interrogation is suppressed. |
| 890 |
% |
| 891 |
% \begin{macro}{\wropt} |
| 892 |
% \changes{2.1}{1994 Dec 29}{Change \cs{temp} to \cs{tempx}} |
| 893 |
% \changes{4.0}{1999 July 20}{AO: output the \cs{cmt@} part also; |
| 894 |
% build \cs{optlist} forwards (FIFO).} |
| 895 |
% The actual outputting of the option command to the batch job file is done |
| 896 |
% by |\wropt|. It tests if the option name is blank (a default in the |
| 897 |
% master bibliographic style, which need not be the menu default), writes |
| 898 |
% out the option name, if present, and adds the explanatory comment. |
| 899 |
% \begin{macrocode} |
| 900 |
\def\wropt#1{% |
| 901 |
\edef\tempx{\csname opt@#1\endcsname}% |
| 902 |
\if!\tempx! |
| 903 |
\wr{\spsp\spsp\pc: (def) |
| 904 |
\csname txt@#1\endcsname |
| 905 |
\ifoptverbose\space\csname cmt@#1\endcsname\fi |
| 906 |
}% |
| 907 |
\else |
| 908 |
\wr{\spsp\tempx,\pc: |
| 909 |
\csname txt@#1\endcsname |
| 910 |
\ifoptverbose\space\csname cmt@#1\endcsname\fi |
| 911 |
}% |
| 912 |
\fi |
| 913 |
\mes{\spsp You have selected: \csname txt@#1\endcsname}% |
| 914 |
} |
| 915 |
% \end{macrocode} |
| 916 |
% \end{macro} |
| 917 |
% |
| 918 |
% \begin{macro}{\wrxopt} |
| 919 |
% \changes{2.1}{1994 Dec 29}{Add macro} |
| 920 |
% \changes{4.0}{1999 July 20}{AO: output the \cs{cmt@} part also} |
| 921 |
% \changes{4.0}{1999 July 20}{AO: build \cs{optlist} forwards (FIFO)} |
| 922 |
% Writing the unused options to the batch job file is done with the |\wrxopt| |
| 923 |
% command, which is heavily controlled by the flags |\ifoptlist| and |
| 924 |
% |\ifoptverbose|. |
| 925 |
% |
| 926 |
% \begin{macrocode} |
| 927 |
\def\wrxopt#1{% |
| 928 |
\edef\tempx{\csname opt@#1\endcsname}% |
| 929 |
\if!\tempx! |
| 930 |
\wr{\pc\space\spsp\pc: (def) |
| 931 |
\csname txt@#1\endcsname |
| 932 |
\ifoptverbose\space\csname cmt@#1\endcsname\fi |
| 933 |
}% |
| 934 |
\else |
| 935 |
\wr{\pc\space\tempx,\pc: |
| 936 |
\csname txt@#1\endcsname |
| 937 |
\ifoptverbose\space\csname cmt@#1\endcsname\fi |
| 938 |
}% |
| 939 |
\fi |
| 940 |
} |
| 941 |
% \end{macrocode} |
| 942 |
% \end{macro} |
| 943 |
% |
| 944 |
% \begin{macro}{\beginoptiongroup} |
| 945 |
% \begin{macro}{\endoptiongroup} |
| 946 |
% One can structure the master file using the commands |
| 947 |
% |\beginoptiongroup| \dots |\endoptiongroup|. |
| 948 |
% The |\beginoptiongroup| command takes two arguments, |
| 949 |
% the prompt text and a control expression. |
| 950 |
% \begin{quote} |
| 951 |
% |\beginoptiongroup|\\ |
| 952 |
% | {CITATION NUMBERS (if numerical references)}|\\ |
| 953 |
% | {\ifnumerical*\fi}|\\ |
| 954 |
% |\optdef{*}{}{arabic numbers}|\\ |
| 955 |
% | {references are numbered 1, 2, 3, etc.}|\\ |
| 956 |
% |\optdef{d}{d'nai}{d'nai numerals}|\\ |
| 957 |
% | {references are numbered base-25}|\\ |
| 958 |
% |\getans|\\ |
| 959 |
% \emph{more commands and option groups}\\ |
| 960 |
% |\endoptiongroup|\\ |
| 961 |
% \end{quote} |
| 962 |
% In the above example, the master file has defined a |\newif| switch called |
| 963 |
% |\ifnumerical|, and now uses this flag to enable the processing encapsulated |
| 964 |
% within the option group: the control expression executes the active |*| command |
| 965 |
% if |\ifnumerical| is true. More complex expressions are possible; use plain |
| 966 |
% \TeX\ constructions to expand the star. |
| 967 |
% |
| 968 |
% The prompt text is output to the console and is also |
| 969 |
% recorded as a comment in the generated |.dbj| file. |
| 970 |
% |
| 971 |
% If the control expression executes the active |*|, then |
| 972 |
% the statements within the option group are executed as usual. |
| 973 |
% If false, then the |.dbj| file will simply contain a record of the options |
| 974 |
% that the user would have been able to chose from. |
| 975 |
% In effect, the interrogation never comes: all the options are unused and |
| 976 |
% are recorded (via |\wrxopt|) as comments. |
| 977 |
% |
| 978 |
% By this means, one can structure the |.dbj| file so that all options |
| 979 |
% are made visible, even if some of them would not be accessible because of |
| 980 |
% internal dependencies. The |.dbj| file will show as much detail about the menus |
| 981 |
% of the master file as is possible. |
| 982 |
% |
| 983 |
% To enable a common idiom, we have caused the value of |\ans| to persist |
| 984 |
% past the end of the option group. This means that one may safely test |
| 985 |
% the value of |\ans| after the |\endoptiongroup|. |
| 986 |
% If processing was turned off within |
| 987 |
% the option group, then the value of |\ans| is the untypeable |$|$_{12}$. |
| 988 |
% |
| 989 |
% If the second argument is either nil or is a star, then the option group |
| 990 |
% will be executed normally. Therefore you can employ this structure |
| 991 |
% for all the processing involving the commonly used idiom. |
| 992 |
% If the master file has statements like: |
| 993 |
% \begin{quote} |
| 994 |
% \begin{verbatim} |
| 995 |
%\mes{PROMPT:} |
| 996 |
%\optdef{*}{}{default}{extended comment}% |
| 997 |
%\optdef{a}{opt-a}{option a}{another extended comment}% |
| 998 |
%\optdef{b}{opt-b}{option b}{more extended comments}% |
| 999 |
%\getans |
| 1000 |
%\if\ans a\whatever\fi |
| 1001 |
% \end{verbatim} |
| 1002 |
% \end{quote} |
| 1003 |
% they should be converted to: |
| 1004 |
% \begin{quote} |
| 1005 |
% \begin{verbatim} |
| 1006 |
%\beginoptiongroup{PROMPT:}{} |
| 1007 |
%\optdef{*}{}{default}{extended comment}% |
| 1008 |
%\optdef{a}{opt-a}{option a}{another extended comment}% |
| 1009 |
%\optdef{b}{opt-b}{option b}{more extended comments}% |
| 1010 |
%\getans |
| 1011 |
%\endoptiongroup |
| 1012 |
%\if\ans a\whatever\fi |
| 1013 |
% \end{verbatim} |
| 1014 |
% \end{quote} |
| 1015 |
% The benefit of this syntax is a single markup for all interrogations |
| 1016 |
% and a consistent appearance in the generated file. |
| 1017 |
% \begin{macrocode} |
| 1018 |
\def\beginoptiongroup#1{\begingroup\activatestar\OGcontinue{#1}}% |
| 1019 |
\def\OGcontinue#1#2{% |
| 1020 |
\endgroup |
| 1021 |
\begingroup |
| 1022 |
\let\OGswitch\secondoftwo\def\tempa{#2}% |
| 1023 |
\ifx\tempa\empty\expandafter\firstoftwo\else\expandafter\secondoftwo\fi |
| 1024 |
{% |
| 1025 |
\activestar |
| 1026 |
}{% |
| 1027 |
\tempa |
| 1028 |
}% |
| 1029 |
\OGswitch{}{% |
| 1030 |
\let\wropt\wrxopt |
| 1031 |
\let\ask\nilans |
| 1032 |
\def\mes##1{}% |
| 1033 |
}% |
| 1034 |
\def\OGmessage{#1}% |
| 1035 |
\umes{\ifoptverbose<<\fi\OGmessage}% |
| 1036 |
} |
| 1037 |
\def\endoptiongroup{% |
| 1038 |
\ifoptverbose\umes{>>\OGmessage}\fi |
| 1039 |
\aftergroup\let\aftergroup\ans\expandafter |
| 1040 |
\endgroup |
| 1041 |
\ans |
| 1042 |
} |
| 1043 |
\def\activestar{\let\OGswitch\firstoftwo} |
| 1044 |
\def\activatestar{\catcode`\*13\relax} |
| 1045 |
{\activatestar\gdef*{\activestar}} |
| 1046 |
\def\firstoftwo#1#2{#1} |
| 1047 |
\def\secondoftwo#1#2{#2} |
| 1048 |
{\catcode`\$=12\gdef\nilans#1#2{\def\ans{$}}} |
| 1049 |
% \end{macrocode} |
| 1050 |
% |
| 1051 |
% For more examples of using option groups, see the file \texttt{merlin.mbs}. |
| 1052 |
% \end{macro}\end{macro} |
| 1053 |
% |
| 1054 |
% |
| 1055 |
% \subsection{Initial Messages} |
| 1056 |
% The program can now start working. It first introduces itself and asks if |
| 1057 |
% the user wants an explanation of how the menus work. |
| 1058 |
% \begin{macrocode} |
| 1059 |
\mes{***********************************^^J% |
| 1060 |
* This is Make Bibliography Style *^^J% |
| 1061 |
***********************************^^J% |
| 1062 |
It makes up a docstrip batch job to produce^^J% |
| 1063 |
a customized .bst file for running with BibTeX} |
| 1064 |
|
| 1065 |
\ask{\yn}{Do you want a description of the usage? (NO)} |
| 1066 |
|
| 1067 |
\if!\yn!\else\if\yn n\else\if\yn N\else |
| 1068 |
\mes{In the interactive dialogue that follows,^^J% |
| 1069 |
you will be presented with a series of menus.^^J% |
| 1070 |
In each case, one answer is the default, marked as (*),^^J% |
| 1071 |
and a mere carriage-return is sufficient to select it.^^J% |
| 1072 |
(If there is no * choice, then the default is the last choice.)^^J% |
| 1073 |
For the other choices, a letter is indicated^^J% |
| 1074 |
in brackets for selecting that option. If you select^^J% |
| 1075 |
a letter not in the list, default is taken.^^J^^J% |
| 1076 |
The final output is a file containing a batch job^^J% |
| 1077 |
which may be (La)TeXed to produce the desired BibTeX^^J% |
| 1078 |
bibliography style file. The batch job may be edited^^J% |
| 1079 |
to make minor changes, rather than running this program^^J% |
| 1080 |
once again.} |
| 1081 |
\fi\fi\fi |
| 1082 |
% \end{macrocode} |
| 1083 |
% |
| 1084 |
% Ask for the name of the master bibliographic style file, |
| 1085 |
% suggesting a default name. Test if the file exist (argument \texttt{i}). |
| 1086 |
% The name of the master file is split up into root and extension. |
| 1087 |
% \changes{3.0}{1995 Mar 15}{Default master file now \texttt{merlin.mbs}} |
| 1088 |
% \begin{macrocode} |
| 1089 |
\MBaskfile{^^JEnter the name of the MASTER file}(merlin.mbs)i\mfile |
| 1090 |
\let\mroot=\froot |
| 1091 |
\let\mext=\fext |
| 1092 |
% \end{macrocode} |
| 1093 |
% |
| 1094 |
% Originally, I intended the menu information to be in an \texttt{.opt} |
| 1095 |
% file, but this is dangerous: that file may not be consistent with the |
| 1096 |
% master. So now, issue a warning if an \texttt{.opt} file exists, |
| 1097 |
% substituting it only if explicitly requested. (This is useful for me |
| 1098 |
% when testing changes to \theprog{} and I only want a short menu.) |
| 1099 |
% \begin{macrocode} |
| 1100 |
\edef\temp{\mroot.opt} |
| 1101 |
\openin\infile\temp\relax |
| 1102 |
\let\mnext=\mext |
| 1103 |
\ifeof\infile\else |
| 1104 |
\ask{\yn}{** Warning: a file `\temp' also exists^^J |
| 1105 |
\spsp Shall I read it for the menu information? (NO)^^J |
| 1106 |
\spsp (Answer `yes' only if you really know what you are doing)} |
| 1107 |
\if\yn y\def\mnext{opt}\else\if\yn Y\def\mnext{opt}\fi\fi |
| 1108 |
\mes{Menu information read from `\mroot.\mnext'} |
| 1109 |
\fi |
| 1110 |
\closein\infile |
| 1111 |
% \end{macrocode} |
| 1112 |
% |
| 1113 |
% Next, the name of the output \texttt{.bst} file is asked for. Here there is |
| 1114 |
% to be no default for the root part, although the extension defaults to |
| 1115 |
% \texttt{.bst}. |
| 1116 |
% \begin{macrocode} |
| 1117 |
\MBaskfile{^^JName of the final OUTPUT .bst file?}(.bst)o\ofile |
| 1118 |
\let\oroot=\froot |
| 1119 |
\let\oext=\fext |
| 1120 |
% \end{macrocode} |
| 1121 |
% |
| 1122 |
% A comment line of text is asked for. This will go into the preamble of |
| 1123 |
% the final \texttt{.bst} file and should describe the nature of the |
| 1124 |
% bibliographic style, i.e., for which journal(s) it is meant to apply. |
| 1125 |
% \begin{macrocode} |
| 1126 |
\ask{\ans}{^^JGive a comment line to include in the style file.^^J% |
| 1127 |
Something like for which journals it is applicable.} |
| 1128 |
% \end{macrocode} |
| 1129 |
% |
| 1130 |
% \changes{1.1}{1994 May 25}{The \dtx{} driver has extension \texttt{.dbj} |
| 1131 |
% instead of \texttt{.drv}} |
| 1132 |
% The output batch job file is to have the same root name as the output |
| 1133 |
% file, but with the extension \texttt{.dbj}, for \emph{\dtx{} batch job}. |
| 1134 |
% This file is opened and the initial contents are written. |
| 1135 |
% \begin{macrocode} |
| 1136 |
\immediate\openout\outfile\oroot.dbj |
| 1137 |
\wr{\pcpc Driver file to produce \oroot.\oext\space from \mroot.\mext} |
| 1138 |
\wr{\pcpc Generated with \filename, version \fileversion\space (\filedate)} |
| 1139 |
\wr{\pcpc Produced on \Now} |
| 1140 |
\wr{\pcpc} |
| 1141 |
\wr{\string\input\space docstrip} |
| 1142 |
\wr{} |
| 1143 |
\wr{\string\preamble} |
| 1144 |
\wr{----------------------------------------} |
| 1145 |
\wr{*** \ans\space ***} |
| 1146 |
\wr{} |
| 1147 |
\wr{\string\endpreamble} |
| 1148 |
\wr{} |
| 1149 |
\wr{\string\postamble} |
| 1150 |
\wr{End of customized bst file} |
| 1151 |
\wr{\string\endpostamble} |
| 1152 |
\wr{} |
| 1153 |
\wr{\string\keepsilent} |
| 1154 |
\wr{} |
| 1155 |
\wr{\string\askforoverwritefalse} |
| 1156 |
% \end{macrocode} |
| 1157 |
% \changes{3.0}{1995 Feb 5}{Options from master file written to control |
| 1158 |
% sequence \cs{MBopts} instead of directly into \cs{generateFile}} |
| 1159 |
% The options will be written to the output file during the interrogation |
| 1160 |
% when the master file is input. These options are stored in |\MBopts|. |
| 1161 |
% |
| 1162 |
% Note: it is necessary to change the catagory codes of |{| and |}| |
| 1163 |
% temporarily, and to find substitutes, so that mismatched curly braces |
| 1164 |
% could be included in the output text. The same thing is done again at the |
| 1165 |
% end to close the braces finally. This is done with |\MBswitch|. |
| 1166 |
% \begin{macrocode} |
| 1167 |
\begingroup\MBswitch |
| 1168 |
\wr(\string\def\string\MBopts{\string\from{\mroot.\mext}{\pc) |
| 1169 |
\endgroup |
| 1170 |
% \end{macrocode} |
| 1171 |
% |
| 1172 |
% Now each selected option is written on a single line. |
| 1173 |
% |
| 1174 |
% \subsection{The Interrogation} |
| 1175 |
% \changes{2.1}{1995 Jan 2}{Get menu info from master file, not \texttt{.opt} |
| 1176 |
% file.} |
| 1177 |
% The menu information is read in from the master file, or from a file |
| 1178 |
% with extension \texttt{.opt}, but only if one has explicitly requested |
| 1179 |
% this. (This is expert stuff; the \texttt{.opt} files should be avoided |
| 1180 |
% since they might not be up-to-date. Previously they were the default, |
| 1181 |
% but this has been changed in version~2.1 to avoid confusion.) |
| 1182 |
% \begin{macrocode} |
| 1183 |
\newif\ifoptlist |
| 1184 |
%<optlist|optverbose>\optlisttrue |
| 1185 |
\ifoptlist\else |
| 1186 |
\ask\yn{Do you want the unused option lines^^J% |
| 1187 |
\spsp to appear as comments in the output? (NO)} |
| 1188 |
\if!\yn!\else\if\yn n\else\if\yn N\else\optlisttrue\fi\fi\fi |
| 1189 |
\fi |
| 1190 |
\newif\ifoptverbose |
| 1191 |
%<optverbose>\optverbosetrue |
| 1192 |
\ifoptlist |
| 1193 |
\ifoptverbose\else |
| 1194 |
\ask\yn{Do you want verbose comments? (NO)} |
| 1195 |
\if!\yn!\else\if\yn n\else\if\yn N\else\optverbosetrue\fi\fi\fi |
| 1196 |
\fi |
| 1197 |
\fi |
| 1198 |
\edef\temp{\mroot.\mnext} |
| 1199 |
\let\endoptions=\endinput |
| 1200 |
\input\temp |
| 1201 |
% \end{macrocode} |
| 1202 |
% Note that it is necessary to equate |\endoptions| to |\endinput| in |
| 1203 |
% case the master file is read in. An |\endinput| command in the master |
| 1204 |
% file would interfere with the \dtx{} operation, but this indirect |
| 1205 |
% method gets around that problem. |
| 1206 |
% |
| 1207 |
% |
| 1208 |
% \section{Closing the Output File} |
| 1209 |
% The output file is closed by writing the final line that closes the |
| 1210 |
% braces that were opened at the beginning. To this end, the catagory codes |
| 1211 |
% of |{| and |}| must be temporarily altered, as before. |
| 1212 |
% \begin{macrocode} |
| 1213 |
\begingroup\MBswitch |
| 1214 |
\wr(\spsp}}) |
| 1215 |
\endgroup |
| 1216 |
% \end{macrocode} |
| 1217 |
% |
| 1218 |
% Now write the line that processes the options stored in |\MBopts|. |
| 1219 |
% The batch job file is finished and may be closed. |
| 1220 |
% \begin{macrocode} |
| 1221 |
\wr{\string\generate{\string\file{\oroot.\oext}{\string\MBopts}}} |
| 1222 |
\wr{\string\endbatchfile} |
| 1223 |
|
| 1224 |
\immediate\closeout\outfile |
| 1225 |
\mes{^^JFinished!!^^J% |
| 1226 |
Batch job written to file `\oroot.dbj'} |
| 1227 |
% \end{macrocode} |
| 1228 |
% |
| 1229 |
% The batch job may now be run. It is only necessary to input the file. |
| 1230 |
% However, the inputting should not occur with a group or within an |\if| |
| 1231 |
% \dots\ |\fi| clause. Furthermore, under \LaTeX{}, the |\end| command causes |
| 1232 |
% problems, because it has been redefined; the command |\@@end| contains the |
| 1233 |
% original |\end|. |
| 1234 |
% \begin{macrocode} |
| 1235 |
\def\ofile{\oroot.dbj} |
| 1236 |
\ask{\yn}{Shall I now run this batch job? (NO)} |
| 1237 |
\def\temp{\relax} |
| 1238 |
\if!\yn!\else\if\yn n\else\if\yn N\else |
| 1239 |
\def\temp{\input\ofile}\fi\fi\fi |
| 1240 |
{\catcode`\@=11 \ifx\@@end\undefined\else |
| 1241 |
\global\let\end=\@@end\fi} |
| 1242 |
\temp |
| 1243 |
\end |
| 1244 |
%</program> |
| 1245 |
% \end{macrocode} |
| 1246 |
% |
| 1247 |
% \Finale |