GithubHelp home page GithubHelp logo

bib2sx's Introduction

bib2sx

bib2sx is a command-line tool (written in Racket) for parsing BibTeX files (by default) into S-Expressions.

It captures the (potentially recursive) structure of quoting in BibTeX, which is is important for capitalization.

It also supports outputing to JSON, XML and (back to canonicalized) BibTeX.

A blog post explaining bib2sx covers the tool in much more detail.

It will parse name fields (author, editor) into first, von, last and jr with --parse-names.

Dependencies

You will need an installation of the Racket programming language.

Building

To build bib2sx, run make.

Installation

To install to ~/bin/, run make install.

Usage

$ bib2sx [ --inline ] [ --flatten ] [ --parse-names ] [ --texenize ]
         [ --in sx|bib ] [ --out sx|bib|json|xml ]
         [ --json | --bib | --xml ]
         [ <input-file> ]

where:

  • --inline will expand variables into definitions from @string
  • --flatten will convert values into properly-quoted BibTeX strings
  • --parse-names will parse names according to BibTeX's rules
  • --texenize will tokenize values into lexemes meaningful to TeX
  • --in <format> will set the input format: sx or bib allowed; bib is default
  • --out <format> will set the output format; sx, bib, json, or xml allowed; sx is default
  • --json will output JSON; same as --out json
  • --bib will output canonicalized BibTeX; same as --out bib
  • --xml will output XML; same as --out xml

TeXenizing

If you want to render the output in a format other than LaTeX (such as HTML), you will need to interpret the TeX.

To make this easier, the --texenize flag will parse a value into lexemes meaningful to LaTeX.

For instance, \foo{bar} will become "\foo" '("b" "a" "r").

License

bib2sx: A bibtex parser and transformer

Copyright (©) 2015 Matthew Might

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

bib2sx's People

Contributors

mattmight avatar mn200 avatar zapster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bib2sx's Issues

@preamble

Hi,

This tool looks quite useful, but I ran into an error. I often use @preamble{"\providecommand{\baptiste}{First, Last}"} in my bib files, and have entries such as

@article{dummy,
	Author = {\baptiste and Other People},
	Journal = {Journal of things},
	Number = {1},
	Pages = {00000},
	Title = {Some title},
	Volume = {10},
	Year = {2016}}

I find it convenient because I can override the definition in a TeX file, e.g. to make my name bold,

\newcommand{\baptiste}{\textbf{First Last}}

@string seems more limited in scope and doesn't really allow this sort of partial transformation.

Parse error

This:

@inproceedings{wasserrab-nst-OOPSLA06,
  author={Daniel Wasserrab and Tobias Nipkow and Gregor Snelting and Frank Tip},
  title={An Operational Semantics and Type Safety Proof for Multiple
         Inheritance in {C}++},
  booktitle={{OOPSLA} '06: Object oriented programming, systems, languages,
             and applications},
  publisher={ACM Press},
  year=2006
}

causes

parsing error: #t { #f
  context...:
   /Applications/Racket v6.1.1/share/pkgs/parser-tools-lib/parser-tools/yacc.rkt:337:16: parsing-loop
   #%mzc:bib2sx: [running body]
   loop

It could be the above really is malformed, though I can't see why if so.

parse-names on embedded backslash commands

The following input

@inproceedings{foo,
  author    = {Rastislav Bod{\'{\i}}k},
  title     = {Some Test}
}

and command bib2sx --parse-names fails with a parse error. If you remove the outer braces to turn the last name into Bod\'{\i}k, then the parser splits the name into

  (author (name (first "Rastislav" " " "Bod\\'") (von) (last '"\\i" "k") (jr)))

which is wrong.

If you change it to Bod{\'\i}k, you get

  (author (name (first "Rastislav" " " "Bod") (von) (last '"\\'\\i" "k") (jr)))

The form with two sets of braces comes from a DBLP record; I don't know if it, or any of the others, is correct BibTeX.

Convert JSON back to BibTeX

It looks like this tool can convert BibTeX to JSON, but it would be great if it could convert that JSON back to BibTeX.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.