Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference management with HTML/CSS/Javascript (BibTeX style)

HTML+CSS+Javascript tools offer a great way to create beautiful presentations (e.g. reveal.js + MathJax). However, I usually need to add citations to my presentations, and I would like to do that in a systematic way (so the bibliography is organized and the references are well-formatted). This is something that get's handled quite easily in LaTeX through BibTeX.

The best solution I've found so far comes from a library called bibtex-js. It seems to do a good job on rendering BiBTeX files in HTML as a bibliography listing, which is partially what I want. However, I don't only need to render bibliography listings, but also, I need to refer to entries in that bibliography by some index, and get a uniformly formatted reference marker. Take, for example, how LaTeX usually handles this problem:

%In thebibliography.bib
@article{darwin1859origins,
  title={On the origins of species by means of natural selection},
  author={Darwin, Charles},
  journal={London: Murray},
  year={1859}
}

%In mydocument.tex
As \cite{darwin1859origins} sustains in his ground-breaking book...

The previous code would be rendered as something like "As Darwin(1859) sustains in his ground-breaking book". Moreover, the formatting in which the citation is rendered could also be customizable (e.g. "Darwin,1859", "(Darwing,1859)", "[DWN59]", "[1]", etc.).

So the question is, how do you handle a similar task on a HTML document?

Thank you all in advance!

like image 965
GermanK Avatar asked Oct 01 '13 09:10

GermanK


2 Answers

Yes, there is an emacs extension called org-mode, which is text processing with a markdown like syntax. This can export to reveal-js trough this: https://github.com/yjwen/org-reveal Or in my case I use the spacemacs extension: https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bemacs/org#revealjs-support

So org mode is an intermediate format that compiles to whatever you want, ie reveal-js, html, or even latex. This includes a reference management system: https://github.com/jkitchin/org-ref

I'm unhappy with this for reveal.js, if we use this with reveal.js we end up having all the citation being presented as the link (whatever we type after cite:) and the full format citations are grouped on whatever slide you place them (so if you have more than 3 you can't read it correctly, although I guess its in the HTML). What I want is either the numbers I get in latex or footnote based citations, because in case of slides footnotes work kind off good.

This will of course work for just HTML pages, however you probably want to have presentations like me. I was searching for a solution for this when I stumbled upon this unanswered question so I guess here is your answer.

like image 153
Jappie Kerk Avatar answered Sep 19 '22 01:09

Jappie Kerk


I made a project, incidentally also called bibtex-js. Available on npm.

I made it because most BibTeX parsers out there take considerable shortcuts in parsing. This one aligns closely with the authoritative document on BibTeX, Tame the BeaST and so works pretty well in terms of references and parsing author names, which seems what you are after.

I would say, based on some bibliographic standard, roll your own inline citation function:

import {parseBibFile, normalizeFieldValue} from "bibtex";

// Parse bib file
const bibFile = parseBibFile(bibtexString); // insert the darwin1859origins example as a string

// Sanity check: print all ids of entries in the bibfile
console.log(Object.keys(bibFile.entries$)); 

// Get the entry we are after
const entry = bibFile.getEntry("darwin1859origins");

// Get the relevant fields

// normalizeFieldValue turns a BibTeX string into a Javascript string
const year = normalizeFieldValue(entry.getField("year")); 
// get first author
// "author" is a special kind of BibTeX field
const author = entry.getField("author").authors$[0]; 

function inlineCite(author){
   return "("
          + (author.firstNames
                .concat(author.vons)
                .concat(author.lastNames)
                .concat(author.jrs)).join(" ")
          + "," + year
        + ")";
}

console.log(inlineCite(author)); // (Charles Darwin, 1859)

You can do something complicated with et al. if you have multiple authors.

like image 28
Maarten Avatar answered Sep 23 '22 01:09

Maarten