Semantic MediaWiki has a bibtex export format, provided in the Semantic Results Format extension (https://www.semantic-mediawiki.org/wiki/Help:BibTeX_format). I think it would be nice to include such a format in Cargo too.
I have made a patch where I added 2 export formats, namely:
- bibtex
- bibtex export
The bibtex format prints directly the bibtex entries on the page (using HTML). The bibtex export format is intended for exporting the data, it creates a link to download the bibtex entries on a file, or to see them in a new tab.
An exemplary query (in this for publications in conferences) is the following:
{{#cargo_query: tables=conference_publications |fields= bibtex_title=title, bibtex_author=author, conference=booktitle, start_date=date, doi, initial_page=initialpage, last_page=lastpage, CONCAT(city, ", ", country)=address |order by=start_date DESC |format=bibtex export |default entry type=inproceedings }}
As shown in the example, the fields queried must be named with a specific field alias, most of the aliases are the ones accepted by the bibtex format, but we also define some additional ones. The full list of fields accepted by the bibtex format is the following:
address, annote, author, booktitle, chapter, crossref, doi, edition, editor, howpublished, institution, journal, key, month, note, number, organization, pages, publisher, school, series, title, type, volume, year
A description for each field can be seen on the wikipedia page (https://en.wikipedia.org/wiki/BibTeX#Field_types).
In the case of the author and editor fields, a list of names (in bibtex format) separated by 'and' must be given. For these cases, if the type of the cargo data is a list of values, the code takes care of constructing the list with the 'and' separator. If the type of the cargo data is not a list, then the value is used directly.
additionaly, the following extra special aliases are also available:
- bibtexkey The name of the bibtex entry, if not specified or empty the name of the entry will be generated from the authors, the title and the year data.
- date Date of the publication. This will be converted to the year and month fields in the bibtex entry.
- entrytype Type of the bibtex entry, e.g., article, book, booklet, etc. The full list of available types can be seen in https://en.wikipedia.org/wiki/BibTeX#Entry_types. However, note that the code does not check if the field values are valid entry types, it just takes the values directly. If not specified or if the value is empty, the entry type will be set to the one specified in the default entry type option (see below for the description of this option). If default entry type is not spefied then the entry type will be set to article.
- initialpage and endpage Indicate the initial and end pages, respectively. Can be used instead of the pages alias.
Additional allowed parameters for both formats are:
- default entry type The default type of the bibtex entries, e.g., article, book, booklet, etc. If not specified the default will be set to article.
- plain text This must be 1 to output a plain text result (no HTML), and 0 to output a result in HTML format. For the bibtex format the default is 0 (HTML is created), and for the bibtex export format the default is 1 (plain text is created). Originally I had called this option no html, but I changed the name because the semantic and inner working is different from the no html Cargo option.
The bibtex export format also allows the following parameters:
- link text Sets the text of the link (default is "View BibTeX", or the value at the page MediaWiki:cargo-viewbibtex)
- export as file Sets the way of exporting the data. It set to 1, the results will be downloaded on a file, if set to 0, the results will be shown on a new tab. The default is 0.
- filename Sets the name of the file that is downloaded (default is "results.bib")
As an example, the query shown as example above would produce a list of entries like the following:
@inproceedings{dominguez2017throughput, title={Throughput-Based Performance Evaluation of 5G-Candidate Waveforms in High Speed Scenarios}, author={Tom\'as Dom\'inguez-Bola{\~n}o and Jos\'e Rodr\'iguez-Pi{\~n}eiro and Jos\'e A. Garc\'ia-Naya and Castedo, Luis}, address={Kos, Greece}, booktitle={25th European Signal Processing Conference (EUSIPCO 2017)}, doi={10.23919/EUSIPCO.2017.8081280}, pages={643--647}, year={2017}, month=aug, }
The key of the entry is generated from the authors, the title and the year data, since no bibtexkey field is provided in the query. The format of this key is the same as in the citations from Google Scholar, i.e., <Last name><Year><First word of title>. When generating the key, the code removes all non alphabetical characters from the Last name and the first word of the title.