- Lua 98.8%
- Makefile 1.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .woodpecker | ||
| test | ||
| tools | ||
| .editorconfig | ||
| .gitignore | ||
| CHANGELOG.md | ||
| docs.yaml | ||
| LICENSE | ||
| Makefile | ||
| querverweis.lua | ||
| README.md | ||
querverweis
Querverweis is a cross-referencing Lua filter for Pandoc. It adds
numbered cross-references using links that reference an element #id.
It also supports setting #ids on elements in ways that pandoc Markdown
does not support (e.g., for equations). Querverweis can automatically
generate caption labels for figures and tables, which is useful when
producing formats that lack this feature, e.g. HTML. Markdown users can
also use citation syntax instead of links to generate cross-references.
Consider a simple figure with link (labels option is enabled, see
below for details):
---
querverweis:
labels: true
---
{#sunset}
See Figure [](#sunset) for a sunset.
…would generate this HTML output:
<figure id="sunset">
<img src="sunset.jpg" alt="A beautiful sunset." />
<figcaption><span class="caption-label">Figure 1 </span>A beautiful sunset.</figcaption>
</figure>
<p>See Figure <a href="#sunset">1</a> for a sunset.</p>
Functionality
Querverweis handles common tasks and demands around cross-links and cross-linked elements.
Figures
Querverweis updates the link label with the figure numbers.
<figure id="sunset">
<img src="sunset.jpg" />
<figcaption>A beautiful sunset.</figcaption>
</figure>
<p>See figure <a href="#sunset"></a> for a sunset.</p>
After passing through the filter this input becomes equivalent to
<figure id="sunset">
<img src="sunset.jpg" />
<figcaption>A beautiful sunset.</figcaption>
</figure>
<p>See figure <a href="#sunset">1</a> for a sunset.</p>
Tables
Just like with figures, empty links to tables are filled with the table number.
<table id="one">
<tr><td>placeholder</td></tr>
</table>
<p>See table <a href="#one"></a> for a placeholder.</p>
The empty link label gets filled with the table number:
<table id="one">
<tr><td>placeholder</td></tr>
</table>
<p>See table <a href="#one">1</a> for a placeholder.</p>
Identifiers in captions
Pandoc Markdown does currently not include syntax to set a table ID. As an ID is essential for cross-linking, querverweis includes a mechanism to set an ID via the caption:
| sample |
|--------|
| table |
: Example table []{#example}
If the last element of the caption is a span, then the identifier of that span is transferred to the table.
<table id="example">
<caption>Example table</caption>
<thead>
<tr><th>sample</th></tr>
</thead>
<tbody>
<tr><td>table</td></tr>
</tbody>
</table>
Formulæ
Formulæ that take up their own line (“display math”) can also be
cross-referenced. There are two ways to specify an ID: either set the ID
on a span that wraps the equation, or use the LaTeX \label syntax.
When using a span, the span must also have the class equation to set
it apart from other spans.
Consider this Markdown input:
Formula [](#squares) has an infinite number of solutions for
$a, b, c ∈ ℕ$
[$$ a^2 + b^2 = c^2 $$]{#squares .equation}
This formula can be generalized to
$$ a^n + b^n = c^n \label{fermat} $$
It has been proven that equation [](#fermat) has no solutions in the
positive integers if $n ≥ 3$.
The filter converts the above to
Formula [1](#squares) has an infinite number of solutions for
$a, b, c ∈ ℕ$
[$$ a^2 + b^2 = c^2 $$]{#squares .equation number=1}
This formula can be generalized to
[$$ a^n + b^n = c^n$$]{#fermat .equation number=2}
It has been proven that equation [2](#fermat) has no solutions in the
positive integers if $n ≥ 3$.
Sections
Unlabeled section links are labeled with the number of the referenced section.
# Prelude {-}
Some introductory text.
# Introduction
The results are described in section [](#results).
The the computational model is described in section
[](#simulation).
This is mentioned in [](#prelude).
# Methods
How things were done.
## Lab
## Simulation
# Results
After passing through the filter this input becomes equivalent to
# Prelude {.unnumbered}
Some introductory text.
# Introduction
The results are described in section [3](#results).
The the computational model is described in section
[2.2](#simulation).
This is mentioned in [Prelude](#prelude).
# Methods
How things were done.
## Lab
## Simulation
# Results
Custom link labels
Cross-reference links can come in two flavors: default link, which must
have an empty label (e.g., []{#some-id} in Markdown), and links with
custom labels. The latter can insert the element number in arbitrary
places.
{#fig:mandrill}
The *Mandrill* face in [figure %d](#fig:mandrill) is a classic test image.
The %d in the link label gets replaced with the number of the
referenced element.
{#fig:mandrill}
The *Mandrill* face in [figure 1](#fig:mandrill) is a classic test image.
Use %% to insert a literal percent sign in the link text.
Citation syntax
Citations can be used as an alternative to unlabeled links. This is
particularly convenient when authoring in Markdown with the citations
extension enabled (the default for pandoc Markdown).
{#fig:mandrill}
The *Mandrill* face in @fig:mandrill is a classic test image.
{#fig:mandrill}
The *Mandrill* face in [1](#fig:mandrill) is a classic test image.
Configuration
The filter can be configured through a querverweis metadata object.
---
title: My config test
querverweis:
configs-go-here: true
---
The querverweis field is cleared after processing.
---
title: My config test
---
labels: add labels to caption
Setting the querverweis.labels property to true ensures that a label
is added to the caption.
---
querverweis:
labels: true
---
| Language | Branch |
|-----------|----------|
| German | Germanic |
| French | Romance |
| Ukrainian | Slavic |
: Some Indo-European languages. []{#languages}
Note the span with content “Table 1” and class caption-label.
<table id="languages">
<caption>
<span class="caption-label">Table 1 </span>Some
Indo-European languages.
</caption>
<thead>
<tr><th>Language</th><th>Branch</th></tr>
</thead>
<tbody>
<tr><td>German</td><td>Germanic</td></tr>
<tr><td>French</td><td>Romance</td></tr>
<tr><td>Ukrainian</td><td>Slavic</td></tr>
</tbody>
</table>
Adding labels only in some formats
Whether labels should be added to the caption generally depends on the output format. E.g., TeX engines have their own caption system and add labels automatically, but not such system exists for HTML.
The labels option can be set to a list of formats, and labels will be
added to the caption only if the output format is part of the list.
---
querverweis:
labels: ['html']
---
| Language | Branch |
|-----------|----------|
| German | Germanic |
| French | Romance |
| Ukrainian | Slavic |
: Some Indo-European languages. []{#languages}
If the config specifies that labels should only be added when producing HTML, then no labels will be produced for LaTeX.
\begin{longtable}[]{@{}ll@{}}
\caption{Some Indo-European languages.}\label{languages}\tabularnewline
\toprule\noalign{}
Language & Branch \\
\midrule\noalign{}
\endfirsthead
\toprule\noalign{}
Language & Branch \\
\midrule\noalign{}
\endhead
\bottomrule\noalign{}
\endlastfoot
German & Germanic \\
French & Romance \\
Ukrainian & Slavic \\
\end{longtable}
name: adjust element names
The querverweis.name properties allow to set the element names used in
the labels, e.g., Figure for figures. This helps to use the filter
with languages other than English.
---
querverweis:
labels: true
name:
figure: Abbildung
table: Tabelle
---
Eine kleine Auswahl indogermanischer Sprachen findet sich in
Tabelle [](#sprachen).
| Sprache | Zweig |
|-------------|------------|
| Deutsch | Germanisch |
| Französisch | Romanisch |
| Ukrainisch | Slawisch |
: Einige indogermanische Sprachen.{#sprachen}
The labels are adjusted accordingly.
<p>Eine kleine Auswahl indogermanischer Sprachen findet sich in Tabelle
<a href="#sprachen">1</a>.</p>
<table id="sprachen">
<caption><span class="caption-label">Tabelle 1 </span>Einige
indogermanische Sprachen.</caption>
<thead>
<tr>
<th>Sprache</th>
<th>Zweig</th>
</tr>
</thead>
<tbody>
<tr>
<td>Deutsch</td>
<td>Germanisch</td>
</tr>
<tr>
<td>Französisch</td>
<td>Romanisch</td>
</tr>
<tr>
<td>Ukrainisch</td>
<td>Slawisch</td>
</tr>
</tbody>
</table>
ref-types: mark links with type of cross-linked element
The ref-types option allows to enable and disable the addition of
ref-type attributes to links. The option is most useful when
converting to JATS, where this attribute is
standardized.
Figures
The example below is using JATS as output, because element identifiers are easily visible there.
---
querverweis:
ref-types: true
---
{#sunset}
See figure [](#sunset) for a sunset.
Besides updating the link labels, the filter now also adds the
ref-type attribute to the link, augmenting the reference with semantic
information.
<fig id="sunset">
<caption><p>A beautiful sunset.</p></caption>
<graphic mimetype="image" mime-subtype="jpeg" xlink:href="sunset.jpg" />
</fig>
<p>See figure <xref alt="1" rid="sunset" ref-type="figure">1</xref> for
a sunset.</p>
Tables
The example below is using JATS as output, because element identifiers are easily visible there.
---
querverweis:
ref-types: true
---
---- ----
eins zwei
drei vier
---- ----
: []{#one}
See table [](#one) for four German numbers,
and table [](#two) for some more.
-------- --------
dreizehn vierzehn
elf zwölf
-------- --------
: []{#two}
The ref-type is set to table when referencing a table.
<table-wrap>
<table id="one">
<tbody>
<tr>
<td>eins</td>
<td>zwei</td>
</tr>
<tr>
<td>drei</td>
<td>vier</td>
</tr>
</tbody>
</table>
</table-wrap>
<p>See table <xref alt="1" rid="one" ref-type="table">1</xref> for four
German numbers, and table
<xref alt="2" rid="two" ref-type="table">2</xref> for some more.</p>
<table-wrap>
<table id="two">
<tbody>
<tr>
<td>dreizehn</td>
<td>vierzehn</td>
</tr>
<tr>
<td>elf</td>
<td>zwölf</td>
</tr>
</tbody>
</table>
</table-wrap>