Debian Codegraph @

texmf-dist/source/bibtex/bibexport/bibexport.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright
4 %<*driver>
5 \documentclass{ltxdoc}
6 \usepackage{doc}
7
8 \def\script#1{\texttt{#1}}
9 \def\ext#1{\texttt{.#1}}
10 \def\var#1{\texttt{\$#1}}
11 \def\entry#1{\texttt{@#1}}
12 \def\lang#1{\textsc{#1}}
13 \def\bst#1{\textsf{#1.bst}}
14 \def\BibTeX{Bib\TeX}
15
16 %%%\AtBeginDocument{\CodelineIndex\EnableCrossrefs}
17 %%%\AtEndDocument{\PrintIndex}
18 \begin{document}
19 \def\docdate{2019/03/30}
20 \def\fileversion{3.03}
21 %%% Please also change date at the beginning of the script %%%
22 %%% (VERSION and VDATE below) %%%
23 \DocInput{bibexport.dtx}
24 \end{document}
25 %</driver>
26 %
27 % \fi
28 % \CheckSum{45}
29 %% \CharacterTable
30 %% {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
31 %% 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
32 %% Digits \0\1\2\3\4\5\6\7\8\9
33 %% Exclamation \! Double quote \" Hash (number) \#
34 %% Dollar \$ Percent \% Ampersand \&
35 %% Acute accent \' Left paren \( Right paren \)
36 %% Asterisk \* Plus \+ Comma \,
37 %% Minus \- Point \. Solidus \/
38 %% Colon \: Semicolon \; Less than \<
39 %% Equals \= Greater than \> Question mark \?
40 %% Commercial at \@ Left bracket \[ Backslash \\
41 %% Right bracket \] Circumflex \^ Underscore \_
42 %% Grave accent \` Left brace \{ Vertical bar \|
43 %% Right brace \} Tilde \~}
44 %%
45 %
46 % \title{The \script{bibexport.sh} script}
47 % \author{Nicolas Markey}
48 % \date{\docdate}
49 % \maketitle
50 % \StopEventually{}
51 %
52 % \begin{abstract}
53 % \script{bibexport.sh} is a small shell script, relying on \BibTeX, that
54 % extracts entries of one or several \ext{bib} file(s). It~will expand
55 % abbreviations and cross-references, except standard month and journal
56 % abbreviations. The output is indented as neatly as possible, yielding a
57 % readable \ext{bib} file even if the original file is~not.
58 % \end{abstract}
59 %
60 %
61 % \section{Exporting \ext{bib} files}
62 %
63 % \subsection{Why and how?}
64 %
65 % \BibTeX{} aims at allowing for the use of one single \ext{bib} file,
66 % containing many entries, from which \BibTeX{} extracts only the
67 % \verb+\cite+d ones. When sending a document to someone else, this
68 % requires either sending the whole file, or extracting the \verb+\cite+d
69 % entries from the \ext{bib} file.
70 %
71 % \BibTeX{} also has a mechanism for using abbreviations and
72 % cross-references. When extracting entries of a large \ext{bib} file,
73 % it can be interesting to develop those abbreviations, in order to get a
74 % clean, self-contained \ext{bib} file. Also, it may be useful to develop
75 % cross-references in a \ext{bib} file, independently of any document.
76 %
77 % \medskip
78 % \script{bibexport} can either extract entries that are cited in a document,
79 % or all the entries of one or several \ext{bib} files. It will always develop
80 % cross-references and abreviations, except standard abbreviations for months or
81 % some journals, that are defined in standard \BibTeX{} styles. This script
82 % uses \BibTeX{}. This has both pros and cons:
83 % \begin{itemize}
84 %\item[$+$] it is very simple. Basicaly, the script simply calls \BibTeX{}, and the
85 % \ext{bst} file just outputs the name and the content of each field.
86 %\item[$+$] since it uses \BibTeX, we are sure that it will handle everything
87 % "properly", \emph{i.e.} in the same way as they will be handled when cited in
88 % a \LaTeX{} document;
89 %\item[$=$] \BibTeX{} has some strict limitations (especially "no more than 78 consecutive
90 % non-space characters") that we must be aware~of. On~the other hand, any such
91 % problem occuring within the script would also occur when compiling a
92 % document;
93 %\item[$-$] abbreviations and cross-references will \emph{always} be
94 % developped. It~could be argued that this is also a positive point, but
95 % having the choice would be better.
96 %\item[$-$] Many people seem to find \BibTeX's internal language clumsy, and thus
97 % the script could be difficult to adapt to special needs. However, this is
98 % not \emph{that} difficult, as will be explained later~on. In the present case,
99 % adding more fields to be exported is quite easy.
100 % \end{itemize}
101 %
102 % \subsection{Related scripts}
103 %
104 % Several other tools exist for achieving this task:
105 % \begin{itemize}
106 %\item \verb+aux2bib+, written by Ralf Treinen, relies on \verb+bib2bib+,
107 % which is a \lang{CaML} program for selecting some entries in one or several \ext{bib}
108 % files. It does not expand anything, but includes all the necessary
109 % definitions and entries.
110 %\item \verb+bibextract.sh+, by Nelson Beebe. This script uses \lang{awk} for
111 % extracting some entries out of a \ext{bib} file. It~is said not to be
112 % compliant with cross-references.
113 %\item \bst{subset}, by David Kotz. \bst{export} develops the same ideas (but
114 % I discovered that only later~on). \bst{subset} does not handle
115 % \entry{preamble}, neither does it "protect" standard abbreviations.
116 % \end{itemize}
117 %
118 % \subsection{Some examples}
119 %
120 % \begin{itemize}
121 %\item extracting \verb+\cite+d references of a document, also including
122 % cross-references:
123 %\begin{center}
124 % \ttfamily bibexport.sh -o {\itshape <result>}.bib {\itshape <file>}.aux
125 %\end{center}
126 %\item extracting \verb+\cite+d references of a document, without crossrefs,
127 % and using a special \ext{bst} file:
128 %\begin{center}
129 % \ttfamily bibexport.sh -b {\itshape <style>}.bst -o {\itshape <result>}.bib {\itshape <file>}.aux
130 %\end{center}
131 %\item export all the entries of two \ext{bib} files (including crossrefed entries):
132 %\begin{center}
133 % \ttfamily bibexport.sh -a -o {\itshape <result>}.bib {\itshape <file1>}.bib {\itshape <file2>}.bib
134 %\end{center}
135 %\item export all the entries of two \ext{bib} files (without crossrefs):
136 %\begin{center}
137 % \ttfamily bibexport.sh -a -n -o {\itshape <result>}.bib {\itshape <file1>}.bib
138 % {\itshape <file2>}.bib
139 %\end{center}
140 % In fact, the only difference between this and the previous one is that
141 % \texttt{crossref} field will be filtered out at the end of the script.
142 %\item export all the entries of two \ext{bib} files, using an extra file
143 % containing cross-referenced entries (which should not be included):
144 %\begin{center}
145 % \ttfamily bibexport.sh -a -e {\itshape <crossref>}.bib -n -o {\itshape
146 % <result>}.bib \textbackslash\par {\itshape <file1>}.bib {\itshape <file2>}.bib
147 %\end{center}
148 %\end{itemize}
149 %
150 % \subsection{Exporting extra fields}
151 %
152 % By~default, \script{bibexport} exports only "standard" fields
153 % (those defined and used in \bst{plain}), as~well as a few
154 % others. It~is very easy to modify it in order to export other fields:
155 % it~suffices to modify \bst{export} as follows:
156 % \begin{itemize}
157 % \item in the \texttt{ENTRY} list, add the name of the field you would
158 % like to export. Notice that \texttt{ENTRY} takes three space-separated
159 % lists as arguments; you must add extra fields in the first argument
160 % (actually, the last two are empty).
161 % \item in the function \texttt{entry.export.extra}, add a line of the
162 % form
163 % \begin{center}
164 % \ttfamily
165 % "myfield" myfield field.export
166 % \end{center}
167 % where \texttt{myfield} is the name of the extra field you want to
168 % export.
169 % \end{itemize}
170 %
171 % \subsection*{Acknowledgements}
172 % I thank \'Eric Colin de Verdi\`ere, Richard Mathar, Harald Hanche-Olsen,
173 % Damien Pollet, and Caner Kazanci for suggesting several improvements
174 % or corrections.
175 %
176 % \section{The code}
177 % \subsection{The shell script}
178 % \subsubsection{Initialization}
179 %
180 %\begin{macro}{checkversion}
181 % We check that the \ext{bst} files have the correct version number:
182 % \begin{macrocode}
183 %<*script>
184 function checkversion()
185 {
186 kpsewhich expcites.bst > /dev/null ||
187 echo "-----------
188 --Warning-- file expcites.bst not found.
189 -----------"
190 grep -q $VDATE `kpsewhich expkeys.bst` ||
191 echo "-----------
192 --Warning-- the version of the .bst files does not match with that of this script.
193 -----------"
194 }
195 %</script>
196 % \end{macrocode}
197 %\end{macro}
198 %
199 %\begin{macro}{usage}
200 % We first define how the script should be used:
201 % \begin{macrocode}
202 %<*script>
203 function usage()
204 {
205 echo "bibexport: a tool to extract BibTeX entries out of .bib files.
206 usage: `basename $0` [-h|v|n|c|a|d|s|t] [-b|e|es|ec|o|r file] file...
207
208 Basic options:
209 --------------
210 -a, --all export the entire .bib files
211 -o bib, --output-file bib write output to file [default: bibexport.bib]
212 -ns, --nosave overwrite output file without keeping a copy
213 -p, --preamble write a preamble at beginning of output
214 -t, --terse operate silently
215 -h, --help print this message and exit
216 -v, --version print version number and exit
217
218 Advanced options:
219 -----------------
220 -b bst, --bst bst specifies the .bst style file [default: export.bst]
221 -c, --crossref preserve crossref field [default: no]
222 -n, --no-crossref remove crossref'd entries [default: no]
223 -e bib, --extra bib extra .bib file to be used (crossrefs and strings)
224 -es bib, --extras bib extra .bib file to be used (for strings)
225 -ec bib, --extrac bib extra .bib file to be used (for crossrefs)
226 -r bib, --replace bib replace .bib file(s) in the .aux file
227 -d, --debug create intermediate files but don't run BibTeX";
228 exit 0;
229 }
230 %</script>
231 % \end{macrocode}
232 %\end{macro}
233 %
234 %\begin{macro}{opttoolate}
235 % We also have a function to warn if extra options are given after
236 % the names of input files, which is not allowed.
237 % \begin{macrocode}
238 %<*script>
239 function opttoolate()
240 {
241 if [ ! -z "${TOOLATE}" ]; then
242 echo "No options are allowed after the input files";
243 exit 0;
244 fi
245 }
246 %</script>
247 % \end{macrocode}
248 %\end{macro}
249 %\begin{macro}{VERSION}
250 %\begin{macro}{VDATE}
251 %\begin{macro}{ALL}
252 %\begin{macro}{CREF}
253 %\begin{macro}{DEBUG}
254 %\begin{macro}{FILE}
255 %\begin{macro}{EXT}
256 %\begin{macro}{EXTRA}
257 %\begin{macro}{EXTRABIB}
258 %\begin{macro}{REPLACEBIB}
259 %\begin{macro}{NEWBIB}
260 %\begin{macro}{SPACE}
261 %\begin{macro}{BST}
262 %\begin{macro}{TERSE}
263 %\begin{macro}{BANNER}
264 %\begin{macro}{NOSAVE}
265 %\begin{macro}{ARGS}
266 %\begin{macro}{TOOLATE}
267 % We define the default value of some variables:
268 % \begin{itemize}
269 % \item \var{VERSION}: the version number;
270 % \item \var{VDATE}: the release date;
271 % \item \var{ALL}: a flag indicating that all entries of the given (\ext{bib})
272 % file are to be exported;
273 % \item \var{CREF}: the value of \verb+-min-crossrefs+;
274 % \item \var{FILE}: the input file(s);
275 % \item \var{EXT}: the extension (\ext{aux} or \ext{bib}) of input files;
276 % \item \var{EXTRA}: list of possible extra \ext{bib} files without extension;
277 % \item \var{EXTRABIB}: list of possible extra \ext{bib} files with extension;
278 % \item \var{REPLACEBIB}: flag indicating that we will replace the \ext{bib}
279 % file given in the \ext{aux} file with a new one;
280 % \item \var{NEWBIB}: new \ext{bib} file to replace that fiven in the
281 % \ext{aux} file;
282 % \item \var{SPACE}: file name separator (can be \textvisiblespace, comma or empty);
283 % \item \var{BST}: the \ext{bst} file to be used;
284 % \item \var{TERSE}: run silently;
285 % \item \var{BANNER}: don't print the initial comment;
286 % \item \var{NOSAVE}: don't keep a copy if overwriting output file;
287 % \item \var{ARGS}: the list of aruments passed to \texttt{bibexport.sh};
288 % \item \var{TOOLATE}: options are not allowed once we have encountered the
289 % first non-option argument.
290 % \item \var{DEBUG}: create intermediate files but do not run BibTeX.
291 % \end{itemize}
292 % \begin{macrocode}
293 %<*script>
294 ## Version number
295 VERSION="3.03";
296 ## Release date
297 VDATE="2019/03/30";
298
299 # ALL is a flag set to 1 when '-a' is given
300 ALL="";
301 # FILE will be the main input file(s) (.aux or .bib, depending on '-a')
302 FILE="";
303 # EXT is the extension of the input file(s) (.aux, or .bib if '-a')
304 EXT=".aux";
305 # EXTRA and EXTRABIB are two copies of the extra files ('-e'), used to
306 # include crossref'd entries and @string's
307 EXTRA="";
308 EXTRABIB="";
309 # REPLACEBIB ('-r') is set to 1 when the \bibdata of the .aux input file
310 # must be ignores (then '-e' must be used)
311 REPLACEBIB="";
312 # NEWBIB will contain the argument given to -r
313 NEWBIB="";
314 # BST is the .bst file to be used (default to export.bst)
315 BST="export";
316 # TERSE will be set to '-terse' if '-t' is given
317 TERSE="";
318 # NOSAVE if no need to save file before overwriting it
319 NOSAVE=""
320 # BANNER is used to turn on or off the preamble informations in the output
321 BANNER="";
322 # CREF is the number of citations of crossrefs from which the crossref'd entry
323 # must be included.
324 CREF="0";
325
326 # SPACE will be either ' ' or ','
327 SPACE="";
328 # TOOLATE is used to prevent extra options after the main file
329 TOOLATE="";
330 # DEBUG is used to create files but not run BibTeX.
331 DEBUG="";
332
333 ARGS=$@;
334 %</script>
335 % \end{macrocode}
336 %\end{macro}
337 %\end{macro}
338 %\end{macro}
339 %\end{macro}
340 %\end{macro}
341 %\end{macro}
342 %\end{macro}
343 %\end{macro}
344 %\end{macro}
345 %\end{macro}
346 %\end{macro}
347 %\end{macro}
348 %\end{macro}
349 %\end{macro}
350 %\end{macro}
351 %\end{macro}
352 %\end{macro}
353 %\end{macro}
354 %
355 % \subsubsection{Handling arguments}
356 %
357 % If no argument have been supplied, we call \script{usage}. Otherwise, we
358 % check version number.
359 %
360 % \begin{macrocode}
361 %<*script>
362 if [ $# -eq 0 ]; then
363 usage;
364 fi
365 checkversion;
366 %</script>
367 % \end{macrocode}
368 %
369 % Otherwise, we enter a \verb+while+-loop for handling the whole list of arguments:
370 % \begin{macrocode}
371 %<*script>
372 while [ $# != 0 ]; do
373 case $1 in
374 %</script>
375 % \end{macrocode}
376 %\begin{itemize}
377 %\item \verb+-a+ or \verb+--all+: export all the bibliography. This
378 % means that we input \ext{bib} files.
379 % \begin{macrocode}
380 %<*script>
381 -a|--all)
382 ## - export all entries in the input file(s)
383 ## - the input files are BibTeX files
384 opttoolate;
385 EXT=""; SPACE=""; ALL="a";
386 shift ;;
387 %</script>
388 % \end{macrocode}
389 %\item \verb+-b+ or \verb+--bst+: specifies the style file. It seems
390 % that \BibTeX{} does not like the \texttt{./\textit{style}.bst}
391 % syntax, and we have to handle that case separately.
392 % \begin{macrocode}
393 %<*script>
394 -b|--bst)
395 ## - specifies the .bst file to use (default to 'export.bst')
396 opttoolate;
397 if [ "`dirname $2`" = "." ]; then
398 DOLLARTWO="`basename $2 .bst`";
399 else
400 DOLLARTWO="`dirname $2`/`basename $2 .bst`";
401 fi
402 BST="${DOLLARTWO}";
403 shift 2;;
404 %</script>
405 % \end{macrocode}
406 %\item \verb+-d+ or \verb+--debug+: only creates (and preserves) the
407 % intermediate files. This can help finding problems with the script or
408 % \ext{bst} files.
409 % \begin{macrocode}
410 %<*script>
411 -d|--debug)
412 ## - debug mode: we create files but do not run bibtex
413 ## - instead, we print what we would have done...
414 opttoolate;
415 DEBUG="a";
416 shift ;;
417 %</script>
418 % \end{macrocode}
419 %\item \verb+-e+ or \verb+--extra+: when we want to export all the
420 % entries of a \ext{bib} file, we can specify an extra \ext{bib} file
421 % that would contain entries that we don't want to export, but that
422 % are needed, \emph{e.g.} for crossrefs.
423 % \begin{macrocode}
424 %<*script>
425 -e|--extra)
426 ## - extra input files (containing crossrefs or strings)
427 ## - they will be included twice: once before the main file(s)
428 ## (for @string's), once after (for crossrefs). We fool BibTeX
429 ## by naming the first one 'file.bib' and the second one
430 ## 'file.bib.bib', to avoid complaints.
431 opttoolate;
432 if [ "`dirname $2`" = "." ]; then
433 DOLLARTWO="`basename $2 .bib`";
434 else
435 DOLLARTWO="`dirname $2`/`basename $2 .bib`";
436 fi
437 EXTRA="${EXTRA}${DOLLARTWO},";
438 EXTRABIB="${EXTRABIB},${DOLLARTWO}.bib";
439 shift 2;;
440 %</script>
441 % \end{macrocode}
442 %\item \verb+-es+ or \verb+--extras+: if, for some reason, including extra
443 % files twice is not possible, this options provides a way of including extra
444 % \ext{bib} files only before the main \ext{bib} file(s).
445 % \begin{macrocode}
446 %<*script>
447 -es|--extras)
448 ## - extra input files (containing strings)
449 ## - will be included *before* the main files (hence not suitable
450 ## for crossrefs)
451 opttoolate;
452 if [ "`dirname $2`" = "." ]; then
453 DOLLARTWO="`basename $2 .bib`";
454 else
455 DOLLARTWO="`dirname $2`/`basename $2 .bib`";
456 fi
457 EXTRA="${EXTRA}${DOLLARTWO},";
458 shift 2;;
459 %</script>
460 % \end{macrocode}
461 %\item \verb+-ec+ or \verb+--extrac+: similar to te previous one, but for
462 % file(s) included after the main \ext{bib} file(s).
463 % \begin{macrocode}
464 %<*script>
465 -ec|--extrac)
466 ## - extra input files (containing crossrefs)
467 ## - will be included only *after* the main files (hence not
468 ## suitable for @string's)
469 opttoolate;
470 if [ "`dirname $2`" = "." ]; then
471 DOLLARTWO="`basename $2 .bib`";
472 else
473 DOLLARTWO="`dirname $2`/`basename $2 .bib`";
474 fi
475 EXTRABIB="${EXTRABIB},${DOLLARTWO}.bib";
476 shift 2;;
477 %</script>
478 % \end{macrocode}
479 %\item \verb+-o+ or \verb+--output+: the name of the output file.
480 % \begin{macrocode}
481 %<*script>
482 -o|--output-file)
483 ## - name of the output file
484 ## - we force it to end with '.bib'
485 opttoolate;
486 if [ "`dirname $2`" = "." ]; then
487 DOLLARTWO="`basename $2 .bib`";
488 else
489 DOLLARTWO="`dirname $2`/`basename $2 .bib`";
490 fi
491 OUTPUT="${DOLLARTWO}.bib";
492 shift 2 ;;
493 %</script>
494 % \end{macrocode}
495 %\item \verb+-c+ or \verb+--crossref+ (or others): this options means
496 % that we want crossrefs to be included. Note that for any entry,
497 % field inheritage will be performed.
498 % \begin{macrocode}
499 %<*script>
500 -c|--crossref|--crossrefs|--with-crossref|--with-crossrefs)
501 ## - whether or not to preserve 'crossref' keys.
502 ## - by default, they are removed, but crossref'd entries are
503 ## included.
504 ## - crossrefs are *always* expanded anyway.
505 opttoolate;
506 CREF="1" ;
507 shift ;;
508 %</script>
509 % \end{macrocode}
510 %\item \verb+-n+ or \verb+--no-crossref+: don't include crossref'ed
511 % entries.
512 % \begin{macrocode}
513 %<*script>
514 -n|--no-crossref|--without-crossref|--no-crossrefs|--without-crossrefs)
515 ## - to remove crossref'd entries (hence remove 'crossref' keys).
516 opttoolate;
517 CREF="20000" ;
518 shift ;;
519 %</script>
520 % \end{macrocode}
521 %\item \verb+-r+ or \verb+--replace+: this provides a way of replacing the
522 % \ext{bib} files given by \cmd{bibdata} in the \ext{aux} file with (a) new
523 % one(s).
524 % \begin{macrocode}
525 %<*script>
526 -r|--replace)
527 ## - to replace the file(s) given in \bibdata in the .aux file with
528 ## (a) new one(s).
529 opttoolate;
530 REPLACEBIB="a";
531 if [ "`dirname $2`" = "." ]; then
532 DOLLARTWO="`basename $2 .bib`";
533 else
534 DOLLARTWO="`dirname $2`/`basename $2 .bib`";
535 fi
536 NEWBIB="${NEWBIB}${DOLLARTWO}.bib,";
537 shift 2;;
538 %</script>
539 % \end{macrocode}
540 %\item \verb+-v+ or \verb+--version+ for version number:
541 % \begin{macrocode}
542 %<*script>
543 -v|--version)
544 echo "This is bibexport v${VERSION} (released ${VDATE})"; exit 0;;
545 %</script>
546 % \end{macrocode}
547 %\item \verb+-ns+ or \verb+--nosave+ for not keeping a copy
548 % of the output file if we overwrite it:
549 % \begin{macrocode}
550 %<*script>
551 -ns|--nosave|--no-save)
552 NOSAVE="a";
553 shift ;;
554 %</script>
555 % \end{macrocode}
556 %\item \verb+-p+ or \verb+--preamble+ for inserting some informations
557 % at the beginning of the output file:
558 % \begin{macrocode}
559 %<*script>
560 -p|--preamble|--with-preamble)
561 BANNER="a";
562 shift ;;
563 %</script>
564 % \end{macrocode}
565 %\item \verb+-t+ or \verb+--terse+ for asking \BibTeX{} to run silently:
566 % \begin{macrocode}
567 %<*script>
568 -t|--terse|--silent)
569 TERSE=" -terse ";
570 shift ;;
571 %</script>
572 % \end{macrocode}
573 %\item other dash-options are erroneous (except \verb+-h+, but...):
574 % \begin{macrocode}
575 %<*script>
576 -*)
577 usage;;
578 %</script>
579 % \end{macrocode}
580 %\item there should only remain file names: we add those names to the
581 % list of files.
582 % \begin{macrocode}
583 %<*script>
584 *)
585 ## - list of input files
586 ## - we ensure that no extra option is given later...
587 TOOLATE="a";
588 if [ "`dirname $1`" = "." ]; then
589 DOLLARONE="`basename $1 ${EXT}`";
590 else
591 DOLLARONE="`dirname $1`/`basename $1 ${EXT}`";
592 fi
593 FILE="${FILE}${SPACE}${DOLLARONE}${EXT}";
594 if [ -z "${ALL}" ]; then
595 SPACE=" ";
596 else
597 SPACE=",";
598 fi;
599 shift;;
600 %</script>
601 % \end{macrocode}
602 % \end{itemize}
603 % That's all folks:
604 % \begin{macrocode}
605 %<*script>
606 esac
607 done
608 %</script>
609 % \end{macrocode}
610 %
611 % \subsubsection{The core of the script}
612 %
613 % We first set the name of the result and intermediary files:
614 % \begin{macrocode}
615 %<*script>
616 FINALFILE=${OUTPUT};
617 if [ ! "${FINALFILE}" ]; then
618 FINALFILE="bibexport.bib";
619 fi
620 TMPFILE="bibexp.`date +%s`";
621 %</script>
622 % \end{macrocode}
623 %
624 % We then create the \ext{aux} file for the main run of \BibTeX. Note
625 % that this could call \BibTeX, with the \bst{expkeys} file, in the
626 % case where we want to export all entries of a \ext{bib} file but not
627 % crossrefs. Note how, in that case, we trick \BibTeX for inputing
628 % extra files twice: we include then with their short name first (with
629 % no extension), and then with the full name. We \emph{need} to do that,
630 % since \verb+string+ abbreviations must be defined first, while
631 % crossrefs must occur after having been referenced.
632 %
633 % \begin{macrocode}
634 %<*script>
635 if [ -z "${EXT}" ]; then ## we export all entries
636 if [ -z "${EXTRA}" ]; then ## we have no extra files
637 cat > ${TMPFILE}.aux <<EOF
638 \citation{*}
639 \bibdata{${FILE}}
640 \bibstyle{${BST}}
641 EOF
642 else ## we have extra files (e.g. for crossrefs) but want all entries from ${FILE}
643 ## we first extract the keys to be used:
644 cat > ${TMPFILE}.aux <<EOF
645 \citation{*}
646 \bibdata{${FILE}}
647 \bibstyle{expkeys}
648 EOF
649 ## This run may generate errors. We redirect the output:
650 bibtex -min-crossrefs=${CREF} -terse ${TMPFILE} >/dev/null 2>&1;
651 mv -f ${TMPFILE}.bbl ${TMPFILE}.aux;
652 ## and then prepare the .aux file for exporting:
653 cat >> ${TMPFILE}.aux <<EOF
654 \bibdata{${EXTRA}${FILE}${EXTRABIB}}
655 \bibstyle{${BST}}
656 EOF
657 fi
658 else ## we only export entries listed in the given .aux file:
659 if [ -z "${REPLACEBIB}" ]; then
660 cat ${FILE} | sed -e "s/bibstyle{.*}/bibstyle{${BST}}/" > ${TMPFILE}.aux;
661 else
662 cat ${FILE} | sed -e "s/bibstyle{.*}/bibstyle{${BST}}/" \
663 -e "s|bibdata{.*}|bibdata{${EXTRA}${NEWBIB%,}${EXTRABIB}}|" > ${TMPFILE}.aux;
664 fi
665 fi
666 %</script>
667 % \end{macrocode}
668 %
669 % This was the hard part. We now call \BibTeX, clean and rename the
670 % output file, and remove intermediary files:
671 %
672 % \begin{macrocode}
673 %<*script>
674 if [ -z "$DEBUG" ]; then
675 bibtex -min-crossrefs=${CREF} ${TERSE} ${TMPFILE};
676 if [ -e ${FINALFILE} ] && [ -z "${NOSAVE}" ]; then
677 mv ${FINALFILE} ${FINALFILE}-save-`date "+%Y.%m.%d:%H.%M.%S"`
678 fi
679 echo "" > ${FINALFILE}
680 else
681 echo "bibtex -min-crossrefs=${CREF} ${TERSE} ${TMPFILE};"
682 if [ -e ${FINALFILE} ] && [ -z "${NOSAVE}" ]; then
683 echo "mv ${FINALFILE} ${FINALFILE}-save-`date \"+%Y.%m.%d:%H.%M.%S\"`"
684 fi
685 echo "echo \"\" > ${FINALFILE}"
686 fi
687 if [ ! -z "${BANNER}" ]; then
688 ## list of cited entries
689 if [ -z "$DEBUG" ]; then
690 sed -i -e "s/\\\bibstyle{.*}/\\\bibstyle{expcites}/" ${TMPFILE}.aux
691 mv ${TMPFILE}.aux ${TMPFILE}-cites.aux
692 bibtex -terse -min-crossrefs=${CREF} ${TMPFILE}-cites
693 echo -ne "@comment{generated using bibexport:\n" >> ${FINALFILE};
694 echo -ne " creation date:\t`date +\"%c\"`\n" >> ${FINALFILE};
695 echo -ne " command:\t\t`basename $0` ${ARGS}\n" >> ${FINALFILE};
696 if [ -z "${EXT}" ]; then
697 echo -ne " source files:\t\t${FILETAB}\t\t\t${EXTRABIBTAB}\n" >> ${FINALFILE}; \
698 fi
699 cat ${TMPFILE}-cites.bbl >> ${FINALFILE};
700 #echo -ne " bibexport-version:\tv${VERSION} (${VDATE})\n" >> ${FINALFILE};
701 #echo -ne " bibexport-maintainer:\tNicolas Markey <bibexport(at)markey.fr>\n" >> ${FINALFILE};
702 sed -i -e "s/}/)/g" ${FINALFILE};
703 echo -n -e "}\n\n\n" >> ${FINALFILE};
704 rm -f ${TMPFILE}-cites.bbl ${TMPFILE}-cites.aux ${TMPFILE}-cites.blg
705 fi
706 fi
707 if [ ${CREF} -ne 1 ]; then
708 if [ -z "$DEBUG" ]; then
709 egrep -iv '^ *crossref *= *[^,]+,?$' \
710 ${TMPFILE}.bbl >> ${FINALFILE};
711 else
712 echo "egrep -iv '^ *crossref *= *[^,]+,?$' ${TMPFILE}.bbl >> ${FINALFILE};"
713 fi
714 else
715 if [ -z "$DEBUG" ]; then
716 cat ${TMPFILE}.bbl >> ${FINALFILE};
717 else
718 echo "cat ${TMPFILE}.bbl >> ${FINALFILE};"
719 fi
720 fi
721 if [ -z "$DEBUG" ]; then
722 rm -f ${TMPFILE}.bbl ${TMPFILE}.aux ${TMPFILE}.blg;
723 else
724 echo "rm -f ${TMPFILE}.bbl ${TMPFILE}.aux ${TMPFILE}.blg";
725 fi
726 %</script>
727 % \end{macrocode}
728 %
729 %
730 % \subsection{The \bst{expkeys} file}
731 %
732 % The only role of that file is to export the list of entries to be
733 % exported. It is used when we export all the entries of \ext{bib}
734 % files, except those of \emph{extra} \ext{bib} files.
735 % Thus:
736 % \begin{macrocode}
737 %<*expkeys>
738 ENTRY{}{}{}
739 READ
740 FUNCTION{export.key}
741 {
742 "\citation{" cite$ "}" * * write$ newline$
743 }
744 ITERATE{export.key}
745 %</expkeys>
746 % \end{macrocode}
747 %
748 % \subsection{The \bst{expcites} file}
749 %
750 % This file is used for exporting and formating the list of \verb+\cite+d entries.
751 % We begin with some parameters defining the margins
752 % \subsubsection{Some configuration values}
753 % \begin{macro}{left.width}
754 % \begin{macro}{right.width}
755 % \begin{macro}{url.right.width}
756 % \begin{macro}{left.short.width}
757 % \begin{macro}{right.short.width}
758 % \begin{macro}{left.delim}
759 % \begin{macro}{right.delim}
760 % \begin{macrocode}
761 %<*expcites>
762 FUNCTION{left.width}{#23}
763 FUNCTION{right.width}{#55}
764 FUNCTION{url.right.width}{#61}
765 FUNCTION{left.short.width}{#10} %% for @preamble
766 FUNCTION{right.long.width}{#63}
767 FUNCTION{left.delim}{quote$}
768 FUNCTION{right.delim}{quote$}
769 %</expcites>
770 % \end{macrocode}
771 % \end{macro}
772 % \end{macro}
773 % \end{macro}
774 % \end{macro}
775 % \end{macro}
776 % \end{macro}
777 % \end{macro}
778 %
779 % \subsubsection{Entries}
780 % We only want to export \verb+\cite+d keys, so we won't use any field.
781 % \begin{macro}{ENTRY}
782 % \begin{macrocode}
783 %<*expcites>
784 ENTRY{dummy}{}{}
785 %</expcites>
786 % \end{macrocode}
787 % \end{macro}
788 %
789 % \subsubsection{Basic functions}
790 %
791 %\begin{macro}{or}
792 %\begin{macro}{and}
793 %\begin{macro}{not}
794 % \begin{macrocode}
795 %<*expcites>
796 FUNCTION{not}
797 {
798 {#0}
799 {#1}
800 if$
801 }
802 FUNCTION{and}
803 {
804 'skip$
805 {pop$ #0}
806 if$
807 }
808 FUNCTION{or}
809 {
810 {pop$ #1}
811 'skip$
812 if$
813 }
814 %</expcites>
815 % \end{macrocode}
816 % \end{macro}
817 % \end{macro}
818 % \end{macro}
819 %
820 % \subsubsection{Splitting strings}
821 %
822 % We design functions for splitting strings, so that the final
823 % \ext{bib} file will be cleanly indented.
824 % \begin{macro}{space.complete}
825 % \begin{macro}{split.string}
826 % \begin{macrocode}
827 %<*expcites>
828 INTEGERS{left.length right.length}
829 STRINGS{ s t }
830 INTEGERS{bool cpt}
831 FUNCTION{space.complete}
832 {
833 'left.length :=
834 duplicate$ text.length$ left.length swap$ -
835 {duplicate$ #0 >}
836 {
837 swap$ " " * swap$ #1 -
838 }
839 while$
840 pop$
841 }
842 FUNCTION{split.string}
843 {
844 'right.length :=
845 duplicate$ right.length #1 + #1 substring$ "" =
846 {""}
847 {
848 's :=
849 right.length
850 {duplicate$ duplicate$ s swap$ #1 substring$ " " = not and}
851 {#1 -}
852 while$
853 duplicate$ #2 <
854 {
855 pop$ " " s * ""
856 }
857 {
858 duplicate$ s swap$ #1 swap$ substring$
859 swap$
860 s swap$ global.max$ substring$
861 }
862 if$
863 }
864 if$
865 }
866 %</expcites>
867 % \end{macrocode}
868 % \end{macro}
869 % \end{macro}
870 %
871 % \subsubsection{Exporting cited entries}
872 %
873 % Now we initialize, and export \verb+\cite+d entries.
874 %\begin{macro}{init.cited.keys}
875 %\begin{macro}{write.cited.keys}
876 %\begin{macro}{write.cited.keys.last}
877 %\begin{macro}{write.nbkeys}
878 %\begin{macro}{cited.keys}
879 %\begin{macro}{end.cited.keys}
880 % \begin{macrocode}
881 %<*expcites>
882 FUNCTION{init.cited.keys}
883 {
884 left.delim 's :=
885 #0 'bool :=
886 #0 'cpt :=
887 }
888 FUNCTION{write.cited.keys}
889 {
890 bool
891 {"" left.width space.complete swap$}
892 {" list of keys: " left.width space.complete swap$
893 #1 'bool :=}
894 if$
895 {duplicate$ text.length$ right.width >}
896 {
897 right.width split.string 't :=
898 *
899 write$ newline$
900 "" left.width space.complete t
901 }
902 while$
903 pop$ pop$ t
904 }
905 FUNCTION{write.cited.keys.last}
906 {
907 bool
908 {"" left.width space.complete swap$}
909 {" list of keys: " left.width space.complete swap$
910 #1 'bool :=}
911 if$
912 {duplicate$ duplicate$ text.length$ #1 substring$ "," = not}
913 {duplicate$ text.length$ #1 - #1 swap$ substring$}
914 while$
915 duplicate$ text.length$ #1 - #1 swap$ substring$
916 right.delim * "," *
917 {duplicate$ "" = not}
918 {
919 right.width split.string 't :=
920 *
921 write$ newline$
922 "" left.width space.complete t
923 }
924 while$
925 pop$ pop$
926 }
927 FUNCTION{write.nbkeys}
928 {
929 " number of entries: " left.width space.complete
930 " " *
931 cpt int.to.str$ * "," * write$ newline$
932 }
933 FUNCTION{cited.keys}
934 {
935 cpt #1 + 'cpt :=
936 s cite$ ", " * * 's :=
937 s text.length$ #4000 >
938 {s write.cited.keys 's :=}
939 'skip$
940 if$
941 }
942 FUNCTION{end.cited.keys}
943 {
944 s write.cited.keys.last
945 write.nbkeys
946 }
947 %</expcites>
948 % \end{macrocode}
949 % \end{macro}
950 % \end{macro}
951 % \end{macro}
952 % \end{macro}
953 % \end{macro}
954 % \end{macro}
955 %
956 % \subsubsection{Now, we export...}
957 %
958 % We now export everything...
959 % \begin{macrocode}
960 %<*expcites>
961 FUNCTION{article}{cited.keys}
962 FUNCTION{book}{cited.keys}
963 FUNCTION{booklet}{cited.keys}
964 FUNCTION{conference}{cited.keys}
965 FUNCTION{habthesis}{cited.keys}
966 FUNCTION{inbook}{cited.keys}
967 FUNCTION{incollection}{cited.keys}
968 FUNCTION{inproceedings}{cited.keys}
969 FUNCTION{journals}{cited.keys}
970 FUNCTION{manual}{cited.keys}
971 FUNCTION{mastersthesis}{cited.keys}
972 FUNCTION{misc}{cited.keys}
973 FUNCTION{phdthesis}{cited.keys}
974 FUNCTION{proceedings}{cited.keys}
975 FUNCTION{techreport}{cited.keys}
976 FUNCTION{unpublished}{cited.keys}
977 READ
978 EXECUTE{init.cited.keys}
979 ITERATE{cited.keys}
980 EXECUTE{end.cited.keys}
981 %</expcites>
982 % \end{macrocode}
983 %
984 % \subsection{The \bst{export} file}
985 %
986 % \subsubsection{Some configuration values}
987 % \begin{macro}{left.width}
988 % \begin{macro}{right.width}
989 % \begin{macro}{url.right.width}
990 % \begin{macro}{left.short.width}
991 % \begin{macro}{right.short.width}
992 % \begin{macro}{left.delim}
993 % \begin{macro}{right.delim}
994 % We define here the indentation values, and the field
995 % delimiters. \emph{short} width are used for \entry{preamble}.
996 % \begin{macrocode}
997 %<*export>
998 FUNCTION{left.width}{#18}
999 FUNCTION{right.width}{#55}
1000 FUNCTION{url.right.width}{#61}
1001 FUNCTION{left.short.width}{#10} %% for @preamble
1002 FUNCTION{right.long.width}{#63}
1003 FUNCTION{left.delim}{"{"}
1004 FUNCTION{right.delim}{"}"}
1005 %FUNCTION{left.delim}{quote$}
1006 %FUNCTION{right.delim}{quote$}
1007 %</export>
1008 % \end{macrocode}
1009 %\end{macro}
1010 %\end{macro}
1011 %\end{macro}
1012 %\end{macro}
1013 %\end{macro}
1014 %\end{macro}
1015 %\end{macro}
1016 % \subsubsection{Entries}
1017 % We use standard entries here. Of course, more entries could be added
1018 % for special \ext{bib} files. Those extra entries will also have to
1019 % be added in the main exporting function.
1020 % \begin{macro}{ENTRY}
1021 % \begin{macrocode}
1022 %<*export>
1023 ENTRY{
1024 % Standard fields:
1025 address
1026 author
1027 booktitle
1028 chapter
1029 edition
1030 editor
1031 howpublished
1032 institution
1033 journal
1034 key
1035 month
1036 note
1037 number
1038 organization
1039 pages
1040 publisher
1041 school
1042 series
1043 title
1044 type
1045 volume
1046 year
1047 % Special (but still somewhat standard) fields (natbib, germbib, DBLP, ...):
1048 abstract
1049 acronym
1050 annote
1051 biburl
1052 bibsource
1053 doi
1054 eid
1055 isbn
1056 issn
1057 language
1058 timestamp
1059 url
1060 urn
1061 }{}{}
1062 %</export>
1063 % \end{macrocode}
1064 % \end{macro}
1065 %
1066 % \subsubsection{Basic functions}
1067 %
1068 % No comment.
1069 %\begin{macro}{or}
1070 %\begin{macro}{and}
1071 %\begin{macro}{not}
1072 % \begin{macrocode}
1073 %<*export>
1074 FUNCTION{not}
1075 {
1076 {#0}
1077 {#1}
1078 if$
1079 }
1080 FUNCTION{and}
1081 {
1082 'skip$
1083 {pop$ #0}
1084 if$
1085 }
1086 FUNCTION{or}
1087 {
1088 {pop$ #1}
1089 'skip$
1090 if$
1091 }
1092 %</export>
1093 % \end{macrocode}
1094 %\end{macro}
1095 %\end{macro}
1096 %\end{macro}
1097 % \subsubsection{Splitting strings}
1098 %
1099 % We design functions for splitting strings, so that the final
1100 % \ext{bib} file will be cleanly indented. This is also crucial
1101 % to avoid long URLs.
1102 % \begin{macro}{space.complete}
1103 % \begin{macro}{split.string}
1104 % \begin{macro}{split.url}
1105 % \begin{macro}{split.name}
1106 % \begin{macrocode}
1107 %<*export>
1108 INTEGERS{left.length right.length}
1109 STRINGS{ s t }
1110 FUNCTION{space.complete}
1111 {
1112 'left.length :=
1113 duplicate$ text.length$ left.length swap$ -
1114 {duplicate$ #0 >}
1115 {
1116 swap$ " " * swap$ #1 -
1117 }
1118 while$
1119 pop$
1120 }
1121 FUNCTION{split.string}
1122 {
1123 'right.length :=
1124 duplicate$ right.length #1 + #1 substring$ "" =
1125 {""}
1126 {
1127 's :=
1128 right.length
1129 {duplicate$ duplicate$ s swap$ #1 substring$ " " = not and}
1130 {#1 -}
1131 while$
1132 duplicate$ #2 <
1133 {
1134 pop$ " " s * ""
1135 }
1136 {
1137 duplicate$ s swap$ #1 swap$ substring$
1138 swap$
1139 s swap$ global.max$ substring$
1140 }
1141 if$
1142 }
1143 if$
1144 }
1145 FUNCTION{split.url}
1146 {
1147 'right.length :=
1148 duplicate$ right.length #1 + #1 substring$ "" =
1149 {""}
1150 {
1151 's :=
1152 right.length
1153 {duplicate$ duplicate$ s swap$ #1 substring$
1154 duplicate$ "/" = swap$
1155 duplicate$ "&" = swap$
1156 duplicate$ "?" = swap$
1157 duplicate$ "-" = swap$
1158 ":" = or or or or not and}
1159 {#1 -}
1160 while$
1161 duplicate$ #2 <
1162 {
1163 pop$ " " s * ""
1164 }
1165 {
1166 duplicate$ s swap$ #1 swap$ substring$
1167 swap$ #1 +
1168 s swap$ global.max$ substring$
1169 }
1170 if$
1171 }
1172 if$
1173 }
1174 FUNCTION{split.name}
1175 {
1176 'right.length :=
1177 duplicate$ right.length #1 + #1 substring$ "" =
1178 {""}
1179 {
1180 's :=
1181 right.length
1182 {duplicate$ duplicate$ s swap$ #5 substring$ " and " = not and}
1183 {#1 -}
1184 while$
1185 duplicate$ #2 <
1186 {
1187 pop$ " " s * ""
1188 }
1189 {
1190 #4 + duplicate$ s swap$ #1 swap$ substring$
1191 swap$
1192 s swap$ global.max$ substring$
1193 }
1194 if$
1195 }
1196 if$
1197 }
1198 %</export>
1199 % \end{macrocode}
1200 % \end{macro}
1201 % \end{macro}
1202 % \end{macro}
1203 % \end{macro}
1204 % \subsubsection{Exporting fields}
1205 %
1206 % Here, we have four exporting functions, since we also have to deal
1207 % with abbreviations:
1208 %\begin{macro}{field.export}
1209 %\begin{macro}{abbrv.export}
1210 %\begin{macro}{name.export}
1211 %\begin{macro}{url.export}
1212 % \begin{macrocode}
1213 %<*export>
1214 FUNCTION{field.export}
1215 {
1216 duplicate$ missing$
1217 'skip$
1218 {
1219 left.delim swap$ * right.delim *
1220 swap$
1221 " " swap$ * " = " * left.width space.complete
1222 swap$ "," *
1223 {duplicate$ "" = not}
1224 {
1225 right.width split.string 't :=
1226 *
1227 write$ newline$
1228 "" left.width space.complete t
1229 }
1230 while$
1231 }
1232 if$
1233 pop$ pop$
1234 }
1235 FUNCTION{abbrv.export}
1236 {
1237 duplicate$ missing$
1238 'skip$
1239 {
1240 swap$
1241 " " swap$ * " = " * left.width space.complete
1242 swap$ "," *
1243 {duplicate$ "" = not}
1244 {
1245 right.width split.string 't :=
1246 *
1247 write$ newline$
1248 "" left.width space.complete t
1249 }
1250 while$
1251 }
1252 if$
1253 pop$ pop$
1254 }
1255 FUNCTION{name.export}
1256 {
1257 duplicate$ missing$
1258 'skip$
1259 {
1260 left.delim swap$ * right.delim *
1261 swap$
1262 " " swap$ * " = " * left.width space.complete
1263 swap$ "," *
1264 {duplicate$ "" = not}
1265 {
1266 right.width split.name 't :=
1267 *
1268 write$ newline$
1269 "" left.width space.complete t
1270 }
1271 while$
1272 }
1273 if$
1274 pop$ pop$
1275 }
1276 FUNCTION{url.export}
1277 {
1278 duplicate$ missing$
1279 'skip$
1280 {
1281 left.delim swap$ * right.delim *
1282 swap$
1283 " " swap$ * " = " * left.width space.complete
1284 swap$ "," *
1285 {duplicate$ "" = not}
1286 {
1287 url.right.width split.url 't :=
1288 *
1289 write$ newline$
1290 "" left.width space.complete t
1291 }
1292 while$
1293 }
1294 if$
1295 pop$ pop$
1296 }
1297 %</export>
1298 % \end{macrocode}
1299 %\end{macro}
1300 %\end{macro}
1301 %\end{macro}
1302 %\end{macro}
1303 % \subsubsection{Handling abbreviations}
1304 %
1305 % Abbreviations are difficult to deal with if we wish to still use
1306 % them, since \BibTeX will expand them before we can do anything. All we
1307 % can do is to define them in a special way, in order to be able to get
1308 % back to the abbreviations later on. This is precisely what we do:
1309 %\begin{macro}{jan-dec}
1310 %\begin{macro}{acmcs-tcs}
1311 %\begin{macro}{remove.exports.from.months}
1312 %\begin{macro}{remove.export.from.journal}
1313 % \begin{macrocode}
1314 %<*export>
1315 MACRO{jan}{"export-jan"}
1316 MACRO{feb}{"export-feb"}
1317 MACRO{mar}{"export-mar"}
1318 MACRO{apr}{"export-apr"}
1319 MACRO{may}{"export-may"}
1320 MACRO{jun}{"export-jun"}
1321 MACRO{jul}{"export-jul"}
1322 MACRO{aug}{"export-aug"}
1323 MACRO{sep}{"export-sep"}
1324 MACRO{oct}{"export-oct"}
1325 MACRO{nov}{"export-nov"}
1326 MACRO{dec}{"export-dec"}
1327 MACRO{acmcs}{"export-acmcs"}
1328 MACRO{acta}{"export-acta"}
1329 MACRO{cacm}{"export-cacm"}
1330 MACRO{ibmjrd}{"export-ibmjrd"}
1331 MACRO{ibmsj}{"export-ibmsj"}
1332 MACRO{ieeese}{"export-ieeese"}
1333 MACRO{ieeetc}{"export-ieeetc"}
1334 MACRO{ieeetcad}{"export-ieeetcad"}
1335 MACRO{ipl}{"export-ipl"}
1336 MACRO{jacm}{"export-jacm"}
1337 MACRO{jcss}{"export-jcss"}
1338 MACRO{scp}{"export-scp"}
1339 MACRO{sicomp}{"export-sicomp"}
1340 MACRO{tocs}{"export-tocs"}
1341 MACRO{tods}{"export-tods"}
1342 MACRO{tog}{"export-tog"}
1343 MACRO{toms}{"export-toms"}
1344 MACRO{toois}{"export-poois"}
1345 MACRO{toplas}{"export-toplas"}
1346 MACRO{tcs}{"export-tcs"}
1347 INTEGERS{ intxt }
1348 FUNCTION{remove.exports.from.months}
1349 {
1350 #0 'intxt :=
1351 duplicate$ missing$
1352 'skip$
1353 {'t :=
1354 ""
1355 {t #1 #1 substring$ "" = not}
1356 {
1357 t #1 #7 substring$ "export-" =
1358 {intxt
1359 {right.delim * #0 'intxt :=}
1360 'skip$
1361 if$
1362 duplicate$ "" =
1363 'skip$
1364 {" # " *}
1365 if$
1366 t #8 #3 substring$ *
1367 t #11 global.max$ substring$ 't :=}
1368 {intxt
1369 'skip$
1370 {duplicate$ "" =
1371 {}
1372 {" # " *}
1373 if$
1374 left.delim * #1 'intxt :=}
1375 if$
1376 t #1 #1 substring$ *
1377 t #2 global.max$ substring$ 't :=}
1378 if$
1379 }
1380 while$
1381 intxt
1382 {right.delim *}
1383 'skip$
1384 if$
1385 }
1386 if$
1387 }
1388 FUNCTION{remove.export.from.journals}
1389 {
1390 duplicate$ missing$
1391 'skip$
1392 {
1393 duplicate$ #1 #7 substring$ "export-" =
1394 {#8 global.max$ substring$}
1395 {left.delim swap$
1396 right.delim * *}
1397 if$
1398 }
1399 if$
1400 }
1401 %</export>
1402 % \end{macrocode}
1403 %\end{macro}
1404 %\end{macro}
1405 %\end{macro}
1406 %\end{macro}
1407 %
1408 % \subsubsection{Now, we export...}
1409 %
1410 % We gather everything. This is were special fields must be added for
1411 % being exported:
1412 %\begin{macro}{entry.export.standard}
1413 %\begin{macro}{entry.export.extra}
1414 %\begin{macro}{entry.export}
1415 %\begin{macro}{export}
1416 % \begin{macrocode}
1417 %<*export>
1418 FUNCTION{entry.export.standard}
1419 {
1420 "address" address field.export
1421 "author" author name.export
1422 "booktitle" booktitle field.export
1423 "chapter" chapter field.export
1424 "crossref" crossref field.export
1425 "edition" edition field.export
1426 "editor" editor name.export
1427 "howpublished" howpublished field.export
1428 "institution" institution field.export
1429 "journal" journal remove.export.from.journals abbrv.export
1430 "key" key field.export
1431 "month" month remove.exports.from.months abbrv.export
1432 "note" note field.export
1433 "number" number field.export
1434 "organization" organization field.export
1435 "pages" pages field.export
1436 "publisher" publisher field.export
1437 "school" school field.export
1438 "series" series field.export
1439 "type" type field.export
1440 "title" title field.export
1441 "volume" volume field.export
1442 "year" year field.export
1443 }
1444 FUNCTION{entry.export.extra}
1445 {
1446 "abstract" abstract field.export
1447 "acronym" acronym field.export
1448 "annote" annote field.export
1449 "biburl" biburl url.export
1450 "bibsource" bibsource field.export
1451 "doi" doi field.export
1452 "eid" eid field.export
1453 "isbn" isbn field.export
1454 "issn" issn field.export
1455 "language" language field.export
1456 "timestamp" timestamp field.export
1457 "url" url url.export
1458 "urn" urn url.export
1459 }
1460 FUNCTION{entry.export}
1461 {
1462 entry.export.standard
1463 entry.export.extra
1464 }
1465 FUNCTION{export}
1466 {
1467 "@" type$ * "{" * cite$ * "," * write$ newline$
1468 entry.export
1469 "}" write$ newline$ newline$
1470 }
1471 %</export>
1472 % \end{macrocode}
1473 %\end{macro}
1474 %\end{macro}
1475 %\end{macro}
1476 %\end{macro}
1477 %
1478 % \subsubsection{Miscellanea}
1479 % We also have to handle preamble, and to define functions for each
1480 % entry type (we won't use them but otherwise, \BibTeX would complain).
1481 %
1482 %\begin{macro}{preamble}
1483 %\begin{macro}{header}
1484 %\begin{macro}{entries.headers}
1485 %\begin{macro}{article-unpublished}
1486 % \begin{macrocode}
1487 %<*export>
1488 FUNCTION{preamble}
1489 {
1490 preamble$ duplicate$ "" =
1491 'pop$
1492 {
1493 ",-------------------." write$ newline$
1494 "| PREAMBLE |" write$ newline$
1495 "`-------------------'" write$ newline$ newline$
1496 "@preamble{ " swap$
1497 quote$ swap$ * quote$ *
1498 {duplicate$ "" = not}
1499 {
1500 right.long.width split.string 't :=
1501 *
1502 write$ newline$
1503 "" left.short.width space.complete t
1504 }
1505 while$
1506 "}" write$ newline$ newline$
1507 pop$ pop$
1508 }
1509 if$
1510 }
1511 FUNCTION{header}
1512 {
1513 %"** This file has been automatically generated by bibexport **"
1514 %write$ newline$
1515 %"** See http://people.irisa.fr/Nicolas.Markey/latex.php **"
1516 %write$ newline$
1517 %"** for more informations about bibexport. **"
1518 %write$ newline$
1519 newline$
1520 }
1521 FUNCTION{entries.header}
1522 {
1523 preamble$ "" =
1524 'skip$
1525 {
1526 ",-------------------." write$ newline$
1527 "| BIBTEX ENTRIES |" write$ newline$
1528 "`-------------------'" write$ newline$ newline$
1529 }
1530 if$
1531 }
1532 FUNCTION{article}{export}
1533 FUNCTION{book}{export}
1534 FUNCTION{booklet}{export}
1535 FUNCTION{conference}{export}
1536 FUNCTION{habthesis}{export}
1537 FUNCTION{inbook}{export}
1538 FUNCTION{incollection}{export}
1539 FUNCTION{inproceedings}{export}
1540 FUNCTION{journals}{export}
1541 FUNCTION{manual}{export}
1542 FUNCTION{mastersthesis}{export}
1543 FUNCTION{misc}{export}
1544 FUNCTION{phdthesis}{export}
1545 FUNCTION{proceedings}{export}
1546 FUNCTION{techreport}{export}
1547 FUNCTION{unpublished}{export}
1548 %</export>
1549 % \end{macrocode}
1550 %\end{macro}
1551 %\end{macro}
1552 %\end{macro}
1553 %\end{macro}
1554 % \subsubsection{Main program}
1555 %
1556 % We now can execute and iterate those functions:
1557 %
1558 % \begin{macrocode}
1559 %<*export>
1560 READ
1561 EXECUTE{header}
1562 EXECUTE{preamble}
1563 EXECUTE{entries.header}
1564 ITERATE{export}
1565 %</export>
1566 % \end{macrocode}
1567 %
1568 % \Finale
1569 \endinput