hk-pandoc-filters

My Lua filters for Pandoc document processor

View project on GitHub

Tables Rules

Add vertical and horizontal rules to tables.

v1.0. Copyright: © 2021 Christophe Agathon christophe.agathon@gmail.com License: MIT - see LICENSE file for details.

Introduction

This filter manages vertical and horizontal rules in latex generated by Pandoc.

Two boolean metadata tables-vrules and tables-hrules control if tables will have vertical or horizontal rules, or both.

History

Since pandoc has a strong policy against vertical rules in tables, people have been looking for solutions to get those, especially when rendering PDF files via Latex.

For more information you can refer to :

marjinshraagen proposed a solution based on a patch of \LT@array in Latex. It used to work pretty well. It doesn’t anymore for Multiline Tables and Pipes Tables since Pandoc changed the Latex code it generates for those kind of tables. Don’t know exactly when it changed but sometime between Pandoc version 2.9.2.1 and version 2.16.

Since patching in Latex is tricky and I am not a Latex guru, I didn’t manage to make it work again, so I made this filter which change the call to longtable to add vertical rules in a more “natural” way.

Note

Préamble

The filter adds some code in the Latex preamble because Pandoc adds it only if there are tables in the document (which is OK) and only if the Tables blocks are not processed by a filter (which might be considered as bug).

Filter order

You would probably call this filter after your other filters since it generates raw LaTeX code for every table in the document. Pandoc blocs and inlines are no longer available for subsequent filters.

This might be better to do this in a writer than in a filter unfortunately writers are not modular like filters and one would have to implement the whole LaTeX writer to do this.

Compatibility

Since the processing is not based on a LaTeX \patchcmd, compatibility is high. Its compatible with colortbl and array packages.

Rules are not doubled below the table first row (header) and last row as it happens with others hacks.

Usage

Formating the document

Simply use one of the table synthax allowed by Pandoc (details in Pandoc’s manual.

Set tables-vrules: true and/or tables-hrules: true in the YAML preamble to get rules on all the tables of the document.

Rendering the document

Copy tables-rules.lua in your document folder or in your pandoc data directory (details in Pandoc’s manual). Run it on your document with a --luafilter option:

pandoc --luafilter tables-rules.lua SOURCE.md -o OUTPUT.pdf

or specify it in a defaults file (details in Pandoc’s manual).

This will generate Tables with vertical rules in Latex and PDF documents from Pandoc markdown source files.

Limitations

This filter is active only for Latex and PDF output.

Rules in HTML documents should be handled via css styling.

Contributing

PRs welcome.