CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
7 Utilities for Bibliographies
3
4
A standard for collecting references (in particular to mathematical texts)
5
is BibTeX (http://www.ctan.org/tex-archive/biblio/bibtex/distribs/doc/). A
6
disadvantage of BibTeX is that the format of the data is specified with the
7
use by LaTeX in mind. The data format is less suited for conversion to other
8
document types like plain text or HTML.
9
10
In the first section we describe utilities for using data from BibTeX files
11
in GAP.
12
13
In the second section we introduce a new XML based data format BibXMLext for
14
bibliographies which seems better suited for other tasks than using it with
15
LaTeX.
16
17
Another section will describe utilities to deal with BibXMLext data in GAP.
18
19
20
7.1 Parsing BibTeX Files
21
22
Here are functions for parsing, normalizing and printing reference lists in
23
BibTeX format. The reference describing this format is [Lam85, Appendix B].
24
25
7.1-1 ParseBibFiles
26
27
ParseBibFiles( bibfile1[, bibfile2[, ...]] )  function
28
ParseBibStrings( str1[, str2[, ...]] )  function
29
Returns: list [list of bib-records, list of abbrevs, list of expansions]
30
31
The first function parses the files bibfile1 and so on (if a file does not
32
exist the extension .bib is appended) in BibTeX format and returns a list as
33
follows: [entries, strings, texts]. Here entries is a list of records, one
34
record for each reference contained in bibfile. Then strings is a list of
35
abbreviations defined by @string-entries in bibfile and texts is a list
36
which contains in the corresponding position the full text for such an
37
abbreviation.
38
39
The second function does the same, but the input is given as GAP strings
40
str1 and so on.
41
42
The records in entries store key-value pairs of a BibTeX reference in the
43
form rec(key1 = value1, ...). The names of the keys are converted to lower
44
case. The type of the reference (i.e., book, article, ...) and the citation
45
key are stored as components .Type and .Label. The records also have a .From
46
field that says that the data are read from a BibTeX source.
47
48
As an example consider the following BibTeX file.
49
50
 doc/test.bib 
51
@string{ j = "Important Journal" }
52
@article{ AB2000, Author= "Fritz A. First and Sec, X. Y.", 
53
TITLE="Short", journal = j, year = 2000 }
54

55
56
 Example 
57
gap> bib := ParseBibFiles("doc/test.bib");
58
[ [ rec( From := rec( BibTeX := true ), Label := "AB2000", 
59
 Type := "article", author := "Fritz A. First and Sec, X. Y."
60
 , journal := "Important Journal", title := "Short", 
61
 year := "2000" ) ], [ "j" ], [ "Important Journal" ] ]
62

63
64
7.1-2 NormalizedNameAndKey
65
66
NormalizedNameAndKey( namestr )  function
67
Returns: list of strings and names as lists
68
69
NormalizeNameAndKey( r )  function
70
Returns: nothing
71
72
The argument namestr must be a string describing an author or a list of
73
authors as described in the BibTeX documentation in [Lam85, Appendix B 1.2].
74
The function NormalizedNameAndKey returns a list of the form [ normalized
75
name string, short key, long key, names as lists]. The first entry is a
76
normalized form of the input where names are written as lastname, first name
77
initials. The second and third entry are the name parts of a short and long
78
key for the bibliography entry, formed from the (initials of) last names.
79
The fourth entry is a list of lists, one for each name, where a name is
80
described by three strings for the last name, the first name initials and
81
the first name(s) as given in the input.
82
83
The function NormalizeNameAndKey gets as argument r a record for a
84
bibliography entry as returned by ParseBibFiles (7.1-1). It substitutes
85
.author and .editor fields of r by their normalized form, the original
86
versions are stored in fields .authororig and .editororig.
87
88
Furthermore a short and a long citation key is generated and stored in
89
components .printedkey (only if no .key is already bound) and .keylong.
90
91
We continue the example from ParseBibFiles (7.1-1).
92
93
 Example 
94
gap> bib := ParseBibFiles("doc/test.bib");;
95
gap> NormalizedNameAndKey(bib[1][1].author);
96
[ "First, F. A. and Sec, X. Y.", "FS", "firstsec", 
97
 [ [ "First", "F. A.", "Fritz A." ], [ "Sec", "X. Y.", "X. Y." ] ] ]
98
gap> NormalizeNameAndKey(bib[1][1]);
99
gap> bib[1][1];
100
rec( From := rec( BibTeX := true ), Label := "AB2000", 
101
 Type := "article", author := "First, F. A. and Sec, X. Y.", 
102
 authororig := "Fritz A. First and Sec, X. Y.", 
103
 journal := "Important Journal", keylong := "firstsec2000", 
104
 printedkey := "FS00", title := "Short", year := "2000" )
105

106
107
7.1-3 WriteBibFile
108
109
WriteBibFile( bibfile, bib )  function
110
Returns: nothing
111
112
This is the converse of ParseBibFiles (7.1-1). Here bib either must have a
113
format as list of three lists as it is returned by ParseBibFiles (7.1-1). Or
114
bib can be a record as returned by ParseBibXMLextFiles (7.3-4). A BibTeX
115
file bibfile is written and the entries are formatted in a uniform way. All
116
given abbreviations are used while writing this file.
117
118
We continue the example from NormalizeNameAndKey (7.1-2). The command
119
120
 Example 
121
gap> WriteBibFile("nicer.bib", bib);
122

123
124
produces a file nicer.bib as follows:
125
126
 nicer.bib 
127
@string{j = "Important Journal" }
128

129
@article{ AB2000,
130
 author = {First, F. A. and Sec, X. Y.},
131
 title = {Short},
132
 journal = j,
133
 year = {2000},
134
 authororig = {Fritz A. First and Sec, X. Y.},
135
 keylong = {firstsec2000},
136
 printedkey = {FS00}
137
}
138

139
140
7.1-4 LabelsFromBibTeX
141
142
LabelsFromBibTeX( path, keys, bibfiles, style )  function
143
Returns: a list of pairs of strings [key, label]
144
145
This function uses bibtex to determine the ordering of a list of references
146
and a label for each entry which is typeset in a document citing these
147
references.
148
149
The argument path is a directory specified as string or directory object.
150
The argument bibfiles must be a list of files in BibTeX format, each
151
specified by a path relative to the first argument, or an absolute path
152
(starting with '/') or relative to the GAP roots (starting with "gap://").
153
The list keys must contain strings which occur as keys in the given BibTeX
154
files. Finally the string style must be the name of a bibliography style
155
(like "alpha").
156
157
The list returned by this function contains pairs [key, label] where key is
158
one of the entries of keys and label is a string used for citations of the
159
bibliography entry in a document. These pairs are ordered as the reference
160
list produced by BibTeX.
161
162
 Example 
163
gap> f := Filename(DirectoriesPackageLibrary("gapdoc","doc"), "test.bib");;
164
gap> LabelsFromBibTeX(".", ["AB2000"], [f], "alpha");
165
[ [ "AB2000", "FS00" ] ]
166

167
168
7.1-5 InfoBibTools
169
170
InfoBibTools info class
171
172
The default level of this info class is 1. Functions like ParseBibFiles
173
(7.1-1), StringBibAs... are then printing some information. You can suppress
174
it by setting the level of InfoBibTools to 0. With level 2 there may be some
175
more information for debugging purposes.
176
177
178
7.2 The BibXMLext Format
179
180
Bibliographical data in BibTeX files have the disadvantage that the actual
181
data are given in LaTeX syntax. This makes it difficult to use the data for
182
anything but for LaTeX, say for representations of the data as plain text or
183
HTML. For example: mathematical formulae are in LaTeX $ environments,
184
non-ASCII characters can be specified in many strange ways, and how to
185
specify URLs for links if the output format allows them?
186
187
Here we propose an XML data format for bibliographical data which addresses
188
these problems, it is called BibXMLext. In the next section we describe some
189
tools for generating (an approximation to) this data format from BibTeX
190
data, and for using data given in BibXMLext format for various purposes.
191
192
The first motivation for this development was the handling of
193
bibliographical data in GAPDoc, but the format and the tools are certainly
194
useful for other purposes as well.
195
196
We started from a DTD bibxml.dtd which is publicly available, say from
197
http://bibtexml.sf.net/. This is essentially a reformulation of the
198
definition of the BibTeX format, including several of some widely used
199
further fields. This has already the advantage that a generic XML parser can
200
check the validity of the data entries, for example for missing compulsary
201
fields in entries. We applied the following changes and extensions to define
202
the DTD for BibXMLext, stored in the file bibxmlext.dtd which can be found
203
in the root directory of this GAPDoc package (and in Appendix C):
204
205
names
206
Lists of names in the author and editor fields in BibTeX are difficult
207
to parse. Here they must be given by a sequence of <name>-elements
208
which each contain an optional <first>- and a <last>-element for the
209
first and last names, respectively.
210
211
<M> and <Math>
212
These elements enclose mathematical formulae, the content is LaTeX
213
code (without the $). These should be handled in the same way as the
214
elements with the same names in GAPDoc, see 3.8-2 and 3.8-1. In
215
particular, simple formulae which have a well defined plain text
216
representation can be given in <M>-elements.
217
218
Encoding
219
Note that in XML files we can use the full range of unicode
220
characters, see http://www.unicode.org/. All non-ASCII characters
221
should be specified as unicode characters. This makes dealing with
222
special characters easy for plain text or HTML, only for use with
223
LaTeX some sort of translation is necessary.
224
225
<URL>
226
These elements are allowed everywhere in the text and should be
227
represented by links in converted formats which allow this. It is used
228
in the same way as the element with the same name in GAPDoc, see
229
3.5-5.
230
231
<Alt Only="..."> and <Alt Not="...">
232
Sometimes information should be given in different ways, depending on
233
the output format of the data. This is possible with the
234
<Alt>-elements with the same definition as in GAPDoc, see 3.9-1.
235
236
<C>
237
This element should be used to protect text from case changes by
238
converters (the extra {} characters in BibTeX title fields).
239
240
<string key="..." value="..."/> and <value key="..."/>
241
The <string>-element defines key-value pairs which can be used in any
242
field via the <value>-element (not only for whole fields but also
243
parts of the text).
244
245
<other type="...">
246
This is a generic element for fields which are otherwise not
247
supported. An arbitrary number of them is allowed for each entry, so
248
any kind of additional data can be added to entries.
249
250
<Wrap Name="...">
251
This generic element is allowed inside all fields. This markup will be
252
just ignored (but not the element content) by our standard tools. But
253
it can be a useful hook for introducing arbitrary further markup (and
254
our tools can easily be extended to handle it).
255
256
Extra entities
257
The DTD defines the standard XML entities (2.1-10 and the entities
258
&nbsp; (non-breakable space), &ndash; and &copyright;. Use &ndash; in
259
page ranges.
260
261
For further details of the DTD we refer to the file bibxmlext.dtd itself
262
which is shown in appendix C. That file also recalls some information from
263
the BibTeX documentation on how the standard fields of entries should be
264
used. Which entry types and which fields are supported (and the ordering of
265
the fields which is fixed by a DTD) can be either read off the DTD, or
266
within GAP one can use the function TemplateBibXML (7.3-10) to get templates
267
for the various entry types.
268
269
Here is an example of a BibXMLext document:
270
271
 doc/testbib.xml 
272
<?xml version="1.0" encoding="UTF-8"?>
273
<!DOCTYPE file SYSTEM "bibxmlext.dtd">
274
<file>
275
<string key="j" value="Important Journal"/>
276
<entry id="AB2000"><article>
277
 <author>
278
 <name><first>Fritz A.</first><last>First</last></name>
279
 <name><first>X. Y.</first><last>Sec&#x0151;nd</last></name>
280
 </author> 
281
 <title>The <Wrap Name="Package"> <C>F</C>ritz</Wrap> package for the 
282
 formula <M>x^y - l_{{i+1}} \rightarrow \mathbb{R}</M></title>
283
 <journal><value key="j"/></journal>
284
 <year>2000</year>
285
 <number>13</number>
286
 <pages>13&ndash;25</pages>
287
 <note>Online data at <URL Text="Bla Bla Publisher">
288
 http://www.publish.com/~ImpJ/123#data</URL></note>
289
 <other type="mycomment">very useful</other>
290
</article></entry>
291
</file>
292

293

294
295
There is a standard XML header and a DOCTYPE declaration referring to the
296
bibxmlext.dtd DTD mentioned above. Local entities could be defined in the
297
DOCTYPE tag as shown in the example in 2.2-3. The actual content of the
298
document is inside a <file>-element, it consists of <string>- and
299
<entry>-elements. Several of the BibXMLext markup features are shown. We
300
will use this input document for some examples below.
301
302
303
7.3 Utilities for BibXMLext data
304
305
306
7.3-1 Translating BibTeX to BibXMLext
307
308
First we describe a tool which can translate bibliography entries from
309
BibTeX data to BibXMLext <entry>-elements. It also does some validation of
310
the data. In some cases it is desirable to improve the result by hand
311
afterwards (editing formulae, adding <URL>-elements, translating non-ASCII
312
characters to unicode, ...).
313
314
See WriteBibXMLextFile (7.3-5) below for how to write the results to a
315
BibXMLext file.
316
317
7.3-2 HeuristicTranslationsLaTeX2XML.Apply
318
319
HeuristicTranslationsLaTeX2XML.Apply( str )  function
320
Returns: a string
321
322
HeuristicTranslationsLaTeX2XML.ApplyToFile( fnam[, outnam] )  function
323
Returns: nothing
324
325
These utilities translate some LaTeX code into text in UTF-8 encoding. The
326
input is given as a string str, or a file name fnam, respectively. The first
327
function returns the translated string. The second function with one
328
argument overwrites the given file with the translated text. Optionally, the
329
translated file content can be written to another file, if its name is given
330
as second argument outnam.
331
332
The record HeuristicTranslationsLaTeX2XML mainly contains translations of
333
LaTeX macros for special characters which were found in hundreds of BibTeX
334
entries from MathSciNet (http://www.ams.org/mathscinet/). Just look at this
335
record if you want to know how it works. It is easy to extend, and if you
336
have improvements which may be of general interest, please send them to the
337
GAPDoc author.
338
339
 Example 
340
gap> s := "\\\"u\\'{e}\\`e{\\ss}";;
341
gap> Print(s, "\n"); 
342
\"u\'{e}\`e{\ss}
343
gap> Print(HeuristicTranslationsLaTeX2XML.Apply(s),"\n");
344
üéèß
345

346
347
7.3-3 StringBibAsXMLext
348
349
StringBibAsXMLext( bibentry[, abbrvs, vals][, encoding] )  function
350
Returns: a string with XML code, or fail
351
352
The argument bibentry is a record representing an entry from a BibTeX file,
353
as returned in the first list of the result of ParseBibFiles (7.1-1). The
354
optional two arguments abbrvs and vals can be lists of abbreviations and
355
substitution strings, as returned as second and third list element in the
356
result of ParseBibFiles (7.1-1). The optional argument encoding specifies
357
the character encoding of the string components of bibentry. If this is not
358
given it is checked if all strings are valid UTF-8 encoded strings, in that
359
case it is assumed that the encoding is UTF-8, otherwise the latin1 encoding
360
is assumed.
361
362
The function StringBibAsXMLext creates XML code of an <entry>-element in
363
BibXMLext format. The result is in UTF-8 encoding and contains some
364
heuristic translations, like splitting name lists, finding places for
365
<C>-elements, putting formulae in <M>-elements, substituting some
366
characters. The result should always be checked and maybe improved by hand.
367
Some validity checks are applied to the given data, for example if all
368
non-optional fields are given. If this check fails the function returns
369
fail.
370
371
If your BibTeX input contains LaTeX markup for special characters, it can be
372
convenient to translate this input with HeuristicTranslationsLaTeX2XML.Apply
373
(7.3-2) or HeuristicTranslationsLaTeX2XML.ApplyToFile (7.3-2) before parsing
374
it as BibTeX.
375
376
As an example we consider again the short BibTeX file doc/test.bib shown in
377
the example for ParseBibFiles (7.1-1).
378
379
 Example 
380
gap> bib := ParseBibFiles("doc/test.bib");;
381
gap> str := StringBibAsXMLext(bib[1][1], bib[2], bib[3]);;
382
gap> Print(str, "\n");
383
<entry id="AB2000"><article>
384
 <author>
385
 <name><first>Fritz A.</first><last>First</last></name>
386
 <name><first>X. Y.</first><last>Sec</last></name>
387
 </author> 
388
 <title>Short</title>
389
 <journal><value key="j"/></journal>
390
 <year>2000</year>
391
</article></entry>
392

393
394
The following functions allow parsing of data which are already in BibXMLext
395
format.
396
397
7.3-4 ParseBibXMLextString
398
399
ParseBibXMLextString( str[, res] )  function
400
ParseBibXMLextFiles( fname1[, fname2[, ...]] )  function
401
Returns: a record with fields .entries, .strings and .entities
402
403
The first function gets a string str containing a BibXMLext document or a
404
part of it. It returns a record with the three mentioned fields. Here
405
.entries is a list of partial XML parse trees for the <entry>-elements in
406
str. The field .strings is a list of key-value pairs from the
407
<string>-elements in str. And .strings is a list of name-value pairs of the
408
named entities which were used during the parsing.
409
410
The optional argument res can be the result of a former call of this
411
function, in that case the newly parsed entries are added to this data
412
structure.
413
414
The second function ParseBibXMLextFiles uses the first on the content of all
415
files given by filenames fname1 and so on. It collects the results in a
416
single record.
417
418
As an example we parse the file testbib.xml shown in 7.2.
419
420
 Example 
421
gap> bib := ParseBibXMLextFiles("doc/testbib.xml");;
422
gap> RecNames(bib);
423
[ "entries", "strings", "entities" ]
424
gap> bib.entries;
425
[ <BibXMLext entry: AB2000> ]
426
gap> bib.strings;
427
[ [ "j", "Important Journal" ] ]
428
gap> bib.entities[1]; 
429
[ "amp", "&#38;#38;" ]
430

431
432
7.3-5 WriteBibXMLextFile
433
434
WriteBibXMLextFile( fname, bib )  function
435
Returns: nothing
436
437
This function writes a BibXMLext file with name fname.
438
439
There are three possibilities to specify the bibliography entries in the
440
argument bib. It can be a list of three lists as returned by ParseBibFiles
441
(7.1-1). Or it can be just the first of such three lists in which case the
442
other two lists are assumed to be empty. To all entries of the (first) list
443
the function StringBibAsXMLext (7.3-3) is applied and the resulting strings
444
are written to the result file.
445
446
The third possibility is that bib is a record in the format as returned by
447
ParseBibXMLextString (7.3-4) and ParseBibXMLextFiles (7.3-4). In this case
448
the entries for the BibXMLext file are produced with StringXMLElement
449
(5.2-2), and if bib.entities is bound then it is tried to resubstitute parts
450
of the string by the given entities with EntitySubstitution (5.2-3).
451
452
As an example we write back the result of the example shown for
453
ParseBibXMLextFiles (7.3-4) to an equivalent XML file.
454
455
 Example 
456
gap> bib := ParseBibXMLextFiles("doc/testbib.xml");;
457
gap> WriteBibXMLextFile("test.xml", bib);
458

459
460
461
7.3-6 Bibliography Entries as Records
462
463
For working with BibXMLext entries we find it convenient to first translate
464
the parse tree of an entry, as returned by ParseBibXMLextFiles (7.3-4), to a
465
record with the field names of the entry as components whose value is the
466
content of the field as string. These strings are generated with respect to
467
a result type. The records are generated by the following function which can
468
be customized by the user.
469
470
7.3-7 RecBibXMLEntry
471
472
RecBibXMLEntry( entry[, restype][, strings][, options] )  function
473
Returns: a record with fields as strings
474
475
This function generates a content string for each field of a bibliography
476
entry and assigns them to record components. This content may depend on the
477
requested result type and possibly some given options.
478
479
The arguments are as follows: entry is the parse tree of an <entry> element
480
as returned by ParseBibXMLextString (7.3-4) or ParseBibXMLextFiles (7.3-4).
481
The optional argument restype describes the type of the result. This package
482
supports currently the types "BibTeX", "Text" and "HTML". The default is
483
"BibTeX". The optional argument strings must be a list of key-value pairs as
484
returned in the component .strings in the result of ParseBibXMLextString
485
(7.3-4). The argument options must be a record.
486
487
If the entry contains an author field then the result will also contain a
488
component .authorAsList which is a list containing for each author a list
489
with three entries of the form [last name, first name initials, first name]
490
(the third entry means the first name as given in the data). Similarly, an
491
editor field is accompanied by a component .editorAsList.
492
493
The following options are currently supported.
494
495
If options.fullname is bound and set to true then the full given first names
496
for authors and editors will be used, the default is to use the initials of
497
the first names. Also, if options.namefirstlast is bound and set to true
498
then the names are written in the form first-name(s) last-name, the default
499
is the form last-name, first-name(s).
500
501
If options.href is bound and set to false then the "BibTeX" type result will
502
not use \href commands. The default is to produce \href commands from
503
<URL>-elements such that LaTeX with the hyperref package can produce links
504
for them.
505
506
The content of an <Alt>-element with Only-attribute is included if restype
507
is given in the attribute and ignored otherwise, and vice versa in case of a
508
Not-attribute. If options.useAlt is bound, it must be a list of strings to
509
which restype is added. Then an <Alt>-element with Only-attribute is
510
evaluated if the intersection of options.useAlt and the types given in the
511
attribute is not empty. In case of a Not-attribute the element is evaluated
512
if this intersection is empty.
513
514
If restype is "BibTeX" then the string fields in the result will be recoded
515
with Encode (6.2-2) and target "LaTeX". If options.hasLaTeXmarkup is bound
516
and set to true (for example, because the data are originally read from
517
BibTeX files), then the target "LaTeXleavemarkup" will be used.
518
519
We use again the file shown in the example for ParseBibXMLextFiles (7.3-4).
520
521
 Example 
522
gap> bib := ParseBibXMLextFiles("doc/testbib.xml");;
523
gap> e := bib.entries[1];; strs := bib.strings;;
524
gap> Print(RecBibXMLEntry(e, "BibTeX", strs), "\n");
525
rec(
526
 From := rec(
527
 BibXML := true,
528
 options := rec(
529
 ),
530
 type := "BibTeX" ),
531
 Label := "AB2000",
532
 Type := "article",
533
 author := "First, F. A. and Sec{\\H o}nd, X. Y.",
534
 authorAsList := 
535
 [ [ "First", "F. A.", "Fritz A." ], 
536
 [ "Sec\305\221nd", "X. Y.", "X. Y." ] ],
537
 journal := "Important Journal",
538
 mycomment := "very useful",
539
 note := 
540
 "Online data at \\href {http://www.publish.com/~ImpJ/123#data} {Bla\
541
 Bla Publisher}",
542
 number := "13",
543
 pages := "13{\\textendash}25",
544
 printedkey := "FS00",
545
 title := 
546
 "The {F}ritz package for the \n formula $x^y - l_{{i+1}} \
547
\\rightarrow \\mathbb{R}$",
548
 year := "2000" )
549
gap> Print(RecBibXMLEntry(e, "HTML", strs).note, "\n");
550
Online data at <a href="http://www.publish.com/~ImpJ/123#data">Bla Bla\
551
 Publisher</a>
552

553
554
7.3-8 AddHandlerBuildRecBibXMLEntry
555
556
AddHandlerBuildRecBibXMLEntry( elementname, restype, handler )  function
557
Returns: nothing
558
559
The argument elementname must be the name of an entry field supported by the
560
BibXMLext format, the name of one of the special elements "C", "M", "Math",
561
"URL" or of the form "Wrap:myname" or any string "mytype" (which then
562
corresponds to entry fields <other type="mytype">). The string "Finish" has
563
an exceptional meaning, see below.
564
565
restype is a string describing the result type for which the handler is
566
installed, see RecBibXMLEntry (7.3-7).
567
568
For both arguments, elementname and restype, it is also possible to give
569
lists of the described ones for installing several handler at once.
570
571
The argument handler must be a function with five arguments of the form
572
handler(entry, r, restype, strings, options). Here entry is a parse tree of
573
a BibXMLext <entry>-element, r is a node in this tree for an element
574
elementname, and restype, strings and options are as explained in
575
RecBibXMLEntry (7.3-7). The function should return a string representing the
576
content of the node r. If elementname is of the form "Wrap:myname" the
577
handler is used for elements of form <Wrap Name="myname">...</Wrap>.
578
579
If elementname is "Finish" the handler should look like above except that
580
now r is the record generated by RecBibXMLEntry (7.3-7) just before it is
581
returned. Here the handler should return nothing. It can be used to
582
manipulate the record r, for example for changing the encoding of the
583
strings or for adding some more components.
584
585
The installed handler is called by BuildRecBibXMLEntry(entry, r, restype,
586
strings, options). The string for the whole content of an element can be
587
generated by ContentBuildRecBibXMLEntry(entry, r, restype, strings,
588
options).
589
590
We continue the example from RecBibXMLEntry (7.3-7) and install a handler
591
for the <Wrap Name="Package">-element such that LaTeX puts its content in a
592
sans serif font.
593
594
 Example 
595
gap> AddHandlerBuildRecBibXMLEntry("Wrap:Package", "BibTeX",
596
> function(entry, r, restype, strings, options)
597
>  return Concatenation("\\textsf{", ContentBuildRecBibXMLEntry(
598
>  entry, r, restype, strings, options), "}");
599
> end);
600
gap> 
601
gap> Print(RecBibXMLEntry(e, "BibTeX", strs).title, "\n");
602
The \textsf{ {F}ritz} package for the 
603
 formula $x^y - l_{{i+1}} \rightarrow \mathbb{R}$
604
gap> Print(RecBibXMLEntry(e, "Text", strs).title, "\n"); 
605
The Fritz package for the 
606
 formula x^y - l_{i+1} → R
607
gap> AddHandlerBuildRecBibXMLEntry("Wrap:Package", "BibTeX", "Ignore");
608

609
610
7.3-9 StringBibXMLEntry
611
612
StringBibXMLEntry( entry[, restype][, strings][, options] )  function
613
Returns: a string
614
615
The arguments of this function have the same meaning as in RecBibXMLEntry
616
(7.3-7) but the return value is a string representing the bibliography entry
617
in a format specified by restype (default is "BibTeX").
618
619
Currently, the following cases for restype are supported:
620
621
"BibTeX"
622
A string with BibTeX source code is generated.
623
624
"Text"
625
A text representation of the text is returned. If options.ansi is
626
bound it must be a record. The components must have names Bib_Label,
627
Bib_author, and so on for all fieldnames. The value of each component
628
is a pair of strings which will enclose the content of the field in
629
the result or the first of these strings in which case the default for
630
the second is TextAttr.reset (see TextAttr (6.1-2)). If you give an
631
empty record here, some default ANSI color markup will be used.
632
633
"HTML"
634
An HTML representation of the bibliography entry is returned. The text
635
from each field is enclosed in markup (mostly <span>-elements) with
636
the class attribute set to the field name. This allows a detailed
637
layout of the code via a style sheet file. If options.MathJax is bound
638
and has the value true then formulae are encoded for display on pages
639
with MathJax support.
640
641
We use again the file shown in the example for ParseBibXMLextFiles (7.3-4).
642
643
 Example 
644
gap> bib := ParseBibXMLextFiles("doc/testbib.xml");;
645
gap> e := bib.entries[1];; strs := bib.strings;;
646
gap> ebib := StringBibXMLEntry(e, "BibTeX", strs);;
647
gap> PrintFormattedString(ebib);
648
@article{ AB2000,
649
 author = {First, F. A. and Sec{\H o}nd, X. Y.},
650
 title = {The {F}ritz package for the formula $x^y -
651
 l_{{i+1}} \rightarrow \mathbb{R}$},
652
 journal = {Important Journal},
653
 number = {13},
654
 year = {2000},
655
 pages = {13{\textendash}25},
656
 note = {Online data at \href
657
 {http://www.publish.com/~ImpJ/123#data} {Bla
658
 Bla Publisher}},
659
 mycomment = {very useful},
660
 printedkey = {FS00}
661
}
662
gap> etxt := StringBibXMLEntry(e, "Text", strs);; 
663
gap> etxt := SimplifiedUnicodeString(Unicode(etxt), "latin1", "single");;
664
gap> etxt := Encode(etxt, GAPInfo.TermEncoding);; 
665
gap> PrintFormattedString(etxt);
666
[FS00] First, F. A. and Second, X. Y., The Fritz package for the
667
formula x^y - l_{i+1} ? R, Important Journal, 13 (2000), 13-25,
668
(Online data at Bla Bla Publisher
669
(http://www.publish.com/~ImpJ/123#data)).
670
gap> ehtml := StringBibXMLEntry(e, "HTML", strs, rec(MathJax := true));;
671
gap> ehtml := Encode(Unicode(ehtml), GAPInfo.TermEncoding);;
672
gap> PrintFormattedString(ehtml);
673
<p class='BibEntry'>
674
[<span class='BibKey'>FS00</span>] 
675
 <b class='BibAuthor'>First, F. A. and Secőnd, X. Y.</b>,
676
 <i class='BibTitle'>The Fritz package for the 
677
 formula \(x^y - l_{{i+1}} \rightarrow \mathbb{R}\)</i>,
678
 <span class='BibJournal'>Important Journal</span> 
679
(<span class='BibNumber'>13</span>)
680
 (<span class='BibYear'>2000</span>),
681
 <span class='BibPages'>13–25</span><br />
682
(<span class='BibNote'>Online data at 
683
<a href="http://www.publish.com/~ImpJ/123#data">Bla Bla 
684
Publisher</a></span>).
685
</p>
686

687

688
689
The following command may be useful to generate completly new bibliography
690
entries in BibXMLext format. It also informs about the supported entry types
691
and field names.
692
693
7.3-10 TemplateBibXML
694
695
TemplateBibXML( [type] )  function
696
Returns: list of types or string
697
698
Without an argument this function returns a list of the supported entry
699
types in BibXMLext documents.
700
701
With an argument type of one of the supported types the function returns a
702
string which is a template for a corresponding BibXMLext entry. Optional
703
field elements have a * appended. If an element has the word OR appended,
704
then either this element or the next must/can be given, not both. If AND/OR
705
is appended then this and/or the next can/must be given. Elements which can
706
appear several times have a + appended. Places to fill are marked by an X.
707
708
 Example 
709
gap> TemplateBibXML();
710
[ "article", "book", "booklet", "conference", "inbook", 
711
 "incollection", "inproceedings", "manual", "mastersthesis", "misc", 
712
 "phdthesis", "proceedings", "techreport", "unpublished" ]
713
gap> Print(TemplateBibXML("inbook"));
714
<entry id="X"><inbook>
715
 <author>
716
 <name><first>X</first><last>X</last></name>+
717
 </author>OR
718
 <editor>
719
 <name><first>X</first><last>X</last></name>+
720
 </editor>
721
 <title>X</title>
722
 <chapter>X</chapter>AND/OR
723
 <pages>X</pages>
724
 <publisher>X</publisher>
725
 <year>X</year>
726
 <volume>X</volume>*OR
727
 <number>X</number>*
728
 <series>X</series>*
729
 <type>X</type>*
730
 <address>X</address>*
731
 <edition>X</edition>*
732
 <month>X</month>*
733
 <note>X</note>*
734
 <key>X</key>*
735
 <annotate>X</annotate>*
736
 <crossref>X</crossref>*
737
 <abstract>X</abstract>*
738
 <affiliation>X</affiliation>*
739
 <contents>X</contents>*
740
 <copyright>X</copyright>*
741
 <isbn>X</isbn>*OR
742
 <issn>X</issn>*
743
 <keywords>X</keywords>*
744
 <language>X</language>*
745
 <lccn>X</lccn>*
746
 <location>X</location>*
747
 <mrnumber>X</mrnumber>*
748
 <mrclass>X</mrclass>*
749
 <mrreviewer>X</mrreviewer>*
750
 <price>X</price>*
751
 <size>X</size>*
752
 <url>X</url>*
753
 <category>X</category>*
754
 <other type="X">X</other>*+
755
</inbook></entry>
756

757
758
759
7.4 Getting BibTeX entries from MathSciNet
760
761
We provide utilities to access the  MathSciNet
762
(http://www.ams.org/mathscinet/) data base from within GAP. One condition
763
for this to work is that the IO-package [Neu07] is available. The other is,
764
of course, that you use these functions from a computer which has access to
765
MathSciNet.
766
767
Please note, that the usual license for MathSciNet access does not allow for
768
automated searches in the database. Therefore, only use the SearchMR (7.4-1)
769
function for single queries, as you would do using your webbrowser.
770
771
7.4-1 SearchMR
772
773
SearchMR( qurec )  function
774
SearchMRBib( bib )  function
775
Returns: a list of strings, a string or fail
776
777
The first function SearchMR provides the same functionality as the Web
778
interface  MathSciNet (http://www.ams.org/mathscinet/). The query strings
779
must be given as a record, and the following components of this record are
780
recognized: Author, AuthorRelated, Title, ReviewText, Journal,
781
InstitutionCode, Series, MSCPrimSec, MSCPrimary, MRNumber, Anywhere,
782
References and Year.
783
784
Furthermore, the component type can be specified. It can be one of "bibtex"
785
(the default if not given), "pdf", "html" and probably others. In the last
786
cases the function returns a string with the correspondig PDF-file or web
787
page from MathSciNet. In the first case the MathSciNet interface returns a
788
web page with BibTeX entries, for convenience this function returns a list
789
of strings, each containing the BibTeX text for a single result entry.
790
791
The format of a .Year component can be either a four digit number,
792
optionally preceded by one of the characters '<', '>' or '=', or it can be
793
two four digit numbers separated by a - to specify a year range.
794
795
The function SearchMRBib gets a record of a parsed BibTeX entry as input as
796
returned by ParseBibFiles (7.1-1) or ParseBibStrings (7.1-1). It tries to
797
generate some sensible input from this information for SearchMR and calls
798
that function.
799
800
 Example 
801
gap> ll := SearchMR(rec(Author:="Gauss", Title:="Disquisitiones"));;
802
gap> ll2 := List(ll, HeuristicTranslationsLaTeX2XML.Apply);;
803
gap> bib := ParseBibStrings(Concatenation(ll2));;
804
gap> bibxml := List(bib[1], StringBibAsXMLext);;
805
gap> bib2 := ParseBibXMLextString(Concatenation(bibxml));;
806
gap> for b in bib2.entries do 
807
>  PrintFormattedString(StringBibXMLEntry(b, "Text")); od; 
808
[Gau95] Gauss, C. F., Disquisitiones arithmeticae, Academia
809
Colombiana de Ciencias Exactas, Físicas y Naturales, Bogotá,
810
Colección Enrique Pérez Arbeláez [Enrique Pérez Arbeláez
811
Collection], 10 (1995), xliv+495 pages, (Translated from the Latin
812
by Hugo Barrantes Campos, Michael Josephy and Ángel Ruiz Zúñiga,
813
With a preface by Ruiz Zúñiga).
814

815
[Gau86] Gauss, C. F., Disquisitiones arithmeticae, Springer-Verlag,
816
New York (1986), xx+472 pages, (Translated and with a preface by
817
Arthur A. Clarke, Revised by William C. Waterhouse, Cornelius
818
Greither and A. W. Grootendorst and with a preface by Waterhouse).
819

820
[Gau66] Gauss, C. F., Disquisitiones arithmeticae, Yale University
821
Press, New Haven, Conn.-London, Translated into English by Arthur A.
822
Clarke, S. J (1966), xx+472 pages.
823

824

825
826
827