A Lua custom writer for Pandoc generating JATS XML
Clone or download
Pull request Compare This branch is even with mjlassila:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



A Lua custom writer for Pandoc generating JATS XML - specifically Journal Publishing Tag Library NISO JATS Version 1.0.


Just download the file JATS.lua and put it in a convenient location. Pandoc includes a lua interpreter, so lua need not be installed separately. You need at least Pandoc version 1.13, released August 2014 (this release adds --template support for custom writers).


To convert the markdown file example1.md into the JATS XML file example1.xml, use the following command:

pandoc examples/example1.md --filter pandoc-citeproc -t jats.lua -o example1.xml --template=default.jats --bibliography=examples/example.bib --csl=jats.csl


pandoc-jats uses the template default.jats - the template uses the same format as other Pandoc templates (e.g. if/end conditions, for/end loops, and a dot can be used to select a field of a variable that takes an object), but is more complex because of the extensive metadata in JATS. Templates are parsed by Pandoc, not the custom Lua writer.

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Publishing DTD v1.0 20120330//EN"
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.0" article-type="$article.type$">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.0" article-type="other">
<journal-id journal-id-type="publisher-id">$journal.publisher-id$</journal-id>
<journal-id journal-id-type="nlm-ta">$journal.nlm-ta$</journal-id>
<journal-id journal-id-type="pmc">$journal.pmc$</journal-id>
<issn pub-type="ppub">$journal.pissn$</issn>
<issn pub-type="epub">$journal.eissn$</issn>
<article-id pub-id-type="publisher-id">$article.publisher-id$</article-id>
<article-id pub-id-type="doi">$article.doi$</article-id>
<article-id pub-id-type="pmid">$article.pmid$</article-id>
<article-id pub-id-type="pmcid">$article.pmcid$</article-id>
<article-id pub-id-type="art-access-id">$article.art-access-id$</article-id>
<subj-group subj-group-type="heading">
<subj-group subj-group-type="categories">
<contrib contrib-type="author">
<contrib-id contrib-id-type="orcid">$author.orcid$</contrib-id>
<xref ref-type="aff" rid="aff-$contrib.aff-id$"/>
<xref ref-type="corresp" rid="cor-$author.cor-id$"><sup>*</sup></xref>
<corresp id="cor-$article.author-notes.corresp.id$">* E-mail: <email>$article.author-notes.corresp.email$</email></corresp>
<fn fn-type="conflict"><p>$article.author-notes.conflict$</p></fn>
<fn fn-type="con"><p>$article.author-notes.con$</p></fn>
<pub-date pub-type="epub" iso-8601-date="$date.iso-8601$">
<pub-date pub-type="epub">
<license license-type="$copyright.type$" xlink:href="$copyright.link$">
<kwd-group kwd-group-type="author">

Citation Style (CSL)

pandoc-jats uses the jats.csl citation style that is included. This style generates XML in JATS format, which is an interim solution as CSL is not really intended to generate XML.


The metadata required for JATS can be stored in a YAML metadata block (new in Pandoc 1.12, the same format is also used by the Jekyll static blog generator. An example from a recent blog post is below:

layout: post
title: "What Can Article Level Metrics Do for You?"
date: 2013-10-22
tags: [example, markdown, article-level metrics, reproducibility]
bibliography: examples/example.bib
csl: examples/jats.csl
  type: research-article
  publisher-id: PBIOLOGY-D-13-03338
  doi: 10.1371/journal.pbio.1001687
  heading: Essay
  publisher-id: plos
  publisher-name: Public Library of Science
  publisher-loc: San Francisco, USA
  nlm-ta: PLoS Biol
  pmc: plosbiol
  title: PLoS Biology
  eissn: 1545-7885
  pissn: 1544-9173
 - surname: Fenner
   given-names: Martin
   orcid: http://orcid.org/0000-0003-1419-2405
   email: mfenner@plos.org
   corresp: true
  holder: Martin Fenner
  year: 2013
  text: "This is an open-access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited."
  type: open-access
  link: http://creativecommons.org/licenses/by/3.0/

The article and journal sections correspond to <article-meta> and <journal-meta> in JATS. The standard Pandoc metadata title, author and date are supported.


The JATS XML should be validated, for example with the excellent jats-conversion tools written by Alf Eaton.

To Do

  • supported for latest JATS version (1.1d3 in April 2015)
  • parsing for references in Lua instead of using a CSL style
  • more testing


This tool needs extensive testing with as many markdown documents as possible. Please open an issue in the Issue Tracker if you find a conversion problem.


You'll need busted and inspect to run tests (you might need to install luarocks first):

luarocks install busted
luarocks install inspect

Then run all tests from the root directory (the same directory as jats.lua):


The tests in spec/input_spec.lua are generic and can be reused for other custom Lua writers. They currently test whether all functions called by Pandoc exist. To run these tests against the sample.lua custom writer included with Pandoc, do busted spec/sample_spec.lua.


© 2013-2015 Martin Fenner. Released under the GPL, version 2 or greater. See LICENSE for more info.