diff --git a/BSD3.md b/BSD3.md
deleted file mode 100644
--- a/BSD3.md
+++ /dev/null
@@ -1,30 +0,0 @@
-data-accessor
--------------
-
-Copyright (c) Henning Thielemann <haskell@henning-thielemann.de>, Luke Palmer <lrpalmer@gmail.com>.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this
-  list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice,
-  this list of conditions and the following disclaimer in the documentation
-  and/or other materials provided with the distribution.
-
-* Neither the name of data-accessor nor the names of its
-  contributors may be used to endorse or promote products derived from
-  this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
deleted file mode 100644
--- a/README.md
+++ /dev/null
@@ -1,570 +0,0 @@
-# pandoc-crossref filter [![Build Status](https://travis-ci.org/lierdakil/pandoc-crossref.svg?branch=master)](https://travis-ci.org/lierdakil/pandoc-crossref) [![Build status](https://ci.appveyor.com/api/projects/status/v04mfbglpcdqfln4/branch/master?svg=true)](https://ci.appveyor.com/project/lierdakil/pandoc-crossref/branch/master)
-
-pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
-
-Input file (like [demo.md][demo-md]) can be converted into [html][html], [latex][latex], [pdf][pdf], [md][md] or other formats.
-
-Optionally, you can use cleveref for latex/pdf output, e.g. [cleveref pdf][cpdf], [cleveref latex][clatex], and listings package, e.g. [listings pdf][lpdf], [listings latex][llatex]
-
-You can also enable per-chapter numbering (as with `--chapters` for latex output). You need to specify `-M chapters` for non-latex/pdf output however. Examples: [html][chap-html], [markdown][chap-markdown], [latex][chap-latex], [pdf][chap-pdf].
-
-[demo-md]: https://raw.githubusercontent.com/lierdakil/pandoc-crossref/gh-pages/demo.md
-[html]: http://lierdakil.github.io/pandoc-crossref/output.html
-[latex]: http://lierdakil.github.io/pandoc-crossref/output.latex
-[pdf]: http://lierdakil.github.io/pandoc-crossref/output.pdf
-[md]: http://lierdakil.github.io/pandoc-crossref/output.md
-[chap-html]: http://lierdakil.github.io/pandoc-crossref/output-chapters.html
-[chap-latex]:http://lierdakil.github.io/pandoc-crossref/output-chapters.latex
-[chap-markdown]:http://lierdakil.github.io/pandoc-crossref/output-chapters.md
-[chap-pdf]:http://lierdakil.github.io/pandoc-crossref/output-chapters.pdf
-[clatex]: http://lierdakil.github.io/pandoc-crossref/output-cref.latex
-[cpdf]: http://lierdakil.github.io/pandoc-crossref/output-cref.pdf
-[llatex]: http://lierdakil.github.io/pandoc-crossref/output-listings.latex
-[lpdf]: http://lierdakil.github.io/pandoc-crossref/output-listings.pdf
-
-
-This work is inspired by [pandoc-fignos][1] and [pandoc-eqnos][2] by @tomduck.
-
-[1]: https://github.com/tomduck/pandoc-fignos
-[2]: https://github.com/tomduck/pandoc-eqnos
-
-This package tries to use latex labels and references if output type is LaTeX. It also tries to supplement rudimentary LaTeX configuration that should mimic metadata configuration by setting `header-includes` variable.
-
-## Caveats
-
-### LaTeX output and `--include-in-header`
-
-pandoc-crossref uses metadata variable `header-includes` to add LaTeX definitions to output. However, Pandoc's command line option `--include-in-header`/`-H` overrides this variable. If you need to use `--include-in-header`, add pandoc-crossref-specific definitions as well. See [LaTeX customization](#latex-customization) for more information.
-
-### pandoc-citeproc and pandoc-crossref
-
-Since pandoc-crossref uses the same citation syntax as pandoc-citeproc, you *have* to run former *before* latter. For example:
-
-```
-pandoc -F pandoc-crossref -F pandoc-citeproc file.md -o file.html
-```
-
-### Note on leading/trailing spaces in metadata options
-
-Leading and trailing spaces in YAML metadata will most likely be stripped by either YAML parser or Pandoc itself. If you need leading and/or trailing spaces in pandoc-crossref metadata variables, use html entity for space instead, i.e. `&#32;`. For example, if you want reference ranges to be delimited by a dash with spaces (e.g. `2 - 5`), include the following in YAML metadata:
-
-```yaml
-rangeDelim: '&#32;-&#32;'
-```
-
-or pass `-MrangeDelim='&#32;-&#32;'` to pandoc on command line.
-
-You can use other html entites of course, like `&nbsp;` etc.
-
-## Syntax
-
-Syntax is loosely based on discussion in <https://github.com/jgm/pandoc/issues/813>
-
-### Image labels
-
-```markdown
-![Caption](file.ext){#fig:label}
-```
-
-To label an (implicit) figure, append `{#fig:label}` (with `label` being something unique to reference this figure by) immediately after image definition.
-
-This only works on implicit figures, i.e. an image occurring by itself in a paragraph (which will be rendered as a figure with caption by pandoc)
-
-Image block and label *can not* be separated by spaces.
-
-#### Subfigures
-
-It's possible to group figures as subfigures. Basic syntax is as follows:
-
-```markdown
-<div id="fig:figureRef">
-![subfigure 1 caption](image1.png){#fig:figureRefA}
-
-![subfigure 2 caption](image2.png){#fig:figureRefB}
-
-Caption of figure
-</div>
-```
-
-To sum up, subfigures are made with a div having a figure `id`. Contents of said div consist of several paragraphs. All but last paragraphs contain one subfigure each, with captions, images and (optionally) reference attributes. Last paragraph contains figure caption.
-
-If you put more than one figure in the paragraph, those will still be rendered, but Pandoc will omit subfigure caption in most outputs (but it will work as expected with LaTeX). You can use output-specific hacks to work around that, or use `subfigGrid` (see below).
-
-Output is customizable, with metadata fields. See [Customization](#customization) for more information.
-
-Default settings will produce the following equivalent Markdown from example above:
-
-```markdown
-<div id="fig:figureRef" class="subfigures">
-
-![a](image1.png){#fig:figureRefA}
-
-![b](image2.png){#fig:figureRefB}
-
-Figure 1: Caption of figure. a — subfigure 1 caption, b — subfigure 2
-caption
-
-</div>
-```
-
-References to subfigures will be rendered as `figureNumber (subfigureNumber)`, e.g., in this particular example, `[@fig:figureRefA]` will produce `fig. 1 (a)`.
-
-You can add `nocaption` class to an image to suppress subfigure caption altogether. Note that it will still be counted.
-
-##### Subfigure grid
-
-If you need to align subfigures in a grid, and using output format styles is not an option, you can use `subfigGrid` option. That will typeset subfigures inside a table.
-
-Rows are formed by different paragraphs, with each image in a separate column.
-
-Column widths will be taken from `width` attributes of corresponding images, e.g.
-
-```markdown
-<div id="fig:coolFig">
-![caption a](coolfiga.png){#fig:cfa width=30%}
-![caption b](coolfigb.png){#fig:cfb width=60%}
-![caption c](coolfigb.png){#fig:cfc width=10%}
-
-![caption d](coolfigd.png){#fig:cfd}
-![caption e](coolfige.png){#fig:cfe}
-![caption f](coolfigf.png){#fig:cff}
-
-Cool figure!
-</div>
-```
-
-will produce a table with columns of 30%, 60% and 10% respectively.
-
-Only first row of images is considered for table width computation, other rows are completely ignored.
-
-*Anything* except images is silently ignored. So any text, spaces, soft line breaks etc will silently disappear from output. That doesn't apply to caption paragraph, obviously.
-
-All images will have width attribute automatically set to `100%` in order to fill whole column.
-
-Specifying width in anything but `%` will throw an error.
-
-If width for some images in first row is not specified, those will span equally in the remaining space.
-
-If width isn't specified for any image in first row, those will span equally on 99% of page width (due to Pandoc otherwise omitting width attribute for table).
-
-This option is ignored with LaTeX output, but paragraph breaks should produce similar effect, so images should be typeset correctly. TL;DR you don't need `subfigGrid` enabled for it to work with LaTeX, but you can still enable it.
-
-### Equation labels
-
-```markdown
-$$ math $$ {#eq:label}
-```
-
-To label a display equation, append `{#eq:label}` (with `label` being something unique to reference this equation by) immediately after math block.
-
-Math block and label *can* be separated by one or more spaces.
-
-You can also number all display equations with `autoEqnLabels` metadata setting (see below). Note, however, that you won't be able to reference equations without explicit labels.
-
-Equations numbers will be typeset inside math with `\qquad` before them. If you want to use tables instead, use `tableEqns` option.  Depending on output format, tables might work better or worse than `\qquad`.
-
-### Table labels
-
-```markdown
-a   b   c
---- --- ---
-1   2   3
-4   5   6
-
-: Caption {#tbl:label}
-```
-
-To label a table, append `{#tbl:label}` at the end of table caption (with `label` being something unique to reference this table by). Caption and label *must* be separated by at least one space.
-
-### Section labels
-
-You can also reference sections of any level. Section labels use native pandoc syntax, but must start with "sec:", e.g.
-
-```markdown
-# Section {#sec:section}
-```
-
-You can also use `autoSectionLabels` variable to automatically prepend all section labels (automatically generated with pandoc included) with "sec:". Bear in mind that references can't contain periods, commas etc, so some auto-generated labels will still be unusable.
-
-WARNING: With LaTeX output, you have to invoke pandoc with `--number-sections`, otherwise section labels won't work. It's also advised with other output formats, since with no numbers in section titles, it would be hard to navigate anyway.
-
-#### Section numbering
-
-Pandoc doesn't properly support numbering sections in some output formats, and section reference labels (see below).
-
-You can let pandoc-crossref handle section numbering instedad. This is done via `numberSections` and `sectionsDepth` metadata options.
-
-`numberSections` controls if pandoc-crossref handles numbering sections, while `sectionsDepth` controls what sections are numbered.
-
-Set `sectionsDepth` to `0` to make section numbering consistent with `chaptersDepth`.
-
-If `sectionsDepth` value is lesser than `0`, all sections will be numbered.
-
-Otherwise, only header levels up to and including `sectionsDepth` will be numbered.
-
-### Section reference labels
-
-***Not currently supported with LaTeX output***
-
-If you want to reference some section by a pre-defined label instead of by number, you can specify section attribute `label`, like this:
-
-```markdown
-# Section {label="Custom Label"}
-```
-
-This label will be used instead of section number in `chapters` output and when referencing section directly (with `@sec:section`).
-
-Note that with `chapters` output with depth>1, only given section will be referenced by custom label, e.g. with
-
-```markdown
-# Chapter 1.
-
-## Section with custom label {#sec:scl label="SCL"}
-
-![](figure.png){#fig:figure}
-```
-
-`@sec:scl` will translate into `sec. 1.SCL`, and `@fig:figure` into `fig. 1.SCL.1`
-
-### Code Block labels
-
-There are a couple options to add code block labels. Those work only if code block id starts with `lst:`, e.g. `{#lst:label}`
-
-#### `caption` attribute
-
-`caption` attribute will be treated as code block caption. If code block has both id and `caption` attributes, it will be treated as numbered code block.
-
-<pre>
-```{#lst:code .haskell caption="Listing caption"}
-main :: IO ()
-main = putStrLn "Hello World!"
-```
-</pre>
-
-#### Table-style captions
-
-Enabled with `codeBlockCaptions` metadata option. If code block is immediately
-adjacent to paragraph, starting with `Listing: ` or `: `, said paragraph will be
-treated as code block caption.
-
-<pre>
-Listing: Listing caption
-
-```{#lst:code .haskell}
-main :: IO ()
-main = putStrLn "Hello World!"
-```
-</pre>
-
-or
-
-<pre>
-```{#lst:code .haskell}
-main :: IO ()
-main = putStrLn "Hello World!"
-```
-
-: Listing caption
-</pre>
-
-#### Wrapping div
-
-Wrapping code block without label in a div with id `lst:...` and class, starting with `listing`, and adding paragraph before code block, but inside div, will treat said paragraph as code block caption.
-
-<pre>
-&lt;div id="lst:code" class="listing"&gt;
-Listing caption
-```{.haskell}
-main :: IO ()
-main = putStrLn "Hello World!"
-```
-&lt;/div&gt;
-</pre>
-
-### References
-
-```markdown
-[@fig:label1;@fig:label2;...] or [@eq:label1;@eq:label2;...] or [@tbl:label1;@tbl:label2;...] or @fig:label or @eq:label or @tbl:label
-```
-
-Reference syntax heavily relies on citation syntax. Basic reference is created by writing `@`, then basically desired label with prefix. It is also possible to reference a group of objects, by putting them into brackets with `;` as separator. Similar objects will be grouped in order of them appearing in citation brackets, and sequential reference numbers will be shortened, e.g. `1,2,3` will be shortened to `1-3`.
-
-You can capitalize first reference character to get capitalized prefix, e.g. `[@Fig:label1]` will produce `Fig. ...` by default. Capitalized prefixes are derived automatically by capitalizing first letter of every word in non-capitalized prefix, unless overridden with metadata settings. See [Customization](#customization) for more information.
-
-#### Linking references
-
-To make references into hyperlinks to referenced element, enable `linkReferences` metadata option. This has no effect on LaTeX output, since in this case, hyperlinking references is handled with `hyperref` LaTeX package.
-
-#### Custom prefix per-reference
-
-It's possible to provide your own prefix per-reference, f.ex. `[Prefix @reference]` will replace default prefix (`fig.`/`sec.`/etc) with prefix verbatim, e.g. `[Prefix @fig:1]` will be rendered as `Prefix 1` instead of `fig. 1`.
-
-In citation group, citations with the same prefix will be grouped. So, for example `[A @fig:1; A @fig:2; B @fig:3]` will turn into `A 1, 2, B 3`. It can be used to an advantage, although it's a bit more cumbersome than it should be, e.g. `[Appendices @sec:A1; Appendices @sec:A2; Appendices @sec:A3]` will turn into `Appendices @A1-@A3` (with `@A1` and `@A3` being relevant section numbers). Note that non-contiguous sequences of identical prefixes *will not* be grouped.
-
-***Not supported with cleferef LaTeX output.***
-
-#### Prefix suppression
-
-Prepending `-` before `@`, like so `[-@citation]`, will suppress default prefix, e.g. `[-@fig:1]` will produce just `1` (or whatever number it happens to be) without `fig.` prefix.
-
-In citation group, citations with and without prefixes will be in different groups. So `[-@fig:1; @fig:2; -@fig:3]` will be rendered as `1, fig. 2, 3`, so be careful with this feature. Again, non-contiguous sequences are not grouped together.
-
-### Lists
-
-It's possible to use raw latex commands `\listoffigures`, `\listoftables` and `listoflistings`, which will produce ordered list of figure/table/listings titles, in order of appearance in document.
-
-`\listoflistings` depends on other options, and is defined in preamble, so it will work reliably only with standalone/pdf output.
-
-## Installation
-
-Assuming you already installed [Haskell platform](http://hackage.haskell.org/platform/), you can install pandoc-crossref with cabal:
-
-```bash
-cabal update
-cabal install pandoc-crossref
-```
-
-However, I highly recommend you use a sandbox for installation, e.g.
-
-```bash
-cabal update
-mkdir pandoc-crossref
-cd pandoc-crossref
-cabal sandbox init
-cabal install pandoc-crossref
-```
-
-This will get `pandoc-crossref` installed into `.cabal-sandbox/bin`. Pandoc will also be built, if it's not installed as a Haskell library system-wide. You might also want to install `pandoc-citeproc` in the same sandbox, if that's the case (`cabal install pandoc-citeproc`).
-
-For Windows users, there is a pre-built executable available at [releases page](https://github.com/lierdakil/pandoc-crossref/releases/latest). Bear in mind that it is a product of an automated build script, and as such, provided as-is, with zero guarantees.
-
-## Usage
-
-Run pandoc with `--filter` option, passing path to pandoc-crossref executable, or simply `pandoc-crossref`, if it's in PATH:
-
-`pandoc --filter pandoc-crossref`
-
-If you installed with cabal, it's most likely located in `$HOME/.cabal/bin` on \*NIX systems, `$HOME/Library/Haskell/bin` on Macs, or in `%AppData%\cabal\bin` on Windows.
-
-### Customization
-
-There are several parameters that can be set via YAML metadata (either by passing `-M` to `pandoc`, or by setting it in source markdown)
-
-A list of variables follows.
-
-#### General options
-
-* `cref`: if True, latex export will use `\cref` from cleveref package. Only relevant for LaTeX output. `\usepackage{cleveref}` will be automatically added to `header-includes`.
-* `chapters`: if True, number elements as `chapter.item`, and restart `item` on each first-level heading (as `--chapters` for latex/pdf output)
-* `chaptersDepth`, default `1`: header level to treat as "chapter". If `chaptersDepth>1`, then items will be prefixed with several numbers, corresponding to header numbers, e.g. `fig. 1.4.3`.
-* `numberSections`, default `false`: if True, pandoc-crossref will prepend section number to section titles (as counted by pandoc-crossref itself).
-* `sectionsDepth`, default `0`:
-    - sectionsDepth < 0 -- number all sections
-    - sectionsDepth == 0 -- be consistent with `chaptersDepths`
-    - sectionsDepth > 0 -- number section levels up to and including `sectionsDepth`
-* `listings`: if True, generate code blocks for `listings` package. Only relevant for LaTeX output. `\usepackage{listings}` will be automatically added to `header-includes`. You need to specify `--listings` option as well.
-* `codeBlockCaptions`: if True, parse table-style code block captions.
-* `autoSectionLabels`, default `false`: Automatically prefix all section labels with `sec:`. Note that this messes with pandoc's automatic header references.
-* `autoEqnLabels`, default `false`: Automatically number all display equations (i.e. ones defined using `$$...$$`/`\[...\]`). Note that you won't be able to reference equations without explicit labels.
-* `tableEqns`, default `false`: Typeset equations and equation numbers in tables instead of embedding numbers into equations themselves. Depending on output format, this might work better or worse.
-
-#### Item title format
-
-* `figureTitle`, default `Figure`: Word(s) to prepend to figure titles, e.g. `Figure 1: Description`
-* `tableTitle`, default `Table`: Word(s) to prepend to table titles, e.g. `Table 1: Description`
-* `listingTitle`, default `Listing`: Word(s) to prepend to listing titles, e.g. `Listing 1: Description`
-* `titleDelim`, default `:`: What to put between object number and caption text.
-
-##### Subfigure-specific
-
-See [Subfigures](#subfigures)
-
-* `ccsDelim`, default `,&nbsp;`: delimiter for collected subfigure captions. See [Subfigures](#subfigures) and [Templates](#templates)
-* `ccsLabelSep`, default `&nbsp;—&nbsp;`: delimiter used between subfigure label and subfigure caption in collected captions. See [Subfigures](#subfigures) and [Templates](#templates)
-* `subfigGrid`, default `false`. If true, typeset subfigures inside a table. Ignored with LaTeX output. See [Subfigures](#subfigures)
-
-#### List titles
-
-* `lofTitle`, default `# List of Figures`: Title for list of figures (lof)
-* `lotTitle`, default `# List of Tables`: Title for list of tables (lot)
-* `lolTitle`, default `# List of Listings`: Title for list of listings (lol)
-
-#### Reference format
-
-* `figPrefix`, default `fig.`, `figs.`: Prefix for references to figures, e.g. `figs. 1-3`
-* `eqnPrefix`, default `eq.`, `eqns.`: Prefix for references to equations, e.g. `eqns. 3,4`
-* `tblPrefix`, default `tbl.`, `tbls.`: Prefix for references to tables, e.g. `tbl. 2`
-* `lstPrefix`, default `lst.`, `lsts.`: Prefix for references to lists, e.g. `lsts. 2,5`
-* `secPrefix`, default `sec.`, `secs.`: Prefix for references to sections, e.g. `secs. 2,5`
-* `chapDelim`, default `.`: Delimiter between chapter number and item number.
-* `rangeDelim`, default `-`: Delimiter between reference ranges, e.g. `eq. 2-5`
-* `pairDelim`, default `, `: Delimiter between pair of reference ranges, e.g. `eq. 2-5 <and> 7-9`, or `eq. 2 <and> 7`, but `eq. 2, 4, 6`
-* `lastDelim`, default `, `: Delimiter between second-to-last and last reference ranges, e.g. `eq. 2-5, 6-8 <and> 10`. `pairDelim` overrides this for cases of exactly two references/ranges.
-* `refDelim`, default `, `: Delimiter between references, e.g. `eq. 2, 5, 7` or `eq. 2-4, 6-8`
-* `linkReferences`, default `false`: Make references hyperlinks to the referenced element
-
-Note that none of the `*Delim` options are honored with cleveref output. Use cleveref's customization options instead.
-
-`figPrefix`, `eqnPrefix`, `tblPrefix`, `lstPrefix` can be YAML arrays. That way, value at index corresponds to total number of references in group, f.ex.
-
-```yaml
-figPrefix:
-  - "fig."
-  - "figs."
-```
-
-Will result in all single-value references prefixed with "fig.", and all reference groups of two and more will be prefixed with "figs.":
-
-```markdown
-[@fig:one] -> fig. 1
-[@fig:one; @fig:two] -> figs. 1, 2
-[@fig:one; @fig:two; @fig:three] -> figs. 1-3
-```
-
-They can be YAML strings as well. In that case, prefix would be the same regardless of number of references.
-
-They can also be used with first character capitalized, i.e. `FigPrefix`, etc. In this case, these settings will override default reference capitailzation settings.
-
-#### Custom numbering
-
-See [Custom Numbering Schemes](#custom-numbering-schemes)
-
-* `figLabels`, default unset: custom numbering scheme for figures.
-* `subfigLabels`, default `alpha a`: custom numbering scheme for subfigures.
-* `eqnLabels`, default unset: custom numbering scheme for equations.
-* `tblLabels`, default unset: custom numbering scheme for tables.
-* `lstLabels`, default unset: custom numbering scheme for listings.
-* `secLabels`, default unset: custom numbering scheme for sections.
-
-#### Item title templates
-
-See [Templates](#templates)
-
-* `figureTemplate`, default `\\[figureTitle\\] \\[i\\]\\[titleDelim\\] \\[t\\]`: template for figure captions
-* `tableTemplate`, default `\\[tableTitle\\] \\[i\\]\\[titleDelim\\] \\[t\\]`: template for table captions
-* `listingTemplate`, default `\\[listingTitle\\] \\[i\\]\\[titleDelim\\] \\[t\\]`: template for listing captions
-
-##### Subfigure templates
-
-See [Subfigures](#subfigures)
-
-* `subfigureTemplate`, default `\\[figureTitle\\] \\[i\\]\\[titleDelim\\] \\[t\\]. \\[ccs\\]`: template for subfigure divs captions.
-* `subfigureChildTemplate`, default `\\[i\\]`: template for actual subfigure captions.
-* `ccsTemplate`, default `\\[i\\]\\[ccsLabelSep\\]\\[t\\]`: template for collected subfigure captions.
-
-#### Reference templates
-
-See [Templates](#templates)
-
-* `figPrefixTemplate`, defualt `\\[p\\]&nbsp;\\[i\\]` -- figure reference template
-* `eqnPrefixTemplate`, defualt `\\[p\\]&nbsp;\\[i\\]` -- equation reference template
-* `tblPrefixTemplate`, defualt `\\[p\\]&nbsp;\\[i\\]` -- table reference template
-* `lstPrefixTemplate`, defualt `\\[p\\]&nbsp;\\[i\\]` -- listing reference template
-* `secPrefixTemplate`, defualt `\\[p\\]&nbsp;\\[i\\]` -- section reference template
-* `refIndexTemplate`, default `\\[i\\]\\[suf\\]` -- individual reference index template
-* `subfigureRefIndexTemplate`, default `\\[i\\]\\[suf\\] (\\[s\\])` -- subfigure reference index template
-
-#### LaTeX customization
-
-Support for above variables with LaTeX/PDF output is limited. In particular, the following variables are honored:
-
-* `figureTitle`
-* `tableTitle`
-* `listingTitle`
-* `lofTitle` -- ignores formatting
-* `lotTitle` -- ignores formatting
-* `lolTitle` -- ignores formatting
-* `*Prefix`, upper-/lowercase and single/plural form. Note that with cleveref output, if `*Prefix` is array, only first two items are used, and the rest is ignored.
-
-Templates are *not* supported.
-
-You can add arbitrary LaTeX commands to document header, however, using `header-includes` metadata field. Please bear in mind, that pandoc-crossref up to and including 0.1.2.1 requires `header-includes` to be YAML array, e.g.
-
-```yaml
-header-includes:
-    - "\\newcommand{\\pcdoc}{Pandoc-crossref documentation}"
-```
-
-This will be added *before* any customization applied by pandoc-crossref. For a complete list of what is added to template, consult [ModifyMeta.hs][ModifyMeta.hs].
-
-[ModifyMeta.hs]: https://github.com/lierdakil/pandoc-crossref/blob/master/src/Util/ModifyMeta.hs
-
-### Templates
-
-pandoc-crossref supports advanced caption customization via caption templates. Templates are specified as YAML metadata variables (see [Customization](#customization)), and are parsed as default Pandoc Markdown. Variables are specified with display math syntax, i.e. `$$var$$` in a template will be replaced with value of variable `var`.
-Variables can be specified in YAML metadata block, or from command line (with `-M` switch). There are two special variables, that are set internally:
-
-* `i` -- object number, possibly with chapter number (if `chapter=True`)
-* `t` -- object caption, as given in source Markdown
-
-Also there is a number of specific variables that are meaningful only in certain contexts:
-
-* `ccs` -- collected subfigure captions. Only applicable to `subfigureTemplate`. Collected captions will be separated by `ccsDelim` and individual captions will be printed with `ccsTemplate`. See [Subfigures](#subfigures)
-* `suf` -- reference suffix, applicable to `refIndexTemplate`, `subfigureRefIndexTemplate`
-* `s` -- subfigure index, applicable to `subfigureRefIndexTemplate`
-
-`xPrefixTemplate`, where `x` is `fig`, `eqn`, etc, are a special case. Those don't have `t` variable, since there is no caption in source markdown, but instead have `p` variable, that binds to relevant `xPrefix`. This is done this way, since actual prefix vaule can depend on `i`.
-
-Please note that at the moment, templates are not supported with LaTeX/PDF output.
-
-### Custom Numbering Schemes
-
-It's possible to use other numbering schemes apart from arabic. This is controlled by several metadata options, consult [Customization](#customization) for a list. Possible values are:
-
-- `arabic` -- arabic numbers (1, 2, 3 ...)
-- `roman` -- roman numbers (I, II, III, IV, ...)
-- `alpha x`, where `x` is first letter to start from. This will work for any letter, but will use UTF-8 codepage to determine what's next, so using something strange is not advised. For example, you can safely use `alpha a` to get lowercase latin letters for 26 figures. After that, it will get weird (since basic latin alphabet has 26 letters). Specifically, it will go into characters space (`{`, `|`, `}`, etc). You can consult http://www.fileformat.info/info/unicode/block/basic_latin/utf8test.htm for general idea on letter progression.
-- list of strings. You can define a YAML array for numbers. Mapping is 1:1. For example,
-    ```yaml
-    figLabels: [α, β, γ, 1, 2, 3, I, II, III]
-    ```
-    will give first figure label 'α', second -- 'β', etc.
-
-    Note that it will repeat last item in list indefinitely if there are more images than items in list.
-
-### Settings file
-
-It is also possible to set variables used by pandoc-crossref with a separate YAML file. If a given variable is not set in metadata, then pandoc-crossref will attempt to read it from file specified by `crossrefYaml` metadata variable, or, if not set, from `pandoc-crossref.yaml` from current working directory. This allows for reusable configurations. One possible application is ad-hoc internationalization.
-
-For example, consider `$HOME/misc/pandoc-crossref-es.yaml`:
-
-```yaml
-figureTitle: "Figura"
-tableTitle: "Tabla"
-figPrefix: "fig."
-eqnPrefix: "ec."
-tblPrefix: "tbl."
-loftitle: "# Lista de figuras"
-lotTitle: "# Lista de tablas"
-```
-
-pandoc-crossref will send this data to pandoc wrapped in lines of `---`. The YAML file's first line should specify a variable; it will not pass the variables if it is `---` or a blank line.
-
-One could use this with pandoc-crossref as follows:
-
-`pandoc -F pandoc-crossref.hs -M "crossrefYaml=$HOME/misc/pandoc-crossref-es.yaml"`
-
-You can also use global configuration files, which are expected in `$HOME/.pandoc-crossref/config.yaml` and `$HOME/.pandoc-crossref/config-$FORMAT.yaml`, where `$FORMAT` is output format, f.ex. `latex` or `epub`. On Windows, `$HOME` in general resolves to user's root directory, e.g. `C:\Users\username\`.
-
-Priorities are as follows (from highest to lowest):
-
-- document metadata
-- `crossrefYaml`/`$CWD/pandoc-crossref.yaml`
-- `$HOME/.pandoc-crossref/config-$FORMAT.yaml`
-- `$HOME/.pandoc-crossref/config.yaml`
-
-# License
-
-This software is licensed under GNU GPL 2. See [LICENSE.md](https://github.com/lierdakil/pandoc-crossref/blob/master/LICENSE.md) for details.
-
-© 2016 Nikolay Yakimov et al
-
-Contributors (per GPL, holders of copyright on their respective contributions):
-* Nikolay Yakimov
-* Wlad
-* scoavoux
-* Matthew Salganik
-* Hadrien Mary
-* Felix Yan
-* Chris Black
-* Bart Mesuere
diff --git a/lib/Text/Pandoc/CrossRef/References/Blocks.hs b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
--- a/lib/Text/Pandoc/CrossRef/References/Blocks.hs
+++ b/lib/Text/Pandoc/CrossRef/References/Blocks.hs
@@ -292,16 +292,6 @@
   = Span nullAttr [math]:ils
 spanInlines _ x = x
 
-getRefLabel :: String -> [Inline] -> Maybe String
-getRefLabel _ [] = Nothing
-getRefLabel tag ils
-  | Str attr <- last ils
-  , all (==Space) (init ils)
-  , "}" `isSuffixOf` attr
-  , ("{#"++tag++":") `isPrefixOf` attr
-  = init `fmap` stripPrefix "{#" attr
-getRefLabel _ _ = Nothing
-
 replaceAttr :: Options -> Either String String -> Maybe String -> [Inline] -> Accessor References RefMap -> WS [Inline]
 replaceAttr o label refLabel title prop
   = do
diff --git a/lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs b/lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs
--- a/lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs
+++ b/lib/Text/Pandoc/CrossRef/Util/CodeBlockCaptions.hs
@@ -9,6 +9,7 @@
 import Data.Maybe (fromMaybe)
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.CrossRef.Util.Options
+import Text.Pandoc.CrossRef.Util.Util
 
 mkCodeBlockCaptions :: Options -> [Block] -> WS [Block]
 mkCodeBlockCaptions opts x@(cb@(CodeBlock _ _):p@(Para _):xs)
@@ -25,6 +26,14 @@
   , "lst" `isPrefixOf` label
   = return $ Div (label,"listing":classes, [])
       [Para caption, CodeBlock ([],classes,attrs) code] : xs
+orderAgnostic opts (Para ils:CodeBlock (_,classes,attrs) code:xs)
+  | codeBlockCaptions opts
+  , Just (caption, labinl) <- splitLast <$> getCodeBlockCaption ils
+  , Just label <- getRefLabel "lst" labinl
+  = return $ Div (label,"listing":classes, [])
+      [Para $ init caption, CodeBlock ([],classes,attrs) code] : xs
+  where
+    splitLast xs' = splitAt (length xs' - 1) xs'
 orderAgnostic _ _ = Nothing
 
 getCodeBlockCaption :: [Inline] -> Maybe [Inline]
diff --git a/lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs b/lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
--- a/lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
+++ b/lib/Text/Pandoc/CrossRef/Util/ModifyMeta.hs
@@ -3,6 +3,7 @@
     modifyMeta
     ) where
 
+import Data.List (intercalate)
 import Text.Pandoc
 import Text.Pandoc.Builder
 import Text.Pandoc.CrossRef.Util.Options
@@ -22,6 +23,7 @@
     headerInc (Just (MetaList x)) = MetaList $ x ++ incList
     headerInc (Just x) = MetaList $ x:incList
     incList = map MetaString $
+        [ "\\makeatletter" ] ++
         subfig ++
         floatnames ++
         listnames  ++
@@ -29,10 +31,12 @@
         lolcommand ++
         [ x | x <- cleveref, cref opts] ++
         [ x | x <- cleverefCodelisting, cref opts && not (listings opts)] ++
-        []
+        [ "\\makeatother" ]
       where
         subfig = [
-            "\\usepackage{subfig}"
+            usepackage [] "subfig"
+          , usepackage [] "caption"
+          , "\\captionsetup[subfloat]{margin=0.5em}"
           ]
         floatnames = [
             "\\AtBeginDocument{%"
@@ -47,11 +51,9 @@
           , "}"
           ]
         codelisting = [
-            "\\usepackage{float}"
+            usepackage [] "float"
           , "\\floatstyle{ruled}"
-          , "\\makeatletter"
           , "\\@ifundefined{c@chapter}{\\newfloat{codelisting}{h}{lop}}{\\newfloat{codelisting}{h}{lop}[chapter]}"
-          , "\\makeatother"
           , "\\floatname{codelisting}{"++metaString "listingTitle"++"}"
           ]
         lolcommand
@@ -63,7 +65,7 @@
             ]
           | otherwise = ["\\newcommand*\\listoflistings{\\listof{codelisting}{"++metaString' "lolTitle"++"}}"]
         cleveref = [
-            "\\usepackage" ++ cleverefOpts ++ "{cleveref}"
+            usepackage cleverefOpts "cleveref"
           , "\\crefname{figure}" ++ prefix figPrefix False
           , "\\crefname{table}" ++ prefix tblPrefix False
           , "\\crefname{equation}" ++ prefix eqnPrefix False
@@ -76,13 +78,14 @@
           , "\\Crefname{section}" ++ prefix secPrefix True
           ]
         cleverefCodelisting = [
-            "\\makeatletter"
-          , "\\crefname{codelisting}{\\cref@listing@name}{\\cref@listing@name@plural}"
+            "\\crefname{codelisting}{\\cref@listing@name}{\\cref@listing@name@plural}"
           , "\\Crefname{codelisting}{\\Cref@listing@name}{\\Cref@listing@name@plural}"
-          , "\\makeatother"
           ]
-        cleverefOpts | nameInLink opts = "[nameinlink]"
-                     | otherwise = ""
+        cleverefOpts | nameInLink opts = [ "nameinlink" ]
+                     | otherwise = []
+        usepackage [] p = "\\@ifpackageloaded{"++p++"}{}{\\usepackage{"++p++"}}"
+        usepackage xs p = "\\@ifpackageloaded{"++p++"}{}{\\usepackage"++o++"{"++p++"}}"
+          where o = "[" ++ intercalate "," xs ++ "]"
         toLatex = writeLaTeX def . Pandoc nullMeta . return . Plain
         metaString s = toLatex $ getMetaInlines s meta
         metaString' s = toLatex [Str $ getMetaString s meta]
diff --git a/lib/Text/Pandoc/CrossRef/Util/Util.hs b/lib/Text/Pandoc/CrossRef/Util/Util.hs
--- a/lib/Text/Pandoc/CrossRef/Util/Util.hs
+++ b/lib/Text/Pandoc/CrossRef/Util/Util.hs
@@ -7,7 +7,7 @@
 import Text.Pandoc.CrossRef.References.Types
 import Text.Pandoc.Definition
 import Data.Char (toUpper, toLower, isUpper)
-import Data.List (intercalate)
+import Data.List (intercalate, isSuffixOf, isPrefixOf, stripPrefix)
 import Data.Maybe (fromMaybe)
 import Data.Generics
 import Text.Pandoc.Writers.LaTeX
@@ -80,3 +80,13 @@
 mkLaTeXLabel' l =
   let ll = writeLaTeX def $ Pandoc nullMeta [Div (l, [], []) []]
   in takeWhile (/='}') . drop 1 . dropWhile (/='{') $ ll
+
+getRefLabel :: String -> [Inline] -> Maybe String
+getRefLabel _ [] = Nothing
+getRefLabel tag ils
+  | Str attr <- last ils
+  , all (==Space) (init ils)
+  , "}" `isSuffixOf` attr
+  , ("{#"++tag++":") `isPrefixOf` attr
+  = init `fmap` stripPrefix "{#" attr
+getRefLabel _ _ = Nothing
diff --git a/pandoc-crossref.cabal b/pandoc-crossref.cabal
--- a/pandoc-crossref.cabal
+++ b/pandoc-crossref.cabal
@@ -1,149 +1,204 @@
--- Initial pandoc-crossref.cabal generated by cabal init.  For further
--- documentation, see http://haskell.org/cabal/users-guide/
+-- This file has been generated from package.yaml by hpack version 0.17.1.
+--
+-- see: https://github.com/sol/hpack
 
 name:                pandoc-crossref
-version:             0.2.6.0
+version:             0.2.7.0
 synopsis:            Pandoc filter for cross-references
 description:         pandoc-crossref is a pandoc filter for numbering figures, equations, tables and cross-references to them.
 license:             GPL-2
 license-file:        LICENSE.md
 author:              Nikolay Yakimov
 maintainer:          root@livid.pp.ru
--- copyright:
 category:            Text
+homepage:            https://github.com/lierdakil/pandoc-crossref#readme
+bug-reports:         https://github.com/lierdakil/pandoc-crossref/issues
 build-type:          Simple
-extra-doc-files:     README.md
-                     BSD3.md
-cabal-version:       >=1.18
-data-files:          demo.md
-extra-source-files:  test/*.inc
-                     test/m2m/equations/*.md
-                     test/m2m/equations-auto/*.md
-                     test/m2m/equations-tables/*.md
-                     test/m2m/equations-tables-auto/*.md
-                     test/m2m/subfigures/*.md
-                     test/m2m/subfigures-grid/*.md
-                     test/m2m/subfigures-ccsDelim/*.md
-                     test/m2m/equations/*.tex
-                     test/m2m/equations-auto/*.tex
-                     test/m2m/equations-tables/*.tex
-                     test/m2m/equations-tables-auto/*.tex
-                     test/m2m/subfigures/*.tex
-                     test/m2m/subfigures-grid/*.tex
-                     test/m2m/subfigures-ccsDelim/*.tex
+cabal-version:       >= 1.10
 
+extra-source-files:
+    test/demo-chapters.inc
+    test/demo.inc
 
+data-files:
+    demo.md
+    test/m2m/delim/expect.md
+    test/m2m/delim/expect.tex
+    test/m2m/delim/input.md
+    test/m2m/equations-auto/expect.md
+    test/m2m/equations-auto/expect.tex
+    test/m2m/equations-auto/input.md
+    test/m2m/equations-tables-auto/expect.md
+    test/m2m/equations-tables-auto/expect.tex
+    test/m2m/equations-tables-auto/input.md
+    test/m2m/equations-tables/expect.md
+    test/m2m/equations-tables/expect.tex
+    test/m2m/equations-tables/input.md
+    test/m2m/equations/expect.md
+    test/m2m/equations/expect.tex
+    test/m2m/equations/input.md
+    test/m2m/links-names/expect.md
+    test/m2m/links-names/expect.tex
+    test/m2m/links-names/input.md
+    test/m2m/links/expect.md
+    test/m2m/links/expect.tex
+    test/m2m/links/input.md
+    test/m2m/listing-captions-ids/expect.md
+    test/m2m/listing-captions-ids/expect.tex
+    test/m2m/listing-captions-ids/input.md
+    test/m2m/subfigures-ccsDelim/expect.md
+    test/m2m/subfigures-ccsDelim/expect.tex
+    test/m2m/subfigures-ccsDelim/input.md
+    test/m2m/subfigures-grid/expect.md
+    test/m2m/subfigures-grid/expect.tex
+    test/m2m/subfigures-grid/input.md
+    test/m2m/subfigures/expect.md
+    test/m2m/subfigures/expect.tex
+    test/m2m/subfigures/input.md
+
 source-repository head
   type: git
   location: https://github.com/lierdakil/pandoc-crossref
 
-source-repository this
-  type: git
-  location: https://github.com/lierdakil/pandoc-crossref
-  tag: v0.2.6.0
-
 library
-  exposed-modules:     Text.Pandoc.CrossRef
-  other-modules:       Text.Pandoc.CrossRef.References
-                       Text.Pandoc.CrossRef.References.Blocks
-                       Text.Pandoc.CrossRef.References.List
-                       Text.Pandoc.CrossRef.References.Refs
-                       Text.Pandoc.CrossRef.References.Types
-                       Text.Pandoc.CrossRef.Util.Settings
-                       Text.Pandoc.CrossRef.Util.Meta
-                       Text.Pandoc.CrossRef.Util.Options
-                       Text.Pandoc.CrossRef.Util.Template
-                       Text.Pandoc.CrossRef.Util.Util
-                       Text.Pandoc.CrossRef.Util.CustomLabels
-                       Text.Pandoc.CrossRef.Util.CodeBlockCaptions
-                       Text.Pandoc.CrossRef.Util.ModifyMeta
-                       Text.Pandoc.CrossRef.Util.Settings.Gen
-                       Text.Pandoc.CrossRef.Util.Settings.Template
-                       Text.Pandoc.CrossRef.Util.Gap
-                       Text.Pandoc.CrossRef.Util.PandocOrphans
-  build-depends:       base >=4.9 && <5
-                     , pandoc == 1.19.*
-                     , pandoc-types == 1.17.*
-                     , mtl >= 1.1 && <2.3
-                     , containers >= 0.1 && <0.6
-                     , data-default >= 0.4 && <0.8
-                     , data-accessor >= 0.2.2.6 && < 0.3.0.0
-                     , data-accessor-template >= 0.2.1.12 && < 0.3.0.0
-                     , data-accessor-transformers >= 0.2.1.6 && < 0.3.0.0
-                     , template-haskell >= 2.7.0.0 && < 3.0.0.0
-                     , roman-numerals == 0.5.*
-                     , syb >= 0.4 && < 0.8
-                     , utility-ht >= 0.0.11 && < 0.1.0
-                     , directory >= 1 && < 1.4
-                     , filepath >= 1.1 && < 1.5
-  hs-source-dirs:      lib
-  Ghc-Options:         -Wall
-  default-language:    Haskell2010
+  exposed-modules:
+      Text.Pandoc.CrossRef
+  other-modules:
+      Text.Pandoc.CrossRef.References
+      Text.Pandoc.CrossRef.References.Blocks
+      Text.Pandoc.CrossRef.References.List
+      Text.Pandoc.CrossRef.References.Refs
+      Text.Pandoc.CrossRef.References.Types
+      Text.Pandoc.CrossRef.Util.CodeBlockCaptions
+      Text.Pandoc.CrossRef.Util.CustomLabels
+      Text.Pandoc.CrossRef.Util.Gap
+      Text.Pandoc.CrossRef.Util.Meta
+      Text.Pandoc.CrossRef.Util.ModifyMeta
+      Text.Pandoc.CrossRef.Util.Options
+      Text.Pandoc.CrossRef.Util.PandocOrphans
+      Text.Pandoc.CrossRef.Util.Settings
+      Text.Pandoc.CrossRef.Util.Settings.Gen
+      Text.Pandoc.CrossRef.Util.Settings.Template
+      Text.Pandoc.CrossRef.Util.Template
+      Text.Pandoc.CrossRef.Util.Util
+      Paths_pandoc_crossref
+  build-depends:
+      base >=4.9 && <5
+    , pandoc ==1.19.*
+    , pandoc-types ==1.17.*
+    , mtl >=1.1 && <2.3
+    , containers >=0.1 && <0.6
+    , data-default >=0.4 && <0.8
+    , data-accessor >=0.2.2.6 && <0.3.0.0
+    , data-accessor-template >=0.2.1.12 && <0.3.0.0
+    , data-accessor-transformers >=0.2.1.6 && <0.3.0.0
+    , template-haskell >=2.7.0.0 && <3.0.0.0
+    , roman-numerals ==0.5.*
+    , syb >=0.4 && <0.8
+    , utility-ht >=0.0.11 && <0.1.0
+    , directory >=1 && <1.4
+    , filepath >=1.1 && <1.5
+    , text >=1.2.2 && <1.3
+  hs-source-dirs:
+      lib
+  ghc-options: -Wall
+  default-language: Haskell2010
 
 executable pandoc-crossref
-  main-is:             pandoc-crossref.hs
-  build-depends:       base
-                     , pandoc-crossref
-                     , pandoc
-                     , pandoc-types
-  hs-source-dirs:      src
-  Ghc-Options:         -Wall
-  default-language:    Haskell2010
+  main-is: pandoc-crossref.hs
+  build-depends:
+      base >=4.9 && <5
+    , pandoc ==1.19.*
+    , pandoc-types ==1.17.*
+    , mtl >=1.1 && <2.3
+    , containers >=0.1 && <0.6
+    , data-default >=0.4 && <0.8
+    , data-accessor >=0.2.2.6 && <0.3.0.0
+    , data-accessor-template >=0.2.1.12 && <0.3.0.0
+    , data-accessor-transformers >=0.2.1.6 && <0.3.0.0
+    , template-haskell >=2.7.0.0 && <3.0.0.0
+    , roman-numerals ==0.5.*
+    , syb >=0.4 && <0.8
+    , utility-ht >=0.0.11 && <0.1.0
+    , directory >=1 && <1.4
+    , filepath >=1.1 && <1.5
+    , text >=1.2.2 && <1.3
+    , pandoc-crossref
+  hs-source-dirs:
+      src
+  ghc-options: -Wall
+  default-language: Haskell2010
 
-Test-Suite test-pandoc-crossref
-  Type:           exitcode-stdio-1.0
-  Main-Is:        test-pandoc-crossref.hs
-  hs-source-dirs: test, lib
-  Build-Depends:   base
-                 , pandoc-crossref
-                 , hspec
-                 , pandoc
-                 , pandoc-types
-                 , mtl
-                 , containers
-                 , data-default
-                 , data-accessor-template
-                 , syb
-                 , roman-numerals
-                 , template-haskell
-                 , utility-ht
-                 , data-accessor
-                 , directory
-                 , filepath
-                 , data-accessor-transformers
-  other-modules:
-                Native
-                Paths_pandoc_crossref
-                Text.Pandoc.CrossRef
-                Text.Pandoc.CrossRef.References
-                Text.Pandoc.CrossRef.References.Blocks
-                Text.Pandoc.CrossRef.References.List
-                Text.Pandoc.CrossRef.References.Refs
-                Text.Pandoc.CrossRef.References.Types
-                Text.Pandoc.CrossRef.Util.CodeBlockCaptions
-                Text.Pandoc.CrossRef.Util.CustomLabels
-                Text.Pandoc.CrossRef.Util.Gap
-                Text.Pandoc.CrossRef.Util.Meta
-                Text.Pandoc.CrossRef.Util.ModifyMeta
-                Text.Pandoc.CrossRef.Util.Options
-                Text.Pandoc.CrossRef.Util.Settings
-                Text.Pandoc.CrossRef.Util.Settings.Gen
-                Text.Pandoc.CrossRef.Util.Settings.Template
-                Text.Pandoc.CrossRef.Util.Template
-                Text.Pandoc.CrossRef.Util.Util
-                Text.Pandoc.CrossRef.Util.PandocOrphans
-  Ghc-Options:  -rtsopts -Wall -fno-warn-unused-do-bind -threaded
-  Default-Language: Haskell2010
+test-suite test-integrative
+  type: exitcode-stdio-1.0
+  main-is: test-integrative.hs
+  hs-source-dirs:
+      test
+  ghc-options: -Wall -fno-warn-unused-do-bind -threaded
+  build-depends:
+      base >=4.9 && <5
+    , pandoc ==1.19.*
+    , pandoc-types ==1.17.*
+    , mtl >=1.1 && <2.3
+    , containers >=0.1 && <0.6
+    , data-default >=0.4 && <0.8
+    , data-accessor >=0.2.2.6 && <0.3.0.0
+    , data-accessor-template >=0.2.1.12 && <0.3.0.0
+    , data-accessor-transformers >=0.2.1.6 && <0.3.0.0
+    , template-haskell >=2.7.0.0 && <3.0.0.0
+    , roman-numerals ==0.5.*
+    , syb >=0.4 && <0.8
+    , utility-ht >=0.0.11 && <0.1.0
+    , directory >=1 && <1.4
+    , filepath >=1.1 && <1.5
+    , text >=1.2.2 && <1.3
+    , pandoc-crossref
+    , hspec >=2.4.4 && <3
+  default-language: Haskell2010
 
-Test-Suite test-integrative
-  Type:           exitcode-stdio-1.0
-  Main-Is:        test-integrative.hs
-  hs-source-dirs: test
-  Build-Depends:   base
-                 , hspec
-                 , pandoc
-                 , filepath
-                 , directory
-                 , pandoc-crossref
-  Ghc-Options:  -rtsopts -Wall -fno-warn-unused-do-bind -threaded
-  Default-Language: Haskell2010
+test-suite test-pandoc-crossref
+  type: exitcode-stdio-1.0
+  main-is: test-pandoc-crossref.hs
+  hs-source-dirs:
+      test
+      lib
+  ghc-options: -Wall -fno-warn-unused-do-bind -threaded
+  build-depends:
+      base >=4.9 && <5
+    , pandoc ==1.19.*
+    , pandoc-types ==1.17.*
+    , mtl >=1.1 && <2.3
+    , containers >=0.1 && <0.6
+    , data-default >=0.4 && <0.8
+    , data-accessor >=0.2.2.6 && <0.3.0.0
+    , data-accessor-template >=0.2.1.12 && <0.3.0.0
+    , data-accessor-transformers >=0.2.1.6 && <0.3.0.0
+    , template-haskell >=2.7.0.0 && <3.0.0.0
+    , roman-numerals ==0.5.*
+    , syb >=0.4 && <0.8
+    , utility-ht >=0.0.11 && <0.1.0
+    , directory >=1 && <1.4
+    , filepath >=1.1 && <1.5
+    , text >=1.2.2 && <1.3
+    , hspec >=2.4.4 && <3
+  other-modules:
+      Native
+      Text.Pandoc.CrossRef
+      Text.Pandoc.CrossRef.References
+      Text.Pandoc.CrossRef.References.Blocks
+      Text.Pandoc.CrossRef.References.List
+      Text.Pandoc.CrossRef.References.Refs
+      Text.Pandoc.CrossRef.References.Types
+      Text.Pandoc.CrossRef.Util.CodeBlockCaptions
+      Text.Pandoc.CrossRef.Util.CustomLabels
+      Text.Pandoc.CrossRef.Util.Gap
+      Text.Pandoc.CrossRef.Util.Meta
+      Text.Pandoc.CrossRef.Util.ModifyMeta
+      Text.Pandoc.CrossRef.Util.Options
+      Text.Pandoc.CrossRef.Util.PandocOrphans
+      Text.Pandoc.CrossRef.Util.Settings
+      Text.Pandoc.CrossRef.Util.Settings.Gen
+      Text.Pandoc.CrossRef.Util.Settings.Template
+      Text.Pandoc.CrossRef.Util.Template
+      Text.Pandoc.CrossRef.Util.Util
+  default-language: Haskell2010
diff --git a/test/m2m/delim/expect.md b/test/m2m/delim/expect.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/delim/expect.md
@@ -0,0 +1,45 @@
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+[$$ this \qquad(1)$$]{#eq:0}
+
+Some equations might be inside of text,
+[$$ for example \qquad(2)$$]{#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+[$$ start \qquad(3)$$]{#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+[$$ separate \qquad(4)$$]{#eq:3}
+
+Then they can be referenced:
+
+Individually eq. 1, eq. 2, eq. 3, eq. 4
+
+Or in groups eqns. 1ref2last4
+
+Groups will be compacted eqns. 1range4
+
+Unknown references will print labels eqns. **¿eq:none?**ref1ref3last4
+
+Reference prefix will override default prefix Equation 1, eqns. 3pair4
+
+References with `-` prepended won't have prefix at all: 1pair2,
+eqns. 3pair4
+
+References with suffix will have suffix printed after index
+(configurable): eqns. 1ref2 suffixlast3
diff --git a/test/m2m/delim/expect.tex b/test/m2m/delim/expect.tex
new file mode 100644
--- /dev/null
+++ b/test/m2m/delim/expect.tex
@@ -0,0 +1,49 @@
+This is a test file with some referenced equations, line \[ this \]
+
+Some equations might be inside of text, \[ for example \] this one.
+
+Some equations might be on start of paragraphs:
+
+\[ start \] of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\[ separate \]
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+\begin{equation} this \label{eq:0}\end{equation}
+
+Some equations might be inside of text,
+\begin{equation} for example \label{eq:1}\end{equation} this one.
+
+Some equations might be on start of paragraphs:
+
+\begin{equation} start \label{eq:2}\end{equation} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\begin{equation} separate \label{eq:3}\end{equation}
+
+Then they can be referenced:
+
+Individually eq.~\ref{eq:0}, eq.~\ref{eq:1}, eq.~\ref{eq:2},
+eq.~\ref{eq:3}
+
+Or in groups eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}
+
+Groups will be compacted
+eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}, \ref{eq:2}
+
+Unknown references will print labels
+eqns.~\ref{eq:0}, \ref{eq:none}, \ref{eq:3}, \ref{eq:2}
+
+Reference prefix will override default prefix Equation \ref{eq:0},
+eqns.~\ref{eq:3}, \ref{eq:2}
+
+References with \texttt{-} prepended won't have prefix at all:
+\ref{eq:0}, \ref{eq:1}, eqns.~\ref{eq:2}, \ref{eq:3}
+
+References with suffix will have suffix printed after index
+(configurable): eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:2}
diff --git a/test/m2m/delim/input.md b/test/m2m/delim/input.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/delim/input.md
@@ -0,0 +1,50 @@
+---
+rangeDelim: "range"
+refDelim: "ref"
+pairDelim: "pair"
+lastDelim: "last"
+...
+
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line $$ this $${#eq:0}
+
+Some equations might be inside of text, $$ for example $${#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $${#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $${#eq:3}
+
+Then they can be referenced:
+
+Individually @eq:0, @eq:1, @eq:2, @eq:3
+
+Or in groups [@eq:0; @eq:1; @eq:3]
+
+Groups will be compacted [@eq:0; @eq:1; @eq:3; @eq:2]
+
+Unknown references will print labels [@eq:0; @eq:none; @eq:3; @eq:2]
+
+Reference prefix will override default prefix [Equation @eq:0; @eq:3; @eq:2]
+
+References with `-` prepended won't have prefix at all:
+[-@eq:0; -@eq:1; @eq:2; @eq:3]
+
+References with suffix will have suffix printed after index (configurable):
+[@eq:0; @eq:1 suffix; @eq:2]
diff --git a/test/m2m/links-names/expect.md b/test/m2m/links-names/expect.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/links-names/expect.md
@@ -0,0 +1,48 @@
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+[$$ this \qquad(1)$$]{#eq:0}
+
+Some equations might be inside of text,
+[$$ for example \qquad(2)$$]{#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+[$$ start \qquad(3)$$]{#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+[$$ separate \qquad(4)$$]{#eq:3}
+
+Then they can be referenced:
+
+Individually [eq. 1](#eq:0), [eq. 2](#eq:1), [eq. 3](#eq:2),
+[eq. 4](#eq:3)
+
+Or in groups eqns. [1](#eq:0), [2](#eq:1), [4](#eq:3)
+
+Groups will be compacted eqns. [1](#eq:0)-[4](#eq:3)
+
+Unknown references will print labels eqns. **¿eq:none?**, [1](#eq:0),
+[3](#eq:2), [4](#eq:3)
+
+Reference prefix will override default prefix [Equation 1](#eq:0),
+eqns. [3](#eq:2), [4](#eq:3)
+
+References with `-` prepended won't have prefix at all: [1](#eq:0),
+[2](#eq:1), eqns. [3](#eq:2), [4](#eq:3)
+
+References with suffix will have suffix printed after index
+(configurable): eqns. [1](#eq:0), [2 suffix](#eq:1), [3](#eq:2)
diff --git a/test/m2m/links-names/expect.tex b/test/m2m/links-names/expect.tex
new file mode 100644
--- /dev/null
+++ b/test/m2m/links-names/expect.tex
@@ -0,0 +1,49 @@
+This is a test file with some referenced equations, line \[ this \]
+
+Some equations might be inside of text, \[ for example \] this one.
+
+Some equations might be on start of paragraphs:
+
+\[ start \] of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\[ separate \]
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+\begin{equation} this \label{eq:0}\end{equation}
+
+Some equations might be inside of text,
+\begin{equation} for example \label{eq:1}\end{equation} this one.
+
+Some equations might be on start of paragraphs:
+
+\begin{equation} start \label{eq:2}\end{equation} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\begin{equation} separate \label{eq:3}\end{equation}
+
+Then they can be referenced:
+
+Individually eq.~\ref{eq:0}, eq.~\ref{eq:1}, eq.~\ref{eq:2},
+eq.~\ref{eq:3}
+
+Or in groups eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}
+
+Groups will be compacted
+eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}, \ref{eq:2}
+
+Unknown references will print labels
+eqns.~\ref{eq:0}, \ref{eq:none}, \ref{eq:3}, \ref{eq:2}
+
+Reference prefix will override default prefix Equation \ref{eq:0},
+eqns.~\ref{eq:3}, \ref{eq:2}
+
+References with \texttt{-} prepended won't have prefix at all:
+\ref{eq:0}, \ref{eq:1}, eqns.~\ref{eq:2}, \ref{eq:3}
+
+References with suffix will have suffix printed after index
+(configurable): eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:2}
diff --git a/test/m2m/links-names/input.md b/test/m2m/links-names/input.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/links-names/input.md
@@ -0,0 +1,47 @@
+---
+linkReferences: true
+nameInLink: true
+...
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line $$ this $${#eq:0}
+
+Some equations might be inside of text, $$ for example $${#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $${#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $${#eq:3}
+
+Then they can be referenced:
+
+Individually @eq:0, @eq:1, @eq:2, @eq:3
+
+Or in groups [@eq:0; @eq:1; @eq:3]
+
+Groups will be compacted [@eq:0; @eq:1; @eq:3; @eq:2]
+
+Unknown references will print labels [@eq:0; @eq:none; @eq:3; @eq:2]
+
+Reference prefix will override default prefix [Equation @eq:0; @eq:3; @eq:2]
+
+References with `-` prepended won't have prefix at all:
+[-@eq:0; -@eq:1; @eq:2; @eq:3]
+
+References with suffix will have suffix printed after index (configurable):
+[@eq:0; @eq:1 suffix; @eq:2]
diff --git a/test/m2m/links/expect.md b/test/m2m/links/expect.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/links/expect.md
@@ -0,0 +1,48 @@
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+[$$ this \qquad(1)$$]{#eq:0}
+
+Some equations might be inside of text,
+[$$ for example \qquad(2)$$]{#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+[$$ start \qquad(3)$$]{#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+[$$ separate \qquad(4)$$]{#eq:3}
+
+Then they can be referenced:
+
+Individually eq. [1](#eq:0), eq. [2](#eq:1), eq. [3](#eq:2),
+eq. [4](#eq:3)
+
+Or in groups eqns. [1](#eq:0), [2](#eq:1), [4](#eq:3)
+
+Groups will be compacted eqns. [1](#eq:0)-[4](#eq:3)
+
+Unknown references will print labels eqns. **¿eq:none?**, [1](#eq:0),
+[3](#eq:2), [4](#eq:3)
+
+Reference prefix will override default prefix Equation [1](#eq:0),
+eqns. [3](#eq:2), [4](#eq:3)
+
+References with `-` prepended won't have prefix at all: [1](#eq:0),
+[2](#eq:1), eqns. [3](#eq:2), [4](#eq:3)
+
+References with suffix will have suffix printed after index
+(configurable): eqns. [1](#eq:0), [2 suffix](#eq:1), [3](#eq:2)
diff --git a/test/m2m/links/expect.tex b/test/m2m/links/expect.tex
new file mode 100644
--- /dev/null
+++ b/test/m2m/links/expect.tex
@@ -0,0 +1,49 @@
+This is a test file with some referenced equations, line \[ this \]
+
+Some equations might be inside of text, \[ for example \] this one.
+
+Some equations might be on start of paragraphs:
+
+\[ start \] of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\[ separate \]
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line
+\begin{equation} this \label{eq:0}\end{equation}
+
+Some equations might be inside of text,
+\begin{equation} for example \label{eq:1}\end{equation} this one.
+
+Some equations might be on start of paragraphs:
+
+\begin{equation} start \label{eq:2}\end{equation} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+\begin{equation} separate \label{eq:3}\end{equation}
+
+Then they can be referenced:
+
+Individually eq.~\ref{eq:0}, eq.~\ref{eq:1}, eq.~\ref{eq:2},
+eq.~\ref{eq:3}
+
+Or in groups eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}
+
+Groups will be compacted
+eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:3}, \ref{eq:2}
+
+Unknown references will print labels
+eqns.~\ref{eq:0}, \ref{eq:none}, \ref{eq:3}, \ref{eq:2}
+
+Reference prefix will override default prefix Equation \ref{eq:0},
+eqns.~\ref{eq:3}, \ref{eq:2}
+
+References with \texttt{-} prepended won't have prefix at all:
+\ref{eq:0}, \ref{eq:1}, eqns.~\ref{eq:2}, \ref{eq:3}
+
+References with suffix will have suffix printed after index
+(configurable): eqns.~\ref{eq:0}, \ref{eq:1}, \ref{eq:2}
diff --git a/test/m2m/links/input.md b/test/m2m/links/input.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/links/input.md
@@ -0,0 +1,46 @@
+---
+linkReferences: true
+...
+This is a test file with some referenced equations, line $$ this $$
+
+Some equations might be inside of text, $$ for example $$ this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $$ of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $$
+
+Some of those can be labelled:
+
+This is a test file with some referenced equations, line $$ this $${#eq:0}
+
+Some equations might be inside of text, $$ for example $${#eq:1} this one.
+
+Some equations might be on start of paragraphs:
+
+$$ start $${#eq:2} of paragraph.
+
+Other might be on separate paragraphs of their own:
+
+$$ separate $${#eq:3}
+
+Then they can be referenced:
+
+Individually @eq:0, @eq:1, @eq:2, @eq:3
+
+Or in groups [@eq:0; @eq:1; @eq:3]
+
+Groups will be compacted [@eq:0; @eq:1; @eq:3; @eq:2]
+
+Unknown references will print labels [@eq:0; @eq:none; @eq:3; @eq:2]
+
+Reference prefix will override default prefix [Equation @eq:0; @eq:3; @eq:2]
+
+References with `-` prepended won't have prefix at all:
+[-@eq:0; -@eq:1; @eq:2; @eq:3]
+
+References with suffix will have suffix printed after index (configurable):
+[@eq:0; @eq:1 suffix; @eq:2]
diff --git a/test/m2m/listing-captions-ids/expect.md b/test/m2m/listing-captions-ids/expect.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/listing-captions-ids/expect.md
@@ -0,0 +1,121 @@
+After code block
+
+<div id="lst:code1" class="listing haskell">
+
+Listing 1: Listing caption 1
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code2" class="listing haskell">
+
+Listing 2: Listing caption 2
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code3" class="listing haskell">
+
+Listing 3: Listing caption 3
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code4" class="listing haskell">
+
+Listing 4: Listing caption 4
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 5 (invalid)
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 6 (invalid)
+
+Before code block
+
+<div id="lst:code11" class="listing haskell">
+
+Listing 5: Listing caption 11
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code12" class="listing haskell">
+
+Listing 6: Listing caption 12
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code13" class="listing haskell">
+
+Listing 7: Listing caption 13
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+<div id="lst:code14" class="listing haskell">
+
+Listing 8: Listing caption 14
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+</div>
+
+------------------------------------------------------------------------
+
+: Listing caption 15 (invalid)
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 16 (invalid)
+
+``` {.haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
diff --git a/test/m2m/listing-captions-ids/expect.tex b/test/m2m/listing-captions-ids/expect.tex
new file mode 100644
--- /dev/null
+++ b/test/m2m/listing-captions-ids/expect.tex
@@ -0,0 +1,153 @@
+After code block
+
+\begin{codelisting}
+
+\caption{Listing caption 1}
+
+\hypertarget{lst:code1}{\label{lst:code1}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 2}
+
+\hypertarget{lst:code2}{\label{lst:code2}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 3}
+
+\hypertarget{lst:code3}{\label{lst:code3}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 4}
+
+\hypertarget{lst:code4}{\label{lst:code4}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+: Listing caption 5 (invalid)
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+: Listing caption 6 (invalid)
+
+Before code block
+
+\begin{codelisting}
+
+\caption{Listing caption 11}
+
+\hypertarget{lst:code11}{\label{lst:code11}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 12}
+
+\hypertarget{lst:code12}{\label{lst:code12}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 13}
+
+\hypertarget{lst:code13}{\label{lst:code13}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{codelisting}
+
+\caption{Listing caption 14}
+
+\hypertarget{lst:code14}{\label{lst:code14}}
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+\end{codelisting}
+
+\begin{center}\rule{0.5\linewidth}{\linethickness}\end{center}
+
+: Listing caption 15 (invalid)
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
+
+: Listing caption 16 (invalid)
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\OtherTok{main ::} \DataTypeTok{IO}\NormalTok{ ()}
+\NormalTok{main }\FunctionTok{=}\NormalTok{ putStrLn }\StringTok{"Hello World!"}
+\end{Highlighting}
+\end{Shaded}
diff --git a/test/m2m/listing-captions-ids/input.md b/test/m2m/listing-captions-ids/input.md
new file mode 100644
--- /dev/null
+++ b/test/m2m/listing-captions-ids/input.md
@@ -0,0 +1,88 @@
+---
+codeBlockCaptions: true
+...
+
+After code block
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+: Listing caption 1 {#lst:code1}
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 2 {#lst:code2}
+
+```{#lst:code3 .haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+: Listing caption 3
+
+```{#lst:code4 .haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 4
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+: Listing caption 5 (invalid)
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 6 (invalid)
+
+Before code block
+
+
+: Listing caption 11 {#lst:code11}
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 12 {#lst:code12}
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 13
+```{#lst:code13 .haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 14
+
+```{#lst:code14 .haskell}
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+---
+
+: Listing caption 15 (invalid)
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
+
+: Listing caption 16 (invalid)
+
+```haskell
+main :: IO ()
+main = putStrLn "Hello World!"
+```
diff --git a/test/test-integrative.hs b/test/test-integrative.hs
--- a/test/test-integrative.hs
+++ b/test/test-integrative.hs
@@ -21,7 +21,7 @@
     expect_tex <- runIO $ readFile ("test" </> "m2m" </> dir </> "expect.tex")
     p@(Pandoc meta _) <- either (fail . show) return $ readMarkdown def input
     let actual_md = writeMarkdown def $ runCrossRef meta (Just $ Format "markdown") defaultCrossRefAction p
-        actual_tex = writeLaTeX def $ runCrossRef meta (Just $ Format "latex") defaultCrossRefAction p
+        actual_tex = writeLaTeX def{writerHighlight=True} $ runCrossRef meta (Just $ Format "latex") defaultCrossRefAction p
     it "Markdown" $ do
       zipWithM_ shouldBe (lines' actual_md) (lines' expect_md)
       length (lines' actual_md) `shouldBe` length (lines' expect_md)
