digitalheir / bibtex-js Goto Github PK
View Code? Open in Web Editor NEWLibrary for parsing .bib files, used in Bibliography.js 📚
Home Page: https://digitalheir.github.io/bibtex-js/
License: MIT License
Library for parsing .bib files, used in Bibliography.js 📚
Home Page: https://digitalheir.github.io/bibtex-js/
License: MIT License
Also see #3
When sorting, BibTEX computes a string, named
sort.key$, for each entry. The sort.key$ string is an (often long) string defining the order
in which entries will be sorted. To avoid any ambiguity, sort.key$ should only contain alphanumeric
characters. Classical non-alphanumeric characters23, except special characters, will
be removed by a BibTEX function named purify$. For special characters, purify$ removes
spaces and LATEX commands (strings beginning with a backslash), even those placed between
brace pairs. Everything else is left unmodified. For instance, t^ete, t{^e}te and t{^{e}}te
are transformed into tete, while tête gives tête; Bib{\TeX} gives Bib and Bib\TeX becomes
BibTeX. There are thirteen LATEX commands that won’t follow the above rules: \OE, \ae, \AE,
\aa, \AA, \o, \O, \l, \L, \ss. Those commands correspond to ı, , œ, Œ, æ, Æ, å, Å, ø, Ø, ł, Ł,
ß, and purify$ transforms them (if they are in a special character, in i, j, oe, OE, ae, AE, aa,
AA, o, O, l, L, ss, respectively.
Needs helper functions, see #1, #2, #3.
We’ll need several definitions before going further. The brace depth of an item is the number of
braces surrounding it. This is not a very formal definition, but for instance, in the title above, \LaTeX
has brace depth 2, the C has brace depth 1, and everything else has depth 0. A special character is a
part of a field starting with a left brace being at brace depth 0 immediately followed with a backslash,
and ending with the corresponding right brace. For instance, in the above example, there is no special
character, since \LaTeX is at depth 2. It should be noticed that anything in a special character is
considered as being at brace depth 0, even if it is placed between another pair of braces.
That’s it for the definitions. Generally speaking, several modifications can be applied to the title
by the bibliography style:
• first of all, the title might be used for sorting. When sorting, BibTEX computes a string, named
sort.key$, for each entry. The sort.key$ string is an (often long) string defining the order
in which entries will be sorted. To avoid any ambiguity, sort.key$ should only contain alphanumeric
characters. Classical non-alphanumeric characters23, except special characters, will
be removed by a BibTEX function named purify$. For special characters, purify$ removes
spaces and LATEX commands (strings beginning with a backslash), even those placed between
brace pairs. Everything else is left unmodified. For instance, t^ete, t{^e}te and t{^{e}}te
are transformed into tete, while tête gives tête; Bib{\TeX} gives Bib and Bib\TeX becomes
BibTeX. There are thirteen LATEX commands that won’t follow the above rules: \OE, \ae, \AE,
\aa, \AA, \o, \O, \l, \L, \ss. Those commands correspond to ı, , œ, Œ, æ, Æ, å, Å, ø, Ø, ł, Ł,
ß, and purify$ transforms them (if they are in a special character, in i, j, oe, OE, ae, AE, aa,
AA, o, O, l, L, ss, respectively.
• the second transformation applied to a title is to be turned to lower case (except the first character).
The function named change.case$ does this job. But it only applies to letters that are
a brace depth 0, except within a special character. In a special character, brace depth is always
0, and letters are switched to lower case, except LATEX commands, that are left unmodified.
Hello,
I would like to try out the library but have two concerns.
<script src="downloadedFile.js"></script>
but I do not know how (under which name) to access the functions then. Can it be used with requirejs?bibtex-js$ tsc src/index.ts
src/bibfile/bib-entry/BibEntry.ts(68,34): error TS2322: Type 'FieldValue' is not assignable to type 'Authors'.
Type 'number' is not assignable to type 'Authors'.
src/bibfile/bib-entry/BibStringEntry.ts(107,16): error TS2339: Property 'assign' does not exist on type 'ObjectConstructor'.
src/lexer/Lexer.ts(112,35): error TS2339: Property 'parseInt' does not exist on type 'NumberConstructor'.
src/lexer/Lexer.ts(113,27): error TS2339: Property 'isFinite' does not exist on type 'NumberConstructor'.
bibtex-js$ tsc --version
Version 2.6.1
PS: The npm installed precompiled version seems to work so far, however I wanted to modify it, since I do not want string fields to resolved. I want to read a bibfile, check some things and write it again, with cleaned up formatting to my chosing. I tested "bibclean" and "biber output_format bibtex" which both do not suffide, so I wanted to do my own and looked around for a .js library that can read bibtex files, bevor i have to write yet another parser.
the second transformation applied to a title is to be turned to lower case (except the first character).
The function named change.case$ does this job. But it only applies to letters that are
a brace depth 0, except within a special character. In a special character, brace depth is always
0, and letters are switched to lower case, except LATEX commands, that are left unmodified.
The first point to notice is that two authors are separated with the keyword and. The format of the
names is the second important point: The last name first, then the first name, with a separating
comma. In fact, BibTEX understands other formats.
Before going further, we remark an important point: BibTEX will have to guess which part is the
first name and which part is the last name. It also has to distinguish a possible “von” part (as in John
von Neumann) and a possible “Jr” part.
The following explanation is somewhat technical. The first name will be called First, the last
name is denoted by Last, the “von” with von and the “Jr” part, Jr.
So, BibTEX must be able to distinguish between the different parts of the author field. To that
aim, BibTEX recognizes three possible formats:
• First von Last;
• von Last, First;
• von Last, Jr, First.
Classical non-alphanumeric characters23, except special characters, will
be removed by a BibTEX function named purify$. For special characters, purify$ removes
spaces and LATEX commands (strings beginning with a backslash), even those placed between
brace pairs. Everything else is left unmodified. For instance, t^ete, t{^e}te and t{^{e}}te
are transformed into tete, while tête gives tête; Bib{\TeX} gives Bib and Bib\TeX becomes
BibTeX. There are thirteen LATEX commands that won’t follow the above rules: \OE, \ae, \AE,
\aa, \AA, \o, \O, \l, \L, \ss. Those commands correspond to ı, , œ, Œ, æ, Æ, å, Å, ø, Ø, ł, Ł,
ß, and purify$ transforms them (if they are in a special character, in i, j, oe, OE, ae, AE, aa,
AA, o, O, l, L, ss, respectively.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.