| 1 |
%%***************************************************************************** |
| 2 |
%% bibtcl.tex |
| 3 |
%%***************************************************************************** |
| 4 |
%% Author: Gerd Neugebauer |
| 5 |
%%----------------------------------------------------------------------------- |
| 6 |
%% |
| 7 |
%% To generate the printed documentation run LaTeX on the |
| 8 |
%% driver file bibtcl.ltx. |
| 9 |
%% |
| 10 |
%%----------------------------------------------------------------------------- |
| 11 |
|
| 12 |
\newcommand\code[1]{\texttt{#1}} |
| 13 |
\newcommand\meta[1]{\textit{#1\/}} |
| 14 |
\newcommand\file[1]{\textsf{#1}} |
| 15 |
|
| 16 |
\newcommand\TclSummaryLabel[1]{\textbf{#1\hss}} |
| 17 |
\newcommand\TclSummary[3]{\TclSummaryOO{bibtool #1 |
| 18 |
#2}{#3}\index{bibtool!#1}} |
| 19 |
\newcommand\TclSummaryOO[2]{\begin{list}{}{% |
| 20 |
\parskip=0pt |
| 21 |
\parsep=0pt |
| 22 |
\topsep=0pt |
| 23 |
\rightmargin=2em |
| 24 |
\advance\leftmargin \rightmargin |
| 25 |
\let\makelabel\TclSummaryLabel} |
| 26 |
\item[#1] \ \par #2 |
| 27 |
\end{list}} |
| 28 |
|
| 29 |
\section{Introduction} |
| 30 |
|
| 31 |
The following description assumes that you are familiar with Tcl |
| 32 |
\cite{ousterhout:tcl,welch:practical}. Thus it does not repeat any |
| 33 |
introductory material on this language. You are referred to one of |
| 34 |
the books or the material to be found on the Web. If you are not |
| 35 |
familiar enough with Tcl you are strongly encouraged to read an |
| 36 |
introductory text since there are some subtle points in Tcl which have |
| 37 |
to be understood. Otherwise the language is not usable. |
| 38 |
|
| 39 |
The \BibTool{} library is made available for the Tcl programming |
| 40 |
language in the form of a dynamic loadable library. To use this |
| 41 |
library it is usually sufficient to source the file \file{bibtool.tcl} |
| 42 |
which is created during the installation of the library (see |
| 43 |
section~\ref{sec:installation}) and which can be found in the same |
| 44 |
directory where the machine dependent library resides---even though |
| 45 |
this file is not architecture dependent. Thus the first instruction to |
| 46 |
use the library in a Tcl program is |
| 47 |
|
| 48 |
\begin{verbatim} |
| 49 |
source bibtool.tcl |
| 50 |
\end{verbatim} |
| 51 |
The file \file{bibtool.tcl} contains the information where the |
| 52 |
libraries can be found. It tries to find and load the appropriate |
| 53 |
dynamic library for the operating system and version it is running on. |
| 54 |
If you encounter problems like missing libraries then just reinstall |
| 55 |
the \BibTool{} library on this architecture into the same directory. |
| 56 |
This will create a new subdirectory containing the missing library. |
| 57 |
|
| 58 |
|
| 59 |
\section{Functional vs.\ Object-Oriented Reading} |
| 60 |
|
| 61 |
During the development of the \BibTool{} library an interesting |
| 62 |
question occurred. In principle there are two ways of thinking present |
| 63 |
even in plain Tcl/Tk, namely a functional/pro\-ce\-du\-ral and an |
| 64 |
object oriented point of view. The object oriented point of view can |
| 65 |
be seen mainly in Tk where the widgets act like objects. In Tcl most |
| 66 |
things have only a procedural flavor. |
| 67 |
|
| 68 |
The question arose which paradigm should be supported. The first |
| 69 |
consideration was to use the procedural paradigm since this would |
| 70 |
require only a single new Tcl command to be implemented. This means |
| 71 |
the simplicity argument won. |
| 72 |
|
| 73 |
When lots of subcommands of this single command \code{bibtool} had |
| 74 |
already been implemented the issue was reconsidered. It turned out |
| 75 |
that only one single wrapper function had to be written in C to |
| 76 |
provide the object oriented point of view. Thus for many subcommands |
| 77 |
of \code{bibtool}---namely those dealing with databases or |
| 78 |
entries---there are two alternative notations available. |
| 79 |
|
| 80 |
Consider for example the following situation. the Tcl variables |
| 81 |
\code{entry1} and \code{entry2} contain references to single entries (we |
| 82 |
will see later how we can come to this situation). Then the equality |
| 83 |
of the entries (in the sense of pointers to the same internal data |
| 84 |
structure) can be checked with |
| 85 |
\begin{verbatim} |
| 86 |
bibtool equal $entry1 $entry2 |
| 87 |
\end{verbatim} |
| 88 |
This returns \code{1} upon success and \code{0} upon failure. In the |
| 89 |
object oriented paradigm we have to provide a method of a entry which |
| 90 |
decides whether or not it is identical to another entry. This can be |
| 91 |
written as |
| 92 |
\begin{verbatim} |
| 93 |
$entry1 equal $entry2 |
| 94 |
\end{verbatim} |
| 95 |
|
| 96 |
Another example is concerned with the access to a entry in a |
| 97 |
database. Suppose we have a reference to a database stored in the Tcl |
| 98 |
variable \code{db} and we have already loaded some \BibTeX{} files |
| 99 |
into this database. Then we can get a reference to the first |
| 100 |
entry---storing it in the Tcl variable \code{entry}---with the |
| 101 |
following command: |
| 102 |
\begin{verbatim} |
| 103 |
set rec [bibtool first $db] |
| 104 |
\end{verbatim}%$ |
| 105 |
If we consider \code{\$db} as an object then we can use the method |
| 106 |
\code{first} to get the first entry: |
| 107 |
\begin{verbatim} |
| 108 |
set rec [$db first] |
| 109 |
\end{verbatim}%$ |
| 110 |
|
| 111 |
Thus we have available both paradigms in this library. This effect is |
| 112 |
achieved by using handles to objects. These handles have the prefix |
| 113 |
\code{=BibTcl=}. For each object created a command is defined which is |
| 114 |
an alias to the appropriate \code{bibtool} subcommand. As long as the |
| 115 |
user does not try to define commands with this prefix everything works |
| 116 |
fine. |
| 117 |
|
| 118 |
|
| 119 |
\section{Databases} |
| 120 |
|
| 121 |
\code{bibtool} is designed to handle several databases simultaneously. |
| 122 |
To distinguish the different databases they get assigned a |
| 123 |
handle---which is a unique identifier---when they are created. This |
| 124 |
handle has to be used to refer to a database later on. Thus it is |
| 125 |
preferable to store it in Tcl variable. |
| 126 |
|
| 127 |
The handle can also be seen as an object in an object oriented |
| 128 |
context. The database class provides a fixed set of methods for this |
| 129 |
object. Instead of using an object oriented notation we have decided |
| 130 |
to use a more procedural approach. But you can have your own model in |
| 131 |
mind when you read the code. |
| 132 |
|
| 133 |
One consequence of the use of handles is that \BibTool{} can determine |
| 134 |
which kind of object is addressed. In case of an invalid object an |
| 135 |
appropriate error is raised. This can occur for instance if a |
| 136 |
database handle is used after the database has been deleted, or if an |
| 137 |
arbitrary string is given as handle which does not correspond to an |
| 138 |
object in \BibTool. |
| 139 |
|
| 140 |
The first step to work with a database is the creation. This can be |
| 141 |
done with the command \code{bibtool new}. This command returns a |
| 142 |
handle for a new database which should be stored in a Tcl variable for |
| 143 |
later user: |
| 144 |
\begin{verbatim} |
| 145 |
set db [bibtool new] |
| 146 |
\end{verbatim}% |
| 147 |
This database is empty. If you want to load some files into this |
| 148 |
database you can give the filenames as arguments to \code{bibtool |
| 149 |
new}. Any number of \BibTeX{} files can be given this way: |
| 150 |
\begin{verbatim} |
| 151 |
set db [bibtool new a.bib b.bib c.bib] |
| 152 |
\end{verbatim}% |
| 153 |
Since \BibTool{} is rather noisy by default it might be preferable to |
| 154 |
reduce the verbosity before loading a database. This can be done by |
| 155 |
utilizing \BibTool{} resources as in the following command: |
| 156 |
\begin{verbatim} |
| 157 |
bibtool quiet=on verbose=off |
| 158 |
\end{verbatim}% |
| 159 |
Details on the use of \BibTool{} resources can be found in |
| 160 |
section~\ref{sec:tcl-resources} on page~\pageref{sec:tcl-resources}. |
| 161 |
|
| 162 |
|
| 163 |
But the files can not be loaded at creation time only but also later |
| 164 |
on. This is done with the command \code{bibtool read} as shown in the |
| 165 |
following example: |
| 166 |
\begin{verbatim} |
| 167 |
bibtool read $db c.bib d.bib |
| 168 |
\end{verbatim}%$ |
| 169 |
\code{bibtool read} needs the next argument to be a handle for a |
| 170 |
database. Any following arguments are taken to be file names which are |
| 171 |
loaded into the given database. Upon success the databse handle is |
| 172 |
returned. If one of the files does not exist, can not be read, or |
| 173 |
another error occurrs then this command issues a Tcl error. You can |
| 174 |
use \code{catch} to avoid a termination of Tcl and implement an error |
| 175 |
recovery scheme: |
| 176 |
\begin{verbatim} |
| 177 |
foreach file {c.bib d.bib} { |
| 178 |
if {[catch {bibtool read $db $file} message]} { |
| 179 |
puts stderr "*** $message" |
| 180 |
} |
| 181 |
} |
| 182 |
\end{verbatim}%$ |
| 183 |
The next important operation on a database is the writing |
| 184 |
operation. The command \code{bibtool write} writes the named database |
| 185 |
into the given file. Again an error is raised if this writing can not |
| 186 |
be performed. This is most probably caused by the inability to open |
| 187 |
the file. |
| 188 |
\begin{verbatim} |
| 189 |
set file abc.bib |
| 190 |
if {[catch {bibtool write $db $file} message]} { |
| 191 |
puts stderr "*** $message" |
| 192 |
} |
| 193 |
\end{verbatim}%$ |
| 194 |
Usually the database is written to the file deleting its previous |
| 195 |
contents. Sometimes it can be desirable to append the database to an |
| 196 |
existing file. For this purpose the flag \code{-append} can be used: |
| 197 |
\begin{verbatim} |
| 198 |
if {[catch {bibtool write $db $file -append} message]} { |
| 199 |
puts stderr "*** $message" |
| 200 |
} |
| 201 |
\end{verbatim}%$ |
| 202 |
There is one special case of a file name. If the file name is the |
| 203 |
empty string then the output is written to the standard output stream. |
| 204 |
|
| 205 |
The final operation on a database is its deletion. This can be done |
| 206 |
with the command \code{bibtool delete}. This command takes as argument |
| 207 |
a single \BibTool{} object and performs the delete operation for |
| 208 |
it. Now we are interested in a database object only. Thus the object is a |
| 209 |
database handle. |
| 210 |
\begin{verbatim} |
| 211 |
bibtool delete $db |
| 212 |
\end{verbatim}%$ |
| 213 |
This command deletes the database \code{\$db}. Any reference to it or |
| 214 |
its contents might lead to a Tcl error. This deletion does not remove |
| 215 |
the file on the disk but only frees the handle. |
| 216 |
|
| 217 |
With the means given in this section we can already write a useful |
| 218 |
tool. If we want to write a Tcl program which normalizes a \BibTeX{} |
| 219 |
file then this can be done with the following piece of code: |
| 220 |
\begin{verbatim} |
| 221 |
bibtool quiet=on verbose=off |
| 222 |
bibtool write [bibtool new [lindex $argv 0]] [lindex $argv 1] |
| 223 |
\end{verbatim}% |
| 224 |
This Tcl program reads the \BibTeX{} file given as command line |
| 225 |
argument one and writes it to the file given as the second |
| 226 |
argument. No error detection is performed. To implement error recovery |
| 227 |
and the generalization to several input files is left to the reader. |
| 228 |
|
| 229 |
In fact this is a special case of the main loop of \BibTool. The same |
| 230 |
effect could be achieved with the following command line invocation of |
| 231 |
\BibTool: |
| 232 |
\begin{verbatim} |
| 233 |
bibtool -- quiet=on -- verbose=off infile -o outfile |
| 234 |
\end{verbatim} |
| 235 |
where \code{infile} and \code{outfile} are the names of the input and |
| 236 |
output files respectively. |
| 237 |
|
| 238 |
Next we want to have access to the entries in a database. For this |
| 239 |
purpose two methods are provided which return a handle for the first |
| 240 |
or last entry in a given database respectively. These handles should |
| 241 |
be stored in Tcl variables for later use: |
| 242 |
\begin{verbatim} |
| 243 |
set rec1 [$db first] |
| 244 |
set rec2 [$db last] |
| 245 |
\end{verbatim} |
| 246 |
If the database is empty then no handle is created and the empty |
| 247 |
string is returned. |
| 248 |
|
| 249 |
Next we can try to find a certain entry in the database by speifying |
| 250 |
its key. This can be accomplished with the \code{find} method: |
| 251 |
\begin{verbatim} |
| 252 |
set rec [$db find $key] |
| 253 |
\end{verbatim} |
| 254 |
If no appropriate entry is found then the empty string is returned. |
| 255 |
If you are finished with the database you should release it. This is |
| 256 |
done with the \code{delete} method: |
| 257 |
\begin{verbatim} |
| 258 |
$db delete |
| 259 |
\end{verbatim}%$ |
| 260 |
This command tries to free the memory occupied by the |
| 261 |
database\footnote{Currently a part of the memory is not really freed |
| 262 |
but kept internally to be reused by the next database.}. This |
| 263 |
operation invalidates the handle the the database and any handles to |
| 264 |
entries therein. This means that any access with such handles leads to |
| 265 |
a Tcl error. |
| 266 |
|
| 267 |
One method is present which can be used to check a handle: |
| 268 |
\begin{verbatim} |
| 269 |
$db valid |
| 270 |
\end{verbatim}%$ |
| 271 |
This command returns \code{1} if the database is a valid database or |
| 272 |
entry handle. Here is one place where it is preferable to use the |
| 273 |
procedural writing: |
| 274 |
\begin{verbatim} |
| 275 |
bibtool valid $db |
| 276 |
\end{verbatim}%$ |
| 277 |
This works for any string argument \code{\$db} not only those which |
| 278 |
have been valid \BibTool{} handles previously. |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
\begin{table}[tp] |
| 284 |
\TclSummaryOO{\meta{DB} count \meta{varname}}{} |
| 285 |
\TclSummary{count}{\meta{DB} \meta{varname}}{Count the nunber of |
| 286 |
entries of each type and store the result in the Tcl array |
| 287 |
\meta{varname}. The old contents of this varaible is lost.} |
| 288 |
\TclSummaryOO{\meta{DB} delete}{} |
| 289 |
\TclSummary{delete}{\meta{DB}}{delete a database such that no further |
| 290 |
operations are possible on them. Cf. \code{bibtool delete} for |
| 291 |
entries.} |
| 292 |
\TclSummaryOO{\meta{DB} find \meta{KEY}}{} |
| 293 |
\TclSummary{find}{\meta{DB} \meta{KEY}}{Return a new entry handle which |
| 294 |
corresponds to the first normal entry in the database \meta{DB} |
| 295 |
which has the key \meta{KEY}. If none is found then the empty |
| 296 |
string is returned.} |
| 297 |
\TclSummaryOO{\meta{DB} first}{} |
| 298 |
\TclSummary{first}{\meta{DB}}{Return a new entry handle which |
| 299 |
corresponds to the first normal entry in the database \meta{DB}. |
| 300 |
If the database is empty then the empty string is returned.} |
| 301 |
\TclSummaryOO{\meta{DB} last}{} |
| 302 |
\TclSummary{last}{\meta{DB}}{Return a new entry handle which |
| 303 |
corresponds to the last normal entry in the database \meta{DB}. |
| 304 |
If the database is empty then the empty string is returned.} |
| 305 |
|
| 306 |
\caption{Summary of database operations}\label{fig:tcl-database} |
| 307 |
\rule{\textwidth}{.1pt} |
| 308 |
\end{table} |
| 309 |
\begin{table}[tp] |
| 310 |
\TclSummary{new}{}{create a new database and return a handle to it.} |
| 311 |
\TclSummaryOO{\meta{DB} preamble}{} |
| 312 |
\TclSummary{preamble}{\meta{DB}}{Return the preamble of the database |
| 313 |
\meta{DB}.} |
| 314 |
\TclSummaryOO{\meta{DB} read \meta{?FILE \ldots?}}{} |
| 315 |
\TclSummary{read}{\meta{DB} \meta{?FILE \ldots?}}{read the contents of |
| 316 |
the \BibTeX{} file \meta{FILE} into the database \meta{DB}.} |
| 317 |
\TclSummaryOO{\meta{DB} entry \meta{TYPE}}{} |
| 318 |
\TclSummary{entry}{\meta{DB} \meta{TYPE}}{Create a new entry in the |
| 319 |
database \meta{DB} with the type \meta{TYPE}.} |
| 320 |
\TclSummaryOO{\meta{DB} sort \meta{?-generate?} \meta{?-reverse?}}{} |
| 321 |
\TclSummary{sort}{\meta{DB} \meta{?-generate?} |
| 322 |
\meta{?-reverse?}}{sort the database \meta{DB} according to the sort |
| 323 |
keys. If \meta{-generate} is specified then the sort keys are |
| 324 |
generated first according to the resource \rsc{sort.format}. The |
| 325 |
sort order is ascending or descending depending on the resource |
| 326 |
\rsc{sort.reverse}. If the argument \meta{-reverse} is given then |
| 327 |
this order is reversed again.} |
| 328 |
\TclSummary{sort.format}{=\meta{FORMAT}}{} |
| 329 |
\TclSummaryOO{\meta{DB} valid}{} |
| 330 |
\TclSummary{valid}{\meta{DB}}{check whether the database handle |
| 331 |
\meta{DB} is still valid. A database handle is invalidated by the |
| 332 |
\code{delete} operation.} |
| 333 |
\TclSummaryOO{\meta{DB} write \meta{FILE} \meta{?-append?}}{} |
| 334 |
\TclSummary{write}{\meta{DB} \meta{FILE} \meta{?-append?}}{write the |
| 335 |
contents of the database \meta{DB} into the file \meta{FILE}. If the |
| 336 |
option \meta{-append} is given then the contents is appended to the |
| 337 |
file. If the file is the empty string then the output is written |
| 338 |
to stdout.} |
| 339 |
|
| 340 |
\addtocounter{table}{-1}% |
| 341 |
\caption{Summary of database operations (continued)}\label{fig:tcl-database2} |
| 342 |
\rule{\textwidth}{.1pt} |
| 343 |
\end{table} |
| 344 |
A summary of the commands discussed in this section can be found in |
| 345 |
Table~\ref{fig:tcl-database}. |
| 346 |
|
| 347 |
|
| 348 |
\section{Entries and Fields} |
| 349 |
|
| 350 |
Any \BibTool{} database consists of a set of entries. Currently there |
| 351 |
are three types of entries which are treated differently. The normal |
| 352 |
entry consists of a set of fields which have names and values. The |
| 353 |
following example illustrates such a normal entry:\label{example:bibtool} |
| 354 |
\begin{verbatim} |
| 355 |
@Manual{ neugebauer:bibtool, |
| 356 |
author = {Gerd Neugebauer}, |
| 357 |
title = {{BibTool} -- A Tool to Manipulate {\BibTeX} Files}, |
| 358 |
edition = {2.41}, |
| 359 |
year = {1997} |
| 360 |
} |
| 361 |
\end{verbatim} |
| 362 |
Currently there are two kinds of special entries, namely |
| 363 |
\code{@preamble} and \code{@string} entries. These types of entries |
| 364 |
will be discussed later and we will focus for the moment on normal |
| 365 |
entries. |
| 366 |
|
| 367 |
To navigate through the database the methods \code{forward} and |
| 368 |
\code{backward} are provided. These commands take a entry handle as |
| 369 |
argument and modify it such that it references the next or previous |
| 370 |
entry respectively. Upon success the entry handle is returned. If |
| 371 |
there is no next or previous entry then the handle is released and |
| 372 |
the empty string is returned. |
| 373 |
\begin{verbatim} |
| 374 |
if {[$entry forward]==""} {puts {At end.}} |
| 375 |
if {[$entry backward]==""} {puts {At beginning.}} |
| 376 |
\end{verbatim} |
| 377 |
|
| 378 |
With these methods we are able to write down a loop which visits all |
| 379 |
normal entries. We show the loop starting from the first element and |
| 380 |
approaching to the last one. As an application we count the number of |
| 381 |
entries in the database: |
| 382 |
\begin{verbatim} |
| 383 |
set count 0 |
| 384 |
for { set rec [$db first] } \ |
| 385 |
{ $entry != "" } \ |
| 386 |
{ set rec [$entry forward] }\ |
| 387 |
{ |
| 388 |
incr count 1 |
| 389 |
} |
| 390 |
\end{verbatim}%$ |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
Like for database handles we might be interested to get rid of a |
| 395 |
entry handle. For this purpose the method \code{delete} is also |
| 396 |
provided for entries. The deletion of a entry handle invalidates |
| 397 |
this handle. It does not alter the database in any way. Thus after the |
| 398 |
following piece of code the database has not been changed. |
| 399 |
\begin{verbatim} |
| 400 |
set rec [$db first] |
| 401 |
$entry delete |
| 402 |
\end{verbatim} |
| 403 |
|
| 404 |
\label{bibtool:remove}% |
| 405 |
If you want to delete a database entry you can use the method |
| 406 |
\code{bibtool remove}. This takes as argument a single entry and |
| 407 |
removes it from the database. Additionally the handle is invalidated. |
| 408 |
Thus it can not be used any more. |
| 409 |
|
| 410 |
Consider the problem of looping through all entries and deleting some |
| 411 |
of them. For this purpose we want to assume that we have a boolean |
| 412 |
function \code{has\_to\_be\_deleted} which decides whether the entry |
| 413 |
given as argument has to be deleted. Then the loop can be implemented |
| 414 |
as follows: |
| 415 |
\begin{verbatim} |
| 416 |
for {set rec [$db first]} \ |
| 417 |
{[bibtool $entry valid]} \ |
| 418 |
{set rec $next} { |
| 419 |
set next [$entry dup] |
| 420 |
$next forward |
| 421 |
if {[has_to_be_deleted $entry]} {$entry remove} |
| 422 |
} |
| 423 |
\end{verbatim}%$ |
| 424 |
In this example we see several new things. First of all we see the |
| 425 |
method \code{bibtool remove} in action. Next we see the method |
| 426 |
\code{bibtool valid} which can not only be used to check valid database |
| 427 |
handles but also valid entry handles. It works absolutely analogously |
| 428 |
and is no surprise. |
| 429 |
|
| 430 |
The new method which might be surprising is the \code{bibtool dup}. |
| 431 |
This method creates a new entry handle which points to the same entry |
| 432 |
as the handle given as argument. This is necessary since manipulations |
| 433 |
on the first handle can now be performed safely because they do not |
| 434 |
effect the new handle---except when the entry is deleted. |
| 435 |
|
| 436 |
Let us have a look at \code{bibtool dup} with another example. Let us |
| 437 |
assume that the Tcl variable \code{entry} contains a valid entry handle |
| 438 |
for the database \code{db}. The following piece of code creates a Tcl |
| 439 |
variable \code{new} which contains the same entry handle as |
| 440 |
\code{entry}: |
| 441 |
\begin{verbatim} |
| 442 |
set new $entry |
| 443 |
$entry forward |
| 444 |
\end{verbatim} |
| 445 |
The \code{bibtool forward} operation on \code{entry} modifies \code{new} as |
| 446 |
well. Thus \code{new} either points to the next entry of the initial |
| 447 |
one or it is invalidated if no such entry exists. |
| 448 |
|
| 449 |
In contrast the following piece of code creates a new handle and stores |
| 450 |
it in the Tcl variable \code{new}. |
| 451 |
\begin{verbatim} |
| 452 |
set new [$entry dup] |
| 453 |
$entry forward |
| 454 |
\end{verbatim} |
| 455 |
In this example \code{new} is not effected by the \code{bibtool forward} |
| 456 |
operation on \code{entry}. Even if there is no next entry and |
| 457 |
\code{entry} is invalidated then \code{new} still references the initial |
| 458 |
entry. |
| 459 |
|
| 460 |
We have to come back to \code{bibtool valid} to complete the picture. |
| 461 |
Often it is interesting to know in advance whether the next or |
| 462 |
previous entry exists without duplicating a entry handle and moving |
| 463 |
just to avoid to invalidate a entry handle. For this purpose an |
| 464 |
additional argument can be used. If this optional argument to |
| 465 |
\code{bibtool valid} after the entry handle is \code{-next} or |
| 466 |
\code{-previous} then the existence of the next resp.\ previous entry |
| 467 |
is checked in addition to the validity of the entry handle itself. |
| 468 |
|
| 469 |
Thus the following fragment checks whether there are at least two |
| 470 |
entries in the database \code{\$db}. This is done by positioning a entry at |
| 471 |
the beginning of the database and checking the validity of this |
| 472 |
entry and the next entry: |
| 473 |
\begin{verbatim} |
| 474 |
set rec [$db first] |
| 475 |
if { [bibtool valid $entry] && |
| 476 |
[bibtool valid $entry -previous] } { |
| 477 |
puts {At least two entries.} |
| 478 |
} |
| 479 |
\end{verbatim}%$ |
| 480 |
|
| 481 |
Since we have the possibility to clone a entry handle with |
| 482 |
\code{bibtool dup} or allocate new ones with \code{bibtool first} or |
| 483 |
\code{bibtool last} we need method to compare two entry handles to |
| 484 |
see whether they point to the same entry. This function is called |
| 485 |
\code{bibtool equal}. This function takes two arguments and returns |
| 486 |
\code{1} if they are valid and point to the same entry. If they are |
| 487 |
valid and point to different entries then \code{0} is returned. If |
| 488 |
either one is invalid then an error is raised. |
| 489 |
|
| 490 |
Suppose we have a valid entry handle stored in the Tcl variable |
| 491 |
\code{entry} for which a next entry exists. We execute the following |
| 492 |
piece of code: |
| 493 |
\begin{verbatim} |
| 494 |
set new $entry |
| 495 |
$entry forward |
| 496 |
if {[$entry equal $new]} {print yes} |
| 497 |
\end{verbatim} |
| 498 |
The last line will always produce the answer \code{yes}. This is due |
| 499 |
to the fact that the Tcl variables \code{entry} and \code{new} contain in |
| 500 |
fact the same entry handle. Whereas the following piece of code will |
| 501 |
never produce \code{yes} since here two independent entry handles are |
| 502 |
involved which represent successive entries in the database. |
| 503 |
\begin{verbatim} |
| 504 |
set new [$entry dup] |
| 505 |
$entry forward |
| 506 |
if {[$entry equal $new]} {print yes} |
| 507 |
\end{verbatim} |
| 508 |
|
| 509 |
As an convenient alias the method \code{bibtool ==} is provided as an |
| 510 |
alias for the method \code{bibtool equal}. Thus you can write |
| 511 |
\begin{verbatim} |
| 512 |
if {[$entry == $new]} {print yes} |
| 513 |
\end{verbatim} |
| 514 |
This line will have the same effect as the last line in the example |
| 515 |
above. But beware not to forget the outer brackets. This subtle point |
| 516 |
is illustrated in the following example: |
| 517 |
\begin{verbatim} |
| 518 |
set new [$entry dup] |
| 519 |
if {[$entry == $new]} {print yes} else {print no} |
| 520 |
if { $entry == $new } {print yes} else {print no} |
| 521 |
\end{verbatim}%$ |
| 522 |
According to the explanations given earlier it is not surprising that |
| 523 |
the first conditional prints \code{yes} since both entry handles |
| 524 |
point to the same entry in the database. But they are in fact two |
| 525 |
different handles since \code{new} is derived from \code{entry} with the |
| 526 |
\code{bibtool dup} method. Thus the textual representation of the handles is |
| 527 |
different. These textual representations are compared in the second |
| 528 |
conditional and turn out not to be equal. As a consequence \code{no} |
| 529 |
is printed. |
| 530 |
|
| 531 |
This slight distinction might lead to confusion. If you have problems |
| 532 |
of this kind try to use \code{equal} instead of \code{==}. On the other |
| 533 |
hand the \code{==} notation is very intuitive and you just have to |
| 534 |
take care of the context in which it is evaluated by Tcl. |
| 535 |
|
| 536 |
|
| 537 |
\begin{table}[tp] |
| 538 |
\TclSummaryOO{\meta{ENTRY} backward}{} |
| 539 |
\TclSummary{backward}{\meta{ENTRY}}{Makes \meta{ENTRY} reference |
| 540 |
to the predecessor of its current value. Return \meta{ENTRY} |
| 541 |
upon success. If none is present then delete the entry handle and |
| 542 |
return the empty string.} |
| 543 |
\TclSummaryOO{\meta{ENTRY} delete}{} |
| 544 |
\TclSummary{delete}{\meta{ENTRY}}{Deletes the entry handle |
| 545 |
\meta{ENTRY}. This does not mean that the entry itself is |
| 546 |
modified. Only the reference to it can not be used any more.} |
| 547 |
\TclSummaryOO{\meta{ENTRY} dup}{} |
| 548 |
\TclSummary{dup}{\meta{ENTRY}}{Create a new entry handle pointing |
| 549 |
to the same entry as the entry handle \meta{ENTRY}.} |
| 550 |
\TclSummaryOO{\meta{ENTRY$_1$} equal \meta{ENTRY$_2$}}{} |
| 551 |
\TclSummary{equal}{\meta{ENTRY$_1$} \meta{ENTRY$_2$}}{compares the |
| 552 |
two entries. Returns 1 if they point to the same physical entry.} |
| 553 |
\TclSummaryOO{\meta{ENTRY$_1$} == \meta{ENTRY$_2$}}{} |
| 554 |
\TclSummary{==}{\meta{ENTRY$_1$} \meta{ENTRY$_2$}}{the same as |
| 555 |
\code{equal}.} |
| 556 |
\TclSummaryOO{\meta{ENTRY} fields}{} |
| 557 |
\TclSummary{fields}{\meta{ENTRY}}{Return a list of normal fields in |
| 558 |
the entry.} |
| 559 |
\TclSummaryOO{\meta{ENTRY} remove}{} |
| 560 |
\TclSummary{remove}{\meta{ENTRY}}{Remove the entry from its |
| 561 |
database. The handle is invalidated. The entry ceases to exist.} |
| 562 |
\TclSummaryOO{\meta{ENTRY} valid \meta{?-next\(\mid\)-previous?}}{} |
| 563 |
\TclSummary{valid}{\meta{ENTRY} \meta{?-next\(\mid\)-previous?}}{ |
| 564 |
check whether the entry handle \meta{ENTRY} is still valid. If |
| 565 |
the optional argument \meta{-previous} or \meta{-next} is given |
| 566 |
then it is also checked whether the previous or next entry |
| 567 |
exists. \code{1} is returned when all tests are |
| 568 |
successful. Otherwise \code{0} is returned.} |
| 569 |
|
| 570 |
\caption{Summary of entry operations}\label{fig:tcl-entry} |
| 571 |
\rule{\textwidth}{.1pt} |
| 572 |
\end{table} |
| 573 |
|
| 574 |
|
| 575 |
\section{Entry Fields}\label{sec:fields} |
| 576 |
|
| 577 |
As a database consists of a set of entries, any entry consists of a |
| 578 |
set of fields. The fields are determined by their name. Each name is |
| 579 |
unique within a entry. In addition to the name any field has a value. |
| 580 |
\BibTeX{} itself does not impose much restrictions on the allowed |
| 581 |
fields---except that they have some minor syntactic restrictions. |
| 582 |
Especially there is only one field which is treated special. This is |
| 583 |
the \code{crossref} field which is used for inheritance. Before we |
| 584 |
come to this point we want to present a method how to check for |
| 585 |
existing and not existing fields. |
| 586 |
|
| 587 |
The method \code{bibtool fields} of a entry returns the list of all |
| 588 |
fields defined in a entry. For instance we can reconsider the |
| 589 |
\BibTeX{} entry on page~\pageref{example:bibtool}. Suppose the Tcl |
| 590 |
variable \code{entry} contains a handle pointing to this entry then |
| 591 |
\begin{verbatim} |
| 592 |
fields $entry |
| 593 |
\end{verbatim}%$ |
| 594 |
\noindent |
| 595 |
would return the following list of fields: |
| 596 |
\begin{verbatim} |
| 597 |
author title edition year |
| 598 |
\end{verbatim} |
| 599 |
|
| 600 |
In addition to the normal fields which are stored directly in the |
| 601 |
entry, some information can be acessed as if it was stored in a |
| 602 |
field. Those pseudo-fields will be discussed later. |
| 603 |
|
| 604 |
To check for the existence or non-existence of a field one would could |
| 605 |
extract the list of fields and use the Tcl command \code{lsearch}. To |
| 606 |
avoid the overhead of constructing the intermediate list the method |
| 607 |
\code{bibtool missing} is provided. |
| 608 |
\begin{verbatim} |
| 609 |
$entry missing publisher |
| 610 |
\end{verbatim}%$ |
| 611 |
This invocation returns \code{1} if there is no field with the name |
| 612 |
|publisher| in the entry \code{entry}. Otherwise \code{0} is returned. |
| 613 |
As always an error is raised if \code{entry} does not contain a valid |
| 614 |
entry handle. |
| 615 |
|
| 616 |
Now we come to the access methods for field values. We need a way to |
| 617 |
retrieve the value and a method to modify the value. The first |
| 618 |
approach to retrieve a value is using the method \code{bibtool get}. |
| 619 |
It takes a entry handle and a field name and returns the contents of |
| 620 |
the field as a string. Let us consider the following example: |
| 621 |
\begin{verbatim} |
| 622 |
@String{ BibTool = {{BibTool}} } |
| 623 |
@Manual{ neugebauer:bibtcl, |
| 624 |
title = BibTool # { -- Tcl Programmers Manual}, |
| 625 |
crossref = {neugebauer:bibtool}, |
| 626 |
remark = {Distributed with BibTool} |
| 627 |
} |
| 628 |
\end{verbatim} |
| 629 |
If we want to get the value of the \code{remark} field we can use the |
| 630 |
following method: |
| 631 |
\begin{verbatim} |
| 632 |
$entry get remark |
| 633 |
\end{verbatim}%$ |
| 634 |
This command returns the contents of the remark field as string. Thus |
| 635 |
the result is the Tcl string |
| 636 |
\begin{verbatim} |
| 637 |
Distributed with BibTool |
| 638 |
\end{verbatim} |
| 639 |
The example has been chosen to illustrate some other points as well. |
| 640 |
In this example a \BibTeX{} macro \code{BibTool} is defined which |
| 641 |
contains the \BibTool{} logo protected from case changes in \BibTeX. |
| 642 |
This macro is used in the title field with the concatenation operator |
| 643 |
\code{\#}. Now we want to get the value of the title field: |
| 644 |
\begin{verbatim} |
| 645 |
$entry get title |
| 646 |
\end{verbatim}%$ |
| 647 |
This command yields as a result the string representation of the title |
| 648 |
field. For this purpose all macros are replaced by their values and |
| 649 |
the resultings strings are concatenated. Thus the result is |
| 650 |
\begin{verbatim} |
| 651 |
{BibTool} -- Tcl Programmers Manual |
| 652 |
\end{verbatim} |
| 653 |
Note that the outer double quotes or braces are not contained in the |
| 654 |
result but inner braces or doulbe quotes are. This is due to the fact |
| 655 |
that the result is a Tcl string which does not need additional |
| 656 |
delimiters. |
| 657 |
|
| 658 |
What would have happend if the macro \code{BibTool} would not have |
| 659 |
been defined? In this case the result of the macro expansion is the |
| 660 |
empty string. This empty string would have been concatenated with the |
| 661 |
rest yielding the result |
| 662 |
\begin{verbatim} |
| 663 |
-- Tcl Programmers Manual |
| 664 |
\end{verbatim} |
| 665 |
|
| 666 |
Sometimes it is undesirable to get the expanded version of the value. |
| 667 |
For instance if you want to take advantage of the \BibTeX{} macro |
| 668 |
feature and manipulate things yourself. For this purpose the optional |
| 669 |
flag \code{-noexpand} can be used. If this flag is given the result is |
| 670 |
a Tcl list consisting of strings which contain the components of the |
| 671 |
value. In this case the delimiters (\verb|{}| or \verb|""|) are part |
| 672 |
of the elements to distinguish the string constants from macros. Thus |
| 673 |
the command |
| 674 |
\begin{verbatim} |
| 675 |
$entry get title -noexpand |
| 676 |
\end{verbatim}%$ |
| 677 |
\noindent |
| 678 |
leads to a Tcl list with the following two elements: |
| 679 |
\begin{verbatim} |
| 680 |
BibTool |
| 681 |
{ -- Tcl Programmers Manual} |
| 682 |
\end{verbatim} |
| 683 |
|
| 684 |
Next we have to consider the case that we are asking for a field |
| 685 |
which does not exist in the entry considered. For instance we might |
| 686 |
ask for the author field: |
| 687 |
\begin{verbatim} |
| 688 |
$entry get author |
| 689 |
\end{verbatim}%$ |
| 690 |
Since the entry does not contain an \code{author} field we get the |
| 691 |
empty string as the result. |
| 692 |
|
| 693 |
\BibTeX{} has the feature to use the \code{crossref} field for |
| 694 |
inheritance. If a field is missing in a entry but it has a |
| 695 |
\code{crossref} field then the field is sought in the entry whose key |
| 696 |
is the value of the \code{crossref} field as well. |
| 697 |
This behaviour can be triggered with the optional flag \code{-all} of |
| 698 |
the method \code{bibtool get}: |
| 699 |
\begin{verbatim} |
| 700 |
$entry get author -all |
| 701 |
\end{verbatim}%$ |
| 702 |
In our example the entry \code{neugebauer:bibtool} would be |
| 703 |
considered in this case. If we assume that this entry---as given on |
| 704 |
page~\pageref{example:bibtool}---is also present in the database then the |
| 705 |
result is the string |
| 706 |
\begin{verbatim} |
| 707 |
Gerd Neugebauer |
| 708 |
\end{verbatim} |
| 709 |
|
| 710 |
In addition to the normal fields some pseudo-fields can be queried. |
| 711 |
These pseudo-fields give access to information not really stored as a |
| 712 |
field but present for a entry, a database, or as a global value in |
| 713 |
other form. One such a pseudo-field is the citation key. This citation |
| 714 |
key can be referenced as \code{\$key}. Thus the citation key can be |
| 715 |
retrieved with the following Tcl construct: |
| 716 |
\begin{verbatim} |
| 717 |
set key [$entry get {$key}] |
| 718 |
\end{verbatim} |
| 719 |
Since the \code{\$} is a special character for Tcl it has to be |
| 720 |
protected to be not evaluated by Tcl. |
| 721 |
For our example the entry as given on page~\pageref{example:bibtool} |
| 722 |
this command will set the Tcl variable \code{key} to the value |
| 723 |
\begin{verbatim} |
| 724 |
neugebauer:bibtcl |
| 725 |
\end{verbatim} |
| 726 |
|
| 727 |
\begin{table}[t] |
| 728 |
\begin{center}\doublerulesep=.4pt |
| 729 |
\begin{tabular}{lp{.6\textwidth}}\hline\hline |
| 730 |
{\it pseudo field name}\rule[-1.5ex]{0pt}{4ex} & |
| 731 |
{\it meaning}\\\hline\rule{0pt}{3ex}% |
| 732 |
\code{\$key} & The citation key. \\ |
| 733 |
\code{\$sortkey} & The sort key, i.e.\ the string used |
| 734 |
for sorting entries.\\ |
| 735 |
\code{\$source} & The file the entry is read from or |
| 736 |
the empty string. \\ |
| 737 |
\code{\$type} & The type of the entry. \\ |
| 738 |
\code{\$default.key} & The value of the resource |
| 739 |
\code{default.key}. This string is |
| 740 |
used as a key if the key specification |
| 741 |
failes completely.\\ |
| 742 |
\code{\$fmt.et.al} & The value of the resource |
| 743 |
\code{fmt.et.al}. This string is used |
| 744 |
to abbreviate unnamed additional authors.\\ |
| 745 |
\code{\$fmt.name.pre} & The value of the resource |
| 746 |
\code{fmt.name.pre}. This string is |
| 747 |
inserted between the first name and |
| 748 |
the last name.\\ |
| 749 |
\code{\$fmt.inter.name} & The value of the resource |
| 750 |
\code{fmt.inter.name}. This string is |
| 751 |
inserted between several last names of |
| 752 |
one person.\\ |
| 753 |
\code{\$fmt.name.name} & The value of the resource |
| 754 |
\code{fmt.name.name}. This string is |
| 755 |
inserted between two names.\\ |
| 756 |
\code{\$fmt.name.title} & The value of the resource |
| 757 |
\code{fmt.name.title} This string is |
| 758 |
inserted between name and title.\\ |
| 759 |
\code{\$fmt.title.title}& The value of the resource |
| 760 |
\code{fmt.title.title}. This string is |
| 761 |
inserted between different words of |
| 762 |
the title.\\ |
| 763 |
\code{\$fmt.key.number} & The value of the resource |
| 764 |
\code{fmt.key.number}. This string is |
| 765 |
inserted between the generated key and |
| 766 |
the disambiguating number.\\[1ex] |
| 767 |
\hline\hline |
| 768 |
\end{tabular} |
| 769 |
\caption{Some pseudo fields}\label{tab:pseudo-fields} |
| 770 |
\end{center} |
| 771 |
\end{table} |
| 772 |
Table~\ref{tab:pseudo-fields} contains a list of pseudo fields. There |
| 773 |
are more pseudo fields which can be found in the \BibTool{} |
| 774 |
documentation. But the additional pseudo fields can not be considered |
| 775 |
really important in the context of Tcl. |
| 776 |
|
| 777 |
|
| 778 |
Now we come to the opposite operation. We want to set the value of a |
| 779 |
field to a given string. For this purpose the method \code{bibtool |
| 780 |
set} is provided. This method takes a field name and a string or a list |
| 781 |
of components and sets the value accordingly. Since Tcl does not |
| 782 |
distinguish between a list and a string the second case has to be |
| 783 |
marked with the flag \code{-concat}. The effect of this operation is |
| 784 |
that the field has the given value afterwards. If the field did not |
| 785 |
exist already then this field is added to the entry. |
| 786 |
|
| 787 |
Let us consider an example. The simplest desire is to set the value of |
| 788 |
a field to new string. Suppose we want to change the value of the |
| 789 |
remark field then this can be done as follows: |
| 790 |
\begin{verbatim} |
| 791 |
$entry set remark {Distributed as part of BibTool} |
| 792 |
\end{verbatim}%$ |
| 793 |
Suppose we want to change the value of the field edition from |
| 794 |
\code{2.41} to \code{2.42}. This field is not present in the entry |
| 795 |
but inherited via a \code{crossref} field. Nevertheless this is not |
| 796 |
honored by \code{bibtool set}. A new field is added to this entry |
| 797 |
containing the new value. The other entry is left unchanged. |
| 798 |
|
| 799 |
Suppose we want to add a field \code{month} to the entry. This is one |
| 800 |
place where \BibTeX{} macros are indispensible. Instead of using the |
| 801 |
constant \verb|"June"| we should always use the macro \code{jun} which |
| 802 |
is defined by most \BibTeX{} styles. Thus the \BibTeX{} style designer |
| 803 |
can decide to use the full month name, an abbreviation, or even switch |
| 804 |
to a different language. |
| 805 |
|
| 806 |
If we write |
| 807 |
\begin{verbatim} |
| 808 |
$entry set month jun |
| 809 |
\end{verbatim}%$ |
| 810 |
\noindent |
| 811 |
then the result would be the string \code{jun} and not the \BibTeX{} |
| 812 |
macro. Thus we have to use the flag \code{-concat}. |
| 813 |
\begin{verbatim} |
| 814 |
$entry set month jun -concat |
| 815 |
\end{verbatim}%$ |
| 816 |
This works fine since Tcl does not distinguish the one string |
| 817 |
\code{jun} from the list containing \code{jun} as a single element. |
| 818 |
Nevertheless the correct way would be to use a construction like the |
| 819 |
following one: |
| 820 |
\begin{verbatim} |
| 821 |
$entry set month [list jun] -concat |
| 822 |
\end{verbatim}%$ |
| 823 |
If we want to add a specific day as well then this can be done like in |
| 824 |
the following example\footnote{Note that this does not allow switching |
| 825 |
the languages any more so easy. But this is not our topic here.} |
| 826 |
\begin{verbatim} |
| 827 |
$entry set month [list jun {{~13}}] -concat |
| 828 |
\end{verbatim}%$ |
| 829 |
Beware, \BibTool{} does not check the structure or the contents of |
| 830 |
field values. Thus you have to be careful to use only valid components |
| 831 |
in order for \BibTeX{} to work properly. |
| 832 |
|
| 833 |
\begin{table}[tp] |
| 834 |
\TclSummary{fields}{\meta{ENTRY}}{This command returns a list of |
| 835 |
field names in \meta{ENTRY}.} |
| 836 |
\TclSummaryOO{\meta{ENTRY} forward}{} |
| 837 |
\TclSummary{forward}{\meta{ENTRY}}{Makes \meta{ENTRY} |
| 838 |
reference to the successor of its current value. Return |
| 839 |
\meta{ENTRY} upon success. If none is present then delete the |
| 840 |
entry handle and return the empty string.} |
| 841 |
\TclSummaryOO{\meta{ENTRY} get \meta{FIELD} |
| 842 |
\meta{?-noexpand$\mid$-all?}}{} |
| 843 |
\TclSummary{get}{\meta{ENTRY} \meta{FIELD} \meta{?-noexpand?} |
| 844 |
\meta{?-all?}}{This command returns the value of the field |
| 845 |
\meta{FIELD} in the entry \meta{ENTRY}. The value returned has |
| 846 |
all strings expanded. If the option \meta{-noexpand} is given then the |
| 847 |
unexpanded form as it is contained in the database is returned. If |
| 848 |
the option \meta{-all} is given then the inheritance via crossref is |
| 849 |
honored. I.e. each missing field is extracted from the crossrefed |
| 850 |
entry (etc). If the field does not exist then the empty string is |
| 851 |
returned.} |
| 852 |
\TclSummaryOO{\meta{ENTRY} missing \meta{FIELD}}{} |
| 853 |
\TclSummary{missing}{\meta{ENTRY} \meta{FIELD}}{This command returns |
| 854 |
\code{1} if the field \meta{FIELD} is missing in the entry |
| 855 |
\meta{ENTRY}. Otherwise it returns \code{0}.} |
| 856 |
\TclSummaryOO{\meta{ENTRY} remove \meta{FIELD}}{} |
| 857 |
\TclSummary{remove}{\meta{ENTRY} \meta{FIELD}}{Delete the field |
| 858 |
\meta{FIELD} from the entry \meta{ENTRY}. If it does not exist |
| 859 |
then nothing is changed.} |
| 860 |
\TclSummaryOO{\meta{ENTRY} set \meta{FIELD} \meta{VALUE}}{} |
| 861 |
\TclSummary{set}{\meta{ENTRY} \meta{FIELD} \meta{VALUE}}{This command |
| 862 |
changes the value of the field or pseudo field \meta{FIELD} to |
| 863 |
\meta{VALUE}. The field is added if it has not been present |
| 864 |
already.} |
| 865 |
|
| 866 |
\caption{Summary of field operations}\label{fig:tcl-field} |
| 867 |
\rule{\textwidth}{.1pt} |
| 868 |
\end{table} |
| 869 |
|
| 870 |
To complete the operations on entry fields we need a method to get |
| 871 |
rid of a certain field. For this purpose the method \code{bibtool |
| 872 |
remove} can be used. We have seen this method already on |
| 873 |
page~\pageref{bibtool:remove}. If a field is given together with the |
| 874 |
entry then this field is removed from the entry. Thus |
| 875 |
\begin{verbatim} |
| 876 |
$entry remove remark |
| 877 |
\end{verbatim}%$ |
| 878 |
Deletes the \code{remark} field from the given entry. If the field is |
| 879 |
not present in the entry given then nothing is done. This can be |
| 880 |
especially confusing if a field is inherited via a \code{crossref} |
| 881 |
field. The value can be retrieved with the \code{bibtool get} method |
| 882 |
even when the field has been removed: |
| 883 |
\begin{verbatim} |
| 884 |
$entry remove author |
| 885 |
$entry get author -all |
| 886 |
\end{verbatim} |
| 887 |
The result of the second command is \code{Gerd Neugebauer} even so the |
| 888 |
field has been deleted before. |
| 889 |
|
| 890 |
|
| 891 |
\section{Key Generation} |
| 892 |
|
| 893 |
The generation of new reference keys has been one of the first |
| 894 |
functionalities present in \BibTool. The keys are generated according |
| 895 |
to a specification described in detail in the \BibTool{} |
| 896 |
documentation. Thus it is not repeated here. |
| 897 |
|
| 898 |
The format specification can be specified with a resource command (see |
| 899 |
section~\ref{sec:tcl-resources}. For convenience the command |
| 900 |
\code{bibtool key.format} is provided. It can be used to set the key |
| 901 |
format. It is important to construct the argument such that the string |
| 902 |
which arrives in the resource command is has the proper syntax. This |
| 903 |
means that you have to be careful which characters might need |
| 904 |
quoting. The easiest way is to enclose the complete format with |
| 905 |
braces. Thus nearly everything works as expected. |
| 906 |
|
| 907 |
\begin{table}[t] |
| 908 |
\begin{center}\doublerulesep=.4pt |
| 909 |
\begin{tabular}{lp{.6\textwidth}}\hline\hline |
| 910 |
{\it special format}\rule[-1.5ex]{0pt}{4ex} & |
| 911 |
{\it meaning}\\\hline\rule{0pt}{3ex}% |
| 912 |
\code{empty} & Use the default key. \\ |
| 913 |
\code{short} & Use the last names of authors or editors and the |
| 914 |
first relevant word from the title. \\ |
| 915 |
\code{long} & Use the names of authors or editors with |
| 916 |
initials and the first relevant word from the title. \\ |
| 917 |
\code{new.short} & Like \code{short} but only applied to entries |
| 918 |
without a key.\\ |
| 919 |
\code{new.long} & Like \code{long} but only applied to entries |
| 920 |
without a key.\\[1ex] |
| 921 |
\hline\hline |
| 922 |
\end{tabular} |
| 923 |
\caption{Special format specifiers}\label{tab:special-keys} |
| 924 |
\end{center} |
| 925 |
\end{table} |
| 926 |
Usually the function \code{bibtool key.format} adds the given format |
| 927 |
specification as a further alternative after the specification already |
| 928 |
present. Thus it is possible to iteratively construct the |
| 929 |
specification by giving cases in decreasing order. This exception to |
| 930 |
this rule are the special specifications shown in |
| 931 |
Table~\ref{tab:special-keys}. Those special specifiers are not added |
| 932 |
but they entirely replace the old values. Thus the following |
| 933 |
instruction can be used to clear the old value before adding new |
| 934 |
alternatives: |
| 935 |
\begin{verbatim} |
| 936 |
bibtool key.format {empty} |
| 937 |
\end{verbatim} |
| 938 |
Two practical schemes are provided as convenient abbreviations, namely |
| 939 |
\code{short} and \code{long}. They use the names of authors or editors |
| 940 |
of a entry together with the first relevant word of the title. |
| 941 |
\begin{verbatim} |
| 942 |
bibtool key.format {short} |
| 943 |
\end{verbatim} |
| 944 |
The relevant word is determined by skipping over all words which are |
| 945 |
added to the list of ignored words with \code{bibtool ignored.word}. |
| 946 |
This list usually contains articles from different languages. and is |
| 947 |
initialized at compile time. |
| 948 |
|
| 949 |
Now we are ready to generate a new key. This cam be done either |
| 950 |
globally by applying the function \code{bibtool key} to a database. In |
| 951 |
this case the new key is generated for each entry in this database. |
| 952 |
\begin{verbatim} |
| 953 |
bibtool key $db |
| 954 |
\end{verbatim}%$ |
| 955 |
|
| 956 |
The alternative is to apply they key generation algorithm to a single |
| 957 |
entry. In this case only the key of this entry is generated. As a |
| 958 |
side effect the new key of this entry is returned. |
| 959 |
\begin{verbatim} |
| 960 |
set key [bibtool key $entry] |
| 961 |
puts $key |
| 962 |
\end{verbatim} |
| 963 |
|
| 964 |
\INCOMPLETE |
| 965 |
|
| 966 |
|
| 967 |
\begin{table}[tp] |
| 968 |
\TclSummary{key}{\meta{ENTRY}}{This command creates a new reference |
| 969 |
key for \meta{ENTRY} according to the specification in effect and |
| 970 |
stores it in \meta{ENTRY}. This string is returned.} |
| 971 |
\TclSummary{key}{\meta{DB}}{This command creates a new reference |
| 972 |
key for each entry in \meta{DB} according to the specification in |
| 973 |
effect. The empty string is returned.} |
| 974 |
\TclSummary{key.format}{=\meta{FORMAT}}{} |
| 975 |
\TclSummary{ignored.word}{=\meta{WORD}}{} |
| 976 |
|
| 977 |
\caption{Summary of key generation operations}\label{fig:tcl-keys} |
| 978 |
\rule{\textwidth}{.1pt} |
| 979 |
\end{table} |
| 980 |
|
| 981 |
|
| 982 |
\section{Ignored Words} |
| 983 |
|
| 984 |
The format specifier for key generation or sorting can request that |
| 985 |
certain words are ignored. Those words are managed in a global list in |
| 986 |
\BibTool. Some commands are provided to manipulate this list. Some |
| 987 |
operations are already provided as resources. Nevertheless a more |
| 988 |
convenient form is provided as well. |
| 989 |
|
| 990 |
The list of ignored words is initialized at compile time. Usually this |
| 991 |
list contains articles in different languages since they are usually |
| 992 |
ignored when dealing with titles of publications. |
| 993 |
|
| 994 |
This list can be augmented with additional words with the command |
| 995 |
\code{bibtool add\_ignored}. This command adds add arguments to the |
| 996 |
list of ignored words. The following example should be superfluous but |
| 997 |
it illustrates the application of this operation: |
| 998 |
\begin{verbatim} |
| 999 |
bibtool add_ignored the a an |
| 1000 |
\end{verbatim}% |
| 1001 |
|
| 1002 |
If you are not satisfied with the compiled in list of ignored words |
| 1003 |
you can clear this list with the command \code{bibtool |
| 1004 |
clear\_ignored}. After this operation the list of ignored words is |
| 1005 |
empty and can be filled from scratch. |
| 1006 |
\begin{verbatim} |
| 1007 |
bibtool clear_ignored |
| 1008 |
\end{verbatim}% |
| 1009 |
|
| 1010 |
The operations above could also be achieved with resource commands. We |
| 1011 |
just need an additional operation which returns the list of ignored |
| 1012 |
words. This operation is performed by \code{bibtool get\_ignored}. The |
| 1013 |
result can be stored in a Tcl variable and used in any way you like: |
| 1014 |
\begin{verbatim} |
| 1015 |
set ignored [bibtool get_ignored] |
| 1016 |
\end{verbatim}% |
| 1017 |
|
| 1018 |
|
| 1019 |
\begin{table}[tp] |
| 1020 |
\TclSummary{ignored.word}{=\meta{WORD}}{} |
| 1021 |
\TclSummary{add\_ignored}{\meta{WORD} \ldots}{This command add all |
| 1022 |
arguments to the list of ignored words.} |
| 1023 |
\TclSummary{clear.ignored.words}{\{\}}{} |
| 1024 |
\TclSummary{clear\_ignored}{}{This command removes all words from |
| 1025 |
the list of ignored words.} \TclSummary{get\_ignored}{}{This |
| 1026 |
command returns the list of ignored words.} |
| 1027 |
|
| 1028 |
\caption{Summary of operations on ignored words}\label{fig:tcl-ignored} |
| 1029 |
\rule{\textwidth}{.1pt} |
| 1030 |
\end{table} |
| 1031 |
|
| 1032 |
\section{\BibTeX{} Macros} |
| 1033 |
|
| 1034 |
In section~\ref{sec:fields} we have already seen \BibTeX{} macros and |
| 1035 |
their expansion when the value of a field is retrieved. Since it is |
| 1036 |
possible to get the value of a field in unexpanded form we need a way |
| 1037 |
to get our hands on the value of a macro. For this purpose the database |
| 1038 |
method \code{bibtool string\_get} is provided. |
| 1039 |
\begin{verbatim} |
| 1040 |
$db string_get BibTool |
| 1041 |
\end{verbatim}%$ |
| 1042 |
\noindent returns the value of the string \code{BibTool} as Tcl |
| 1043 |
string. If this macro is not defined then the empty string is |
| 1044 |
returned. The same remarks as for the values of fields hold for |
| 1045 |
\BibTeX{} macros as well. They can be defined in terms of other macros |
| 1046 |
with the concatenation operation (\verb|#|). If you want to get the |
| 1047 |
unexpanded definition the you have to use the flag \code{-noexpand}. In |
| 1048 |
this case the value returned is a list of components to be |
| 1049 |
concatenated. In this case the string delimters are included to allow |
| 1050 |
you to distinguish strings---which are enclosed in delimiters---from |
| 1051 |
macros. |
| 1052 |
|
| 1053 |
The reverse operation to accessing a macro value is the definition of |
| 1054 |
one. Analogeously to field values the method \code{bibtool string\_set} |
| 1055 |
can be used. This method takes a macro name and a string and arranges |
| 1056 |
that the macro expands to the string given: |
| 1057 |
\begin{verbatim} |
| 1058 |
$db string_set BibTool {{\sffamily BibTool}} |
| 1059 |
\end{verbatim}%$ |
| 1060 |
|
| 1061 |
\INCOMPLETE |
| 1062 |
|
| 1063 |
\begin{verbatim} |
| 1064 |
$db string_set BibTool [list Bib Tool] -concat |
| 1065 |
\end{verbatim}%$ |
| 1066 |
|
| 1067 |
If the value of a macro is the empty string we can not distinguish the |
| 1068 |
case that the macro is not defined at all from the case that the macro |
| 1069 |
is defined and has the empty string as its value. To allow this |
| 1070 |
differtiation the method \code{bibtool string missing} can be used: |
| 1071 |
\begin{verbatim} |
| 1072 |
$db string_missing BibTool |
| 1073 |
\end{verbatim}%$ |
| 1074 |
This method returns \code{1} if the macro \code{BibTool} is not |
| 1075 |
defined and \code{0} otherwise. Thus we would get \code{0} in our |
| 1076 |
example. |
| 1077 |
|
| 1078 |
\begin{table}[tp] |
| 1079 |
\TclSummaryOO{\meta{DB} string\_get \meta{MACRO} \meta{?-global?}}{} |
| 1080 |
\TclSummary{string\_get}{\meta{DB} \meta{MACRO} |
| 1081 |
\meta{?-global?}}{This command retieves the value of the macro |
| 1082 |
\meta{MACRO} from the database \meta{DB} or the global set of |
| 1083 |
macros. If the flag \meta{-global} is given then only the global |
| 1084 |
maros are considered.} |
| 1085 |
|
| 1086 |
\TclSummaryOO{\meta{DB} string\_missing \meta{MACRO} \meta{?-global?}}{} |
| 1087 |
\TclSummary{string\_missing}{\meta{DB} \meta{MACRO} |
| 1088 |
\meta{?-global?}}{This tests whether the macro \meta{MACRO} is |
| 1089 |
defined in the database \meta{DB} or the global macros. If the flag |
| 1090 |
\meta{-global} is given then only the global macros are |
| 1091 |
considered.} |
| 1092 |
|
| 1093 |
\TclSummaryOO{\meta{DB} string\_remove \meta{MACRO} \meta{?-global?}}{} |
| 1094 |
\TclSummary{string\_remove}{\meta{DB} \meta{MACRO} |
| 1095 |
\meta{?-global?}}{Remove the definition of the macro \meta{MACRO} |
| 1096 |
from the database \meta{DB}. If the flag \meta{-global} is given |
| 1097 |
then the global macros are considered only.} |
| 1098 |
|
| 1099 |
\TclSummaryOO{\meta{DB} string\_set \meta{MACRO} \meta{VALUE} |
| 1100 |
\meta{?-global?}}{} |
| 1101 |
\TclSummary{string\_set}{\meta{DB} \meta{MACRO} \meta{VALUE} |
| 1102 |
\meta{?-global?}}{This command assigns the new value \meta{VALUE} to |
| 1103 |
the macro \meta{MACRO} in the database \meta{DB}. If the flag |
| 1104 |
\meta{-global} is given then the change is not made local to the |
| 1105 |
database but in the global set of macros.} |
| 1106 |
|
| 1107 |
\caption{Summary of macro operations}\label{fig:tcl-macro} |
| 1108 |
\rule{\textwidth}{.1pt} |
| 1109 |
\end{table} |
| 1110 |
|
| 1111 |
Since we are now able to distinguish a not existing macro from an empty |
| 1112 |
macro we need a method to get rid of a macro completely. This can be |
| 1113 |
accomplished with the method \code{bibtool string\_remove}: |
| 1114 |
\begin{verbatim} |
| 1115 |
$db string_remove BibTool |
| 1116 |
\end{verbatim}%$ |
| 1117 |
After this operation the macro \code{BibTool} is missing. If the given |
| 1118 |
macro has not been defined in the database then nothing will be done. |
| 1119 |
Otherwise the macro definition is removed from the database. |
| 1120 |
|
| 1121 |
Finally we might be interested to get a complete list of all macros |
| 1122 |
defined for a database. For this purpose the method \code{bibtool |
| 1123 |
strings} can be used which returns the names of all macros as a Tcl |
| 1124 |
list: |
| 1125 |
\begin{verbatim} |
| 1126 |
$db strings |
| 1127 |
\end{verbatim}%$ |
| 1128 |
|
| 1129 |
|
| 1130 |
\section{Embedding \LaTeXTeX{} Macros} |
| 1131 |
|
| 1132 |
\begin{verbatim} |
| 1133 |
$db preamble |
| 1134 |
\end{verbatim}%$ |
| 1135 |
|
| 1136 |
\INCOMPLETE |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
\section{De\TeX ing} |
| 1141 |
|
| 1142 |
When you are dealing with \LaTeXTeX{} commands it is pretty easy to |
| 1143 |
get rid of macros. This cam be done with a \code{regsub} command wich |
| 1144 |
matches the macro names and replaces them by the empty string. Suppose |
| 1145 |
the Tcl variable \code{str} contains a string which should be |
| 1146 |
de\TeX{}ed. |
| 1147 |
\begin{verbatim} |
| 1148 |
regsub -all {\\([^a-zA-Z]|[a-zA-Z]+)} $str {} str |
| 1149 |
\end{verbatim}%$ |
| 1150 |
After the invocation of this command the Tcl variable \code{str} |
| 1151 |
has all macro names stripped. For instance the string |
| 1152 |
\begin{verbatim} |
| 1153 |
M{\"u}ller GmbH{\&}Co. |
| 1154 |
\end{verbatim} |
| 1155 |
\noindent is translated to |
| 1156 |
\begin{verbatim} |
| 1157 |
Muller GmbH{}Co. |
| 1158 |
\end{verbatim} |
| 1159 |
Even if the first substitution might be acceptable for non-German |
| 1160 |
speaking people then the second replancement is by far too aggressive. |
| 1161 |
On the other side we could just replace the backslashes. This can be |
| 1162 |
done with a Tcl command like |
| 1163 |
\begin{verbatim} |
| 1164 |
regsub -all {\\} $str {} str |
| 1165 |
\end{verbatim}%$ |
| 1166 |
\noindent results in |
| 1167 |
\begin{verbatim} |
| 1168 |
M"uller GmbH{&}Co. |
| 1169 |
\end{verbatim} |
| 1170 |
This leaves the \code{\&} but also the crippled \verb|"|. Th eother |
| 1171 |
problem are the arguments. They require matching braces. this can not |
| 1172 |
be expressed with regular expressions. Thus \BibTool{} provides a |
| 1173 |
command to define \TeX{} macros and expand in a string them. |
| 1174 |
|
| 1175 |
The command \code{bibtool tex define} can be used to define \TeX{} macros |
| 1176 |
which should be used for expansion lateron. For our previous example |
| 1177 |
we would have needed the following definitions: |
| 1178 |
\begin{verbatim} |
| 1179 |
bibtool tex define {\&=&} |
| 1180 |
bibtool tex define {\"[1]=#1e} |
| 1181 |
\end{verbatim} |
| 1182 |
The argument of \code{bibtool tex define} is one string containing a |
| 1183 |
control sequence on the left side optionally followed by the number of |
| 1184 |
arguments in brackets. It is completed by a equality sign and the |
| 1185 |
replacement text. If no arguments are given then the macro is assumed |
| 1186 |
to have no arguments. |
| 1187 |
|
| 1188 |
In the example above the first definition makes a macro \verb|\&| |
| 1189 |
without arguments and the second definition makes \verb|\"| a macro |
| 1190 |
with one argment. Like in \LaTeX{} the sequence \verb|#|$n$ represents |
| 1191 |
the $n^{th}$ argument.\footnote{Note that in German ae is the |
| 1192 |
representation of \"a without the umlaut accent.} |
| 1193 |
|
| 1194 |
There is one additional case which has not been described already. If |
| 1195 |
you are a little bit familiar with \TeX{} you might know that you can |
| 1196 |
make a character active and assign a macro to this character. Thus you |
| 1197 |
can omit the leading backslash. |
| 1198 |
|
| 1199 |
This case is coverd in \code{bibtool tex define} as well. If the macro |
| 1200 |
name consists of a single character only which is not the backslash |
| 1201 |
then this character is made active then the remainder is used to |
| 1202 |
assign a macro to it. |
| 1203 |
|
| 1204 |
As a side note I want to note that the reading and macro expansion |
| 1205 |
apparatus of \TeX{} is internally imitated to a certain degree. This |
| 1206 |
included catagory codes. But those catagory codes can (currently) not |
| 1207 |
be modified except by making a character active as described above. |
| 1208 |
|
| 1209 |
Initially no macros are defined in \BibTool. This can also be reached |
| 1210 |
with the following command: |
| 1211 |
\begin{verbatim} |
| 1212 |
bibtool tex reset |
| 1213 |
\end{verbatim} |
| 1214 |
After this command has been executed no macros are defined an no |
| 1215 |
characters are active. |
| 1216 |
|
| 1217 |
But now we want to come to the point where we make use of thsoe |
| 1218 |
definitions. This is achieved with the caommand \code{bibtool tex |
| 1219 |
expand}. All defined macros are replaced by their replacement |
| 1220 |
text. Undefined macros are left unchanged. Thus we could use the |
| 1221 |
following invocation: |
| 1222 |
\begin{verbatim} |
| 1223 |
set str [bibtool tex expand $str] |
| 1224 |
\end{verbatim}%$ |
| 1225 |
With the definitions given above and the value of the Tcl variable |
| 1226 |
\code{str} given in the example above we get as a result the following |
| 1227 |
new value in the Tcl variable \code{str}: |
| 1228 |
\begin{verbatim} |
| 1229 |
M{ue}ller GmbH{&}Co. |
| 1230 |
\end{verbatim} |
| 1231 |
Now we could savely strip the braces (and possibly remaining \TeX{} |
| 1232 |
macros with the method described above. |
| 1233 |
|
| 1234 |
\begin{table}[tp] |
| 1235 |
\TclSummary{tex define}{\meta{mac?[n]?=repl}}{Define the \TeX{} macro |
| 1236 |
or active character \meta{mac}. If \meta{[n]} is given then \meta{n} |
| 1237 |
must be a single digit which is interpreted as the muber of |
| 1238 |
arguments of the macro. The replacement text is \meta{repl}. In |
| 1239 |
ttthe replacement text \code{\#}\meta{n} represents the |
| 1240 |
\meta{n}$^{th}$ macro argument.} |
| 1241 |
|
| 1242 |
\TclSummary{tex expand}{\meta{STRING}}{This command returns the |
| 1243 |
string which results from \meta{STRING} by replacing each defined |
| 1244 |
macro or active character and the optional arguments by it's |
| 1245 |
replacement text.} |
| 1246 |
|
| 1247 |
\TclSummary{tex reset}{}{This command deletes all macros and active |
| 1248 |
characters previously defined.} |
| 1249 |
|
| 1250 |
\caption{Summary of operations on \TeX{} strings}\label{fig:tcl-tex} |
| 1251 |
\rule{\textwidth}{.1pt} |
| 1252 |
\end{table} |
| 1253 |
|
| 1254 |
|
| 1255 |
\section{Name Formatting} |
| 1256 |
|
| 1257 |
|
| 1258 |
\begin{verbatim} |
| 1259 |
bibtool name list |
| 1260 |
\end{verbatim} |
| 1261 |
|
| 1262 |
\INCOMPLETE |
| 1263 |
|
| 1264 |
\begin{verbatim} |
| 1265 |
bibtool name count |
| 1266 |
\end{verbatim} |
| 1267 |
|
| 1268 |
\INCOMPLETE |
| 1269 |
|
| 1270 |
|
| 1271 |
\begin{verbatim} |
| 1272 |
bibtool name format $format $name |
| 1273 |
\end{verbatim} |
| 1274 |
|
| 1275 |
\INCOMPLETE |
| 1276 |
|
| 1277 |
|
| 1278 |
\section{Formatting} |
| 1279 |
|
| 1280 |
In principal Tcl provides everything neccessary to extract the |
| 1281 |
contents of entries and create a formatted string which is stored in a |
| 1282 |
field. Since \BibTool{} started as a tool to autmatically create |
| 1283 |
reference keys for \BibTeX{} databases it has a powerful (and fast) |
| 1284 |
mechanism to extract information from a entry and format it according |
| 1285 |
to a given specification. For a full description we refer to |
| 1286 |
\cite{neugebauer:bibtool}. |
| 1287 |
\begin{table}[t] |
| 1288 |
\begin{center}\doublerulesep=.4pt |
| 1289 |
\begin{tabular}{lp{.6\textwidth}}\hline\hline |
| 1290 |
\textit{format}\rule[-1.5ex]{0pt}{4ex} & |
| 1291 |
\textit{meaning}\\\hline\rule{0pt}{3ex}% |
| 1292 |
\code{\%}\textit{sign pre.post} \code{d(}\textit{field}\code{)} & |
| 1293 |
The \textit{post$^{th}$} number is extracted from the field -- |
| 1294 |
\textit{post} defaults to 1. \textit{pre} digits starting from |
| 1295 |
the right are returned. If \textit{sign} is \code{+} then |
| 1296 |
missing digit are replaced by \code{0}. If \textit{sign} is |
| 1297 |
\code{-} and no number is found then \code{0} is returned |
| 1298 |
instead of the empty string. |
| 1299 |
\\ |
| 1300 |
\code{\%}\textit{sign pre.post} \code{D(}\textit{field}\code{)} & |
| 1301 |
Acts like \code{d} but does not truncate longer numbers to |
| 1302 |
\textit{pre} digits. |
| 1303 |
\\ |
| 1304 |
\code{\%}\textit{sign pre.post} \code{n(}\textit{field}\code{)} & |
| 1305 |
The field is treated as a list of names. Last names are |
| 1306 |
extracted. At most \textit{pre} names are used and remaining |
| 1307 |
names are indicated. At most \textit{post} letters from each |
| 1308 |
name are shown. If \textit{sign} is \code{+} then all letters |
| 1309 |
are translated to upper case. If \textit{sign} is \code{-} then |
| 1310 |
all letters are translated to lower case. |
| 1311 |
\\ |
| 1312 |
\code{\%}\textit{sign pre.post} \code{N(}\textit{field}\code{)} & |
| 1313 |
Acts like \code {n} but appends the initials as well. |
| 1314 |
\\ |
| 1315 |
\code{\%}\textit{sign pre.post} \code{p(}\textit{field}\code{)} & |
| 1316 |
Use the name format \textit{pre} to format at most \textit{post} |
| 1317 |
names accordingly. Translate the case according to the |
| 1318 |
\textit{sign}. |
| 1319 |
\\ |
| 1320 |
\code{\%}\textit{sign pre} \code{s(}\textit{field}\code{)} & |
| 1321 |
Use at most \textit{pre} characters. Translate the case |
| 1322 |
according to the \textit{sign}. |
| 1323 |
\\ |
| 1324 |
\code{\%}\textit{sign pre.post} \code{t(}\textit{field}\code{)} & |
| 1325 |
Use a list of words. The words in the \code{ignored.word} list |
| 1326 |
are not considered. At most \textit{pre} words are shown. At |
| 1327 |
most \textit{post} letters from each word are used. Translate |
| 1328 |
the case according to the \textit{sign}. \code{fmt.titlt.title} |
| 1329 |
is inserted between words. |
| 1330 |
\\ |
| 1331 |
\code{\%}\textit{sign pre.post} \code{T(}\textit{field}\code{)} & |
| 1332 |
Acts like \code{t} but does not ignore words. |
| 1333 |
\\ |
| 1334 |
\code{\%}\textit{sign pre.post} \code{w(}\textit{field}\code{)} & |
| 1335 |
Acts like \code{t} but inserts nothing between words. |
| 1336 |
\\ |
| 1337 |
\code{\%}\textit{sign pre.post} \code{W(}\textit{field}\code{)} & |
| 1338 |
Acts like \code{T} but inserts nothing between words. |
| 1339 |
\\[1ex] |
| 1340 |
\hline\hline |
| 1341 |
\end{tabular} |
| 1342 |
\caption{Format specifiers}\label{tab:formats} |
| 1343 |
\end{center} |
| 1344 |
\end{table} |
| 1345 |
|
| 1346 |
The procedure \code{bibtool format} takes a entry and a format |
| 1347 |
specification and usually returnes a string representation of the |
| 1348 |
format where certain constructions are expanded. If a syntax error is |
| 1349 |
detected an error is raised. |
| 1350 |
|
| 1351 |
To start with the easy case we can state, that any allowed character |
| 1352 |
is passed unchanged from the fromat to the result. The percent sign |
| 1353 |
acts as an escape character which starts an extended command. To |
| 1354 |
produce a single percent sign in the output you have to give two |
| 1355 |
percent signs in the format specifier: |
| 1356 |
\begin{verbatim} |
| 1357 |
$entry format {123%%abc} |
| 1358 |
\end{verbatim}%$ |
| 1359 |
This instruction returns \code{123\%abc}. |
| 1360 |
|
| 1361 |
The percent sign starts a format specifier which is similar to a |
| 1362 |
format specifier of the Tcl \code{format} instruction. But instead of |
| 1363 |
giving arbitrary arguments to be formatted in addition to the format |
| 1364 |
specifier, the format contains the names of fields in parentheses. The |
| 1365 |
values of those fields -- or pseudo-fields -- are formatted according |
| 1366 |
to the format specifier. The general form is as follows: |
| 1367 |
|
| 1368 |
\code{\%} \textit{sign pre.post spec} \code{(}\textit{field}\code{)} |
| 1369 |
|
| 1370 |
We will explain the meaning of the different parts from right to |
| 1371 |
left. \textit{field} is the name of a field or pseudo-field. The value |
| 1372 |
of this field is formatted according to the remaining parts of the |
| 1373 |
format specifier. |
| 1374 |
|
| 1375 |
\textit{spec} is a single letter which determines the main |
| 1376 |
functionality. Details can be found in Table~\ref{tab:formats}. For |
| 1377 |
instance the letter \code{n} denotes name formatting. The other parts |
| 1378 |
of the format specifier are optional and influence the exact operation |
| 1379 |
of the formatting. In any case characters that are not allowed are |
| 1380 |
silently ignored and \TeX{} macros are expanded. |
| 1381 |
|
| 1382 |
In general \textit{spe} can be preceeded by the qualifier |
| 1383 |
\code{\#}. But this is not meaningful in the context of Tcl since it |
| 1384 |
always returns the empty string. |
| 1385 |
|
| 1386 |
Let us finally reconsider our example entry from page |
| 1387 |
\pageref{example:bibtool}. For this entry \code{\$entry} we get the |
| 1388 |
following results: |
| 1389 |
|
| 1390 |
\begin{tabular}{lll} |
| 1391 |
\code{\$entry format "\%n(author)"} &\(\mapsto\)& \code{Neugebauer}\\ |
| 1392 |
\code{\$entry format "\%+.3n(author)"} &\(\mapsto\)& \code{NEU}\\ |
| 1393 |
\code{\$entry format "\%-.2n(author)"} &\(\mapsto\)& \code{ne}\\ |
| 1394 |
\code{\$entry format "\%d(edition)"} &\(\mapsto\)& \code{2}\\ |
| 1395 |
\code{\$entry format "\%d(edition)"} &\(\mapsto\)& \code{2}\\ |
| 1396 |
\code{\$entry format "\%+3.2d(edition)"} &\(\mapsto\)& \code{041}\\ |
| 1397 |
\code{\$entry format "\%2d(year)"} &\(\mapsto\)& \code{97}\\ |
| 1398 |
\code{\$entry format "\%-w(title)"} &\(\mapsto\)& \code{bibtool} |
| 1399 |
\end{tabular} |
| 1400 |
|
| 1401 |
|
| 1402 |
\section{Analyzing a \LaTeX{} aux File} |
| 1403 |
|
| 1404 |
\BibTeX{} uses inormation from the auxiliary files created during a |
| 1405 |
\LaTeX{} run. If you want to write a program to extract the entries |
| 1406 |
used in a document or if you want to write a replacement for \BibTeX{} |
| 1407 |
you need a method to get the information from the aux file. Since the |
| 1408 |
information might be distributed in several aux files if the \LaTeX{} |
| 1409 |
document uses \verb|\include| to combine several subdocuments. |
| 1410 |
|
| 1411 |
Thus it is rather handsome to have a method which collects th required |
| 1412 |
information. This is done by the functions \code{bibtool aux} and |
| 1413 |
\code{bibtool aux -db}. |
| 1414 |
|
| 1415 |
The function \code{bibtool aux} returns a list containing all |
| 1416 |
citations mentioned in the aux file. One key is traeted special. If |
| 1417 |
the key \code{*} is used then all entries in the database should be |
| 1418 |
used. In \LaTeX{} this is accomplished by the macro invocation |
| 1419 |
\begin{verbatim} |
| 1420 |
\nocite{*} |
| 1421 |
\end{verbatim} |
| 1422 |
Thus if a \code{*} is recognized then the list contains only one |
| 1423 |
element namely this star. Otherwise you get the complete list with |
| 1424 |
\begin{verbatim} |
| 1425 |
bibtool aux $auxfile |
| 1426 |
\end{verbatim}%$ |
| 1427 |
If the document contains references to \code{neugebauer:bibtool} and |
| 1428 |
\code{neugebauer:bibtcl} then the following Tcl list is returned: |
| 1429 |
\begin{verbatim} |
| 1430 |
neugebauer:bibtool neugebauer:bibtcl |
| 1431 |
\end{verbatim} |
| 1432 |
|
| 1433 |
The other information which can be extracted from an aux file is the |
| 1434 |
list of databases to be used. This is done with the function |
| 1435 |
\code{bibtool aux databases}. It takes the name of an aux file and |
| 1436 |
returns the list of databases mentioned there: |
| 1437 |
\begin{verbatim} |
| 1438 |
bibtool aux $auxfile -db |
| 1439 |
\end{verbatim}%$ |
| 1440 |
More than one databases can be used in one document by separating them |
| 1441 |
by a comma (\code{,}). In a \LaTeX{} document this might look at follows: |
| 1442 |
\begin{verbatim} |
| 1443 |
\bibliography{db1,db2,db3} |
| 1444 |
\end{verbatim} |
| 1445 |
In this case the function \code{bibtool aux -db} returnes the |
| 1446 |
following list |
| 1447 |
\begin{verbatim} |
| 1448 |
db1 db2 db3 |
| 1449 |
\end{verbatim} |
| 1450 |
|
| 1451 |
If the aux file given to either function does not exist or can not be |
| 1452 |
read then a Tcl error is raised. Thus you should always use |
| 1453 |
\code{catch} and implement your own error recovery routine. |
| 1454 |
|
| 1455 |
\begin{table}[tp] |
| 1456 |
\TclSummary{aux}{\meta{FILE}}{Reads the given \LaTeX{} \code{aux} |
| 1457 |
file and collects a list of all citations. If one citation is |
| 1458 |
\code{*} then this \code{*} is returned. Otherwise a list of all |
| 1459 |
citations found is returned. If the \LaTeX{} document has used |
| 1460 |
\code{\char'134 include} then the respective \code{aux} files are |
| 1461 |
also considered.} |
| 1462 |
|
| 1463 |
\TclSummary{aux}{\meta{FILE} \meta{-db}}{Reads the given \LaTeX{} \code{aux} |
| 1464 |
file and collects a list of all databases requested. If the |
| 1465 |
\LaTeX{} document has used \code{\char'134 include} then the |
| 1466 |
respective \code{aux} files are also considered.} |
| 1467 |
|
| 1468 |
\caption{Summary of operations on aux files}\label{fig:tcl-aux} |
| 1469 |
\rule{\textwidth}{.1pt} |
| 1470 |
\end{table} |
| 1471 |
|
| 1472 |
|
| 1473 |
\section{Recognized Entry Types} |
| 1474 |
|
| 1475 |
In \BibTeX{} any entry has a certain type -- the entry type. |
| 1476 |
\BibTool{} maintains a list of known entry types and complains if a |
| 1477 |
entry is read which has an unknown entry type. Such entries are not |
| 1478 |
stored in the database. Usually the entry types of the standard |
| 1479 |
\BibTeX{} styles are already known to \BibTool. But if you are using |
| 1480 |
some other kind of entry type then this has to be declared in |
| 1481 |
\BibTool. This can be done with the resource command |
| 1482 |
\code{new.entry.type}. |
| 1483 |
|
| 1484 |
\begin{verbatim} |
| 1485 |
bibtool new.entry.type={Law} |
| 1486 |
\end{verbatim} |
| 1487 |
|
| 1488 |
Note that no spaces are allowed around the equality sign and that the |
| 1489 |
braces are neccesary to preserve the case of the letters. This is |
| 1490 |
useful since \BibTeX{} and \BibTool{} normally ignore the case of |
| 1491 |
letters. But the string given as entry type is not only used to |
| 1492 |
determine whether or not a entry can be stored in the database but |
| 1493 |
also as the printing representation of the entry type. Thus in our |
| 1494 |
example it would be possible to have entries of the following kind |
| 1495 |
|
| 1496 |
\begin{verbatim} |
| 1497 |
@law{ ... } |
| 1498 |
@Law{ ... } |
| 1499 |
@LAW{ ... } |
| 1500 |
\end{verbatim} |
| 1501 |
|
| 1502 |
All of those would be accepted and be assigned the same entry |
| 1503 |
type. All of them would be printed like the second example. |
| 1504 |
|
| 1505 |
As a sidemark you should note that \code{new.entry.type} can also be |
| 1506 |
used to redefine the printing representation of existing entry |
| 1507 |
types. Whenever an existing entry type is encountered as argument then |
| 1508 |
just this modification is performed. |
| 1509 |
|
| 1510 |
For a Tcl program it might be necessary to know which entry types are |
| 1511 |
defined in \BibTool. Thus it can present a menu to the user to select |
| 1512 |
the appropriate type. For this purpose the instruction \code{bibtool |
| 1513 |
types} is provided. This can be seen in the following fragment of a |
| 1514 |
program where \code{\$menu} is assumed to contain the path to a |
| 1515 |
previously created \code{menu}. |
| 1516 |
|
| 1517 |
\begin{verbatim} |
| 1518 |
foreach type [bibtool types] { |
| 1519 |
$menu add checkbutton \ |
| 1520 |
-variable entry_type \ |
| 1521 |
-value $type \ |
| 1522 |
-label $type |
| 1523 |
} |
| 1524 |
\end{verbatim}%$ |
| 1525 |
|
| 1526 |
If you run this example you will see that the menu contains normal |
| 1527 |
entry types only. Currently the following entry types are considered |
| 1528 |
special:\medskip |
| 1529 |
|
| 1530 |
\mbox{}\hfill |
| 1531 |
\begin{minipage}{.3\textwidth} |
| 1532 |
COMMENT \\ |
| 1533 |
PREAMBLE \\ |
| 1534 |
STRING |
| 1535 |
\end{minipage}\hfill |
| 1536 |
\begin{minipage}{.3\textwidth} |
| 1537 |
ALIAS \\ |
| 1538 |
INCLUDE \\ |
| 1539 |
MODIFY |
| 1540 |
\end{minipage} |
| 1541 |
\hfill\mbox{}\medskip |
| 1542 |
|
| 1543 |
The three sepcial entry types to the left are well known. The entry |
| 1544 |
types to the right are likely to be introduced in \BibTeX\,1.0. |
| 1545 |
|
| 1546 |
If you want to get a complete list of all entry types you can give the |
| 1547 |
optional argument \code{-all} to the \code{bibtool types} |
| 1548 |
command. Then the special entry types are returned in addition to the |
| 1549 |
normal entry types. |
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
\begin{table}[tp] |
| 1554 |
\TclSummary{types}{\meta{?-all?}}{Return the list of defined entry |
| 1555 |
types. Normally all normal entry types are returned. If the |
| 1556 |
option \code{-all} is given then the special entry types are delivered |
| 1557 |
as well. The entry types are returned in some internal order. They |
| 1558 |
are not sorted.} |
| 1559 |
\TclSummary{version}{}{Return the version number of \BibTool.} |
| 1560 |
|
| 1561 |
\caption{Summary of misc operations}\label{fig:tcl-misc} |
| 1562 |
\rule{\textwidth}{.1pt} |
| 1563 |
\end{table} |
| 1564 |
|
| 1565 |
|
| 1566 |
\section{The Version Number} |
| 1567 |
|
| 1568 |
Finally, BibTcl provides a means to get hold of the version number. |
| 1569 |
This can be useful to give this information to the user or to see |
| 1570 |
whether a new enough version is used when older versions might miss |
| 1571 |
some features. I would like to provide means to test for features |
| 1572 |
directly. But until I have descided how this will be implemented the |
| 1573 |
version is the only indicator which can be used. |
| 1574 |
|
| 1575 |
The version number is returned by the function \code{bibtool version}. |
| 1576 |
The return value consists of a number \meta{major}.\meta{minor} where |
| 1577 |
\meta{mayor} is the major version number and \meta{minor} is the minor |
| 1578 |
version number. Additionally some additions may be returned. Thus |
| 1579 |
\begin{verbatim} |
| 1580 |
bibtool version |
| 1581 |
\end{verbatim} |
| 1582 |
\noindent may return \code{2.41} but a value of \code{2.41-a} is also |
| 1583 |
a legal value---even so it is not very likely that you get your hands |
| 1584 |
on such a release. |
| 1585 |
|
| 1586 |
|
| 1587 |
\section{Using \BibTool{} Resources}\label{sec:tcl-resources} |
| 1588 |
|
| 1589 |
Nearly all resource commands of \BibTool{} are accessible through the |
| 1590 |
\code{bibtool} command. If nothing else fits then the argument of the |
| 1591 |
\code{bibtool} command is passed on to the resource evaluator. Since |
| 1592 |
this is done for each single argument this means that special |
| 1593 |
characters have to be protected in a way to ensure that they arrive |
| 1594 |
safely there. |
| 1595 |
|
| 1596 |
For instance the resource evaluator treats the equality sign as |
| 1597 |
optional. Separating spaces are enough. Thus the following two |
| 1598 |
commands have the same effect: |
| 1599 |
\begin{verbatim} |
| 1600 |
bibtool quiet=on |
| 1601 |
bibtool {quiet on} |
| 1602 |
\end{verbatim} |
| 1603 |
Note however that the second form requires the braces to protect the |
| 1604 |
embedded space. |
| 1605 |
|
| 1606 |
\BibTool{} resources can also be queried. Since not each resource |
| 1607 |
command corresponds to a single variable not all resource commands can |
| 1608 |
be used to query values. At least each resource command which |
| 1609 |
corresponds to a string, a boolean, or a numeric value can be queried. |
| 1610 |
|
| 1611 |
Consider the resource instruction from above \code{quiet=on}. This |
| 1612 |
instructions sets the boolean resource \code{quiet}. This variable |
| 1613 |
can be queried with |
| 1614 |
\begin{verbatim} |
| 1615 |
bibtool quiet |
| 1616 |
\end{verbatim} |
| 1617 |
This Tcl command returns the value of the resource variable. Booleans |
| 1618 |
are returned as \code{0} or \code{1} to conform to the Tcl conventions |
| 1619 |
for booleans. |
| 1620 |
|
| 1621 |
\INCOMPLETE |
| 1622 |
|
| 1623 |
|
| 1624 |
\begin{table}[tp] |
| 1625 |
\TclSummary{\meta{RSC\_VARIABLE}}{}{Returns the contents of the |
| 1626 |
resource variable \meta{RSC\_VARIABLE} if this variable is |
| 1627 |
available. Strings, booleans, and numerics are available.} |
| 1628 |
\TclSummary{\meta{RSC}}{\meta{\ldots}}{Passes the resource command |
| 1629 |
\meta{RSC} to the resource evaluator of \BibTool. Each single |
| 1630 |
argument is treated as a separate resource command.} |
| 1631 |
|
| 1632 |
\caption{Summary of resource operations}\label{fig:tcl-rsc} |
| 1633 |
\rule{\textwidth}{.1pt} |
| 1634 |
\end{table} |
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
\chapter{Installation}\label{sec:installation} |
| 1640 |
|
| 1641 |
This section is the last one since it is required only once. It |
| 1642 |
describes the installation of the dynamic loadable library. |
| 1643 |
|
| 1644 |
\section{UNIX} |
| 1645 |
|
| 1646 |
\begin{itemize} |
| 1647 |
\item I suppose that you have unpacked \BibTool{}. You should be in |
| 1648 |
the main directory containing the directory \file{BibTcl}. |
| 1649 |
|
| 1650 |
\item Configure and compile \BibTool{}---if not already done. See the |
| 1651 |
files \file{README.md} and \file{INSTALL} there. The object files must |
| 1652 |
be present in this directory. (In a next release a single library |
| 1653 |
will be assembled and the C API might be documented.) |
| 1654 |
|
| 1655 |
\item Find the file \file{tclConfig.sh}. This file is created during |
| 1656 |
the configuration of Tcl and installed with it. One place to search |
| 1657 |
for it is in the directory \file{/usr/local/lib} or wherever Tcl has |
| 1658 |
installed its libraries. Copy this file into the directory |
| 1659 |
\file{BibTcl}. |
| 1660 |
|
| 1661 |
\item Go to the directory \file{BibTcl} and run |
| 1662 |
|
| 1663 |
\code{./configure} |
| 1664 |
|
| 1665 |
This will have a look at your system and find out which properties |
| 1666 |
it has. From this information a \file{Makefile} is created. |
| 1667 |
|
| 1668 |
\item Run |
| 1669 |
|
| 1670 |
\code{make LIBDIR=/usr/local/lib/BibTool} |
| 1671 |
|
| 1672 |
where the path on the right side of the \code{=} should point to the |
| 1673 |
installed \BibTool. |
| 1674 |
|
| 1675 |
This step should produce the shared library and a small Tcl loader |
| 1676 |
\file{bibtool.tcl} which is independent of the architecture. In |
| 1677 |
fact it figures out the architecture and uses the appropriate |
| 1678 |
installed version. |
| 1679 |
|
| 1680 |
\item Run |
| 1681 |
|
| 1682 |
\code{make install LIBDIR=/usr/local/lib/BibTool} |
| 1683 |
|
| 1684 |
This creates a subdirectory of \file{LIBDIR} according to the OS |
| 1685 |
used. This directory contains the shared library as well as the |
| 1686 |
loader script. The loader script can be freely copied to any other |
| 1687 |
place. The shared library must stay in this directory since the |
| 1688 |
location is compiled into the loader script. |
| 1689 |
|
| 1690 |
\end{itemize} |
| 1691 |
|
| 1692 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1693 |
% |
| 1694 |
% Local Variables: |
| 1695 |
% mode: latex |
| 1696 |
% TeX-master: "bibtcl.ltx" |
| 1697 |
% End: |