Download the PHP package renanbr/bibtex-parser without Composer
On this page you can find all versions of the php package renanbr/bibtex-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bibtex-parser
PHP BibTeX Parser 2.x
This is a BibTeX parser written in PHP.
You are browsing the documentation of BibTeX Parser 2.x, the latest version.
Table of contents
- Installing
- Usage
- Vocabulary
- Processors
- Tag name case
- Authors and editors
- Keywords
- Date
- Fill missing tag
- Trim tags
- Determine URL from the DOI
- LaTeX to unicode
- Custom
- Handling errors
- Advanced usage
- Release Policy
- Dependencies Compatibility Policy
Installing
Usage
This will output:
Vocabulary
BibTeX is all about "entry", "tag's name" and "tag's content".
A BibTeX entry consists of the type (the word after @), a citation-key and a number of tags which define various characteristics of the specific BibTeX entry. (...) A BibTeX tag is specified by its name followed by an equals sign, and the content.
Source: http://www.bibtex.org/Format/
Note: This library considers "type" and "citation-key" as tags. This behavior can be changed implementing your own Listener.
Processors
Processor is a callable that receives an entry as argument and returns a modified entry.
This library contains three main parts:
Parserclass, responsible for detecting units inside a BibTeX input;Listenerclass, responsible for gathering units and transforming them into a list of entries;Processorclasses, responsible for manipulating entries.
Despite you can't configure the Parser, you can append as many Processor as you want to the Listener through Listener::addProcessor() before exporting the contents.
Be aware that Listener provides, by default, these features:
- Found entries are reachable through
Listener::export()method; - Tag content concatenation;
- e.g.
hello # " world"tag's content will generatehello worldstring
- e.g.
- Tag content abbreviation handling;
- e.g.
@string{foo="bar"} @misc{bar=foo}will make$entries[1]['bar']assumebaras value
- e.g.
- Publication's type exposed as
_typetag; - Citation key exposed as
citation-keytag; - Original entry text exposed as
_originaltag.
This project ships some useful processors.
Tag name case
In BibTeX the tag's names aren't case-sensitive.
This library exposes entries as array, in which keys are case-sensitive.
To avoid this misunderstanding, you can force the tags' name character case using TagNameCaseProcessor.
Usage
Authors and editors
BibTeX recognizes four parts of an author's name: First Von Last Jr.
If you would like to parse the author and editor tags included in your entries, you can use the NamesProcessor class.
Usage
Keywords
The keywords tag contains a list of expressions represented as string, you might want to read them as an array instead.
Usage
Date
It adds a new tag _date as DateTimeImmutable.
This processor adds the new tag if and only if this the tags month and year are fulfilled.
Usage
Fill missing tag
It puts a default value to some missing field.
Usage
Trim tags
Apply trim() to all tags.
Usage
Determine URL from the DOI
Sets url tag with DOI if doi tag is present and url tag is missing.
Usage
LaTeX to unicode
BibTeX files store LaTeX contents.
You might want to read them as unicode instead.
The LatexToUnicodeProcessor class solves this problem, but before adding the processor to the listener you must:
- install Pandoc in your system; and
- add ryakad/pandoc-php or ueberdosis/pandoc as a dependency of your project.
Usage
Note: Order matters, add this processor as the last.
Custom
The Listener::addProcessor() method expects a callable as argument.
In the example shown below, we append the text with laser to the title tags for all entries.
Usage
Handling errors
This library throws two types of exception: ParserException and ProcessorException.
The first one may happen during the data extraction.
When it occurs it probably means the parsed BibTeX isn't valid.
The second exception may happen during the data processing.
When it occurs it means the listener's processors can't handle properly the data found.
Both implement ExceptionInterface.
Advanced usage
The core of this library contains these main classes:
RenanBr\BibTexParser\Parserresponsible for detecting units inside a BibTeX input;RenanBr\BibTexParser\ListenerInterfaceresponsible for treating units found.
You can attach listeners to the parser through Parser::addListener().
The parser is able to detect BibTeX units, such as "type", "tag's name", "tag's content".
As the parser finds a unit, it triggers the listeners attached to it.
You can code your own listener! All you have to do is handle units.
$type may assume one of these values:
Parser::TYPEParser::CITATION_KEYParser::TAG_NAMEParser::RAW_TAG_CONTENTParser::BRACED_TAG_CONTENTParser::QUOTED_TAG_CONTENTParser::ENTRY
$context is an array with these keys:
offsetcontains the$text's beginning position. It may be useful, for example, to seek on a file pointer;lengthcontains the original$text's length. It may differ from string length sent to the listener because may there are escaped characters.
Release Policy
There is a single maintained branch per time. This branch targets a minor version.
A maintained version reaches its end-of-life when a new minor version is released.
Dependencies Compatibility Policy
This library is compatible with maintained versions of PHP.