Introduction
Вернуться к: Structures_BibTex
Introduction
This package provides methods to access information stored in a BibTex file. During parsing it is possible to let the data be validated. In addition. the creation of BibTex Strings as well as RTF Strings is also supported.
A few examples
Loading a BibTex File and printing the parsed array
<?php
require_once 'Structures/BibTex.php';
$bibtex = new Structures_BibTex();
$ret = $bibtex->loadFile('foo.bib');
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
$bibtex->parse();
echo '<pre>';
print_r($bibtex->data);
echo '</pre>';
?>
Options
Options can be set either in the constructor or with the method setOption(). When setting in the constructor the options are given in an associative array. The options are:
-
stripDelimiter (default: true) Stripping the delimiter surrounding the entries.
-
validate (default: true) Validation while parsing.
-
unwrap (default: false) Unwrapping entries while parsing.
-
wordWrapWidth (default: false) If set to a number higher one that the entries are wrapped after that amount of characters.
-
wordWrapBreak (default: \n) String used to break the line (attached to the line).
-
wordWrapCut (default: 0) If set to zero the line will we wrapped at the next possible space, if set to one the line will be wrapped exactly after the given amount of characters.
-
removeCurlyBraces (default: false) If set to true Curly Braces will be removed.
Setting options in the constructor
<?php
$bibtex = new Structures_BibTex(array('validate'=>false, 'unwrap'=>true));
?>
Example of setting options using the method setOption():
Setting options using setOption
<?php
$bibtex = new Structures_BibTex();
$bibtex->setOption('validate', false);
$bibtex->setOption('unwrap', true);
?>
Stored Data
The data is stored in the class variable data. This is a a list where each entry is a hash table representing one bibtex-entry. The keys of the hash table correspond to the keys used in bibtex and the values are the corresponding values. Some of these keys are:
-
cite - The key used in a LaTeX source to do the citing.
-
entryType - The type of the entry, like techreport, book and so on.
-
author - One or more authors of the entry. This entry is also a list with hash tables representing the authors as entries. The author has table is explained later.
-
title - Title of the entry.
Author
As described before the authors are stored in a list. Every entry representing one author as a has table. The hash table consits of four keys: first, von, last and jr. The keys are explained in the following list:
-
first - The first name of the author.
-
von - Some names have a 'von' part in their name. This is usually a sign of nobleness.
-
last - The last name of the author.
-
jr - Sometimes a author is the son of his father and has the same name, then the value would be jr. The same is true for the value sen but vice versa.
Adding an entry
To add an entry simply create a hash table with the needed keys and values and call the method addEntry().
Adding an entry
<?php
$bibtex = new Structures_BibTex();
$addarray = array();
$addarray['entryType'] = 'Article';
$addarray['cite'] = 'art2';
$addarray['title'] = 'Titel of the Article';
$addarray['author'][0]['first'] = 'John';
$addarray['author'][0]['last'] = 'Doe';
$addarray['author'][1]['first'] = 'Jane';
$addarray['author'][1]['last'] = 'Doe';
$bibtex->addEntry($addarray);
?>
Вернуться к: Structures_BibTex