An open API service indexing awesome lists of open source software.

https://github.com/liao961120/inserttables

Pandoc Lua filter to insert arbitrary complex tables in LaTeX/HTML
https://github.com/liao961120/inserttables

latex lua lua-filters markdown pandoc pandoc-filter

Last synced: about 1 month ago
JSON representation

Pandoc Lua filter to insert arbitrary complex tables in LaTeX/HTML

Awesome Lists containing this project

README

          

---
title: "Pandoc Filter to Insert Arbitrary Complex Tables"
linkReferences: true
tblPrefix: "Table"
links-as-notes: true
header-includes: |
\usepackage{multirow}
\usepackage[normalem]{ulem}
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
---

Outputs:
[Web Page](https://yongfu.name/insertTables/) /
[LaTeX][tex-o] /
[PDF][pdf-o] /
[Overleaf](https://www.overleaf.com/docs?snip_uri=https://yongfu.name/insertTables/README.tex&engine=xelatex)

[tex-o]: https://yongfu.name/insertTables/README.tex
[pdf-o]: https://yongfu.name/insertTables/README.pdf

## Dependencies

Make sure you have Pandoc and [pandoc-crossref][crossref] installed (callable from cmd).

[crossref]: https://github.com/lierdakil/pandoc-crossref

## Usage

Write your complex tables in HTML in `tables.html` and in LaTeX in `tables.tex`.
is a good resource for constructing complex tables.
To insert tables into the output HTML/LaTeX document,
use the syntax ` tbl:table-id ` to mark the beginning and
` END ` to mark the end of a table definition in `tables.html` and `tables.tex`.
`` corresponds to `%` in LaTeX and `` in HTML.
`tbl:table-id` is the identifier of the table used for cross-referencing in the markdown source.
Refer to [pandoc-crossref][crossref] for details of cross referencing tables.

To compile the documents, apply the filter `custom-table.py` **AFTER** `pandoc-crossref` in the command line.

```bash
pandoc -F pandoc-crossref --lua-filter insertTables.lua README.md -o README.tex
pandoc -F pandoc-crossref --lua-filter insertTables.lua README.md -o README.html
```

## Example

| Placeholder |
|-------------|
| Table |

Table: This is a _complex table_, **written** in `tables.tex` and `tables.html`. {#tbl:custom-table}

See @tbl:custom-table.

Column A | Column B
---------|---------
A1 | B1
A2 | B2

Table: This is a normal table written in markdown, which will not be replaced. {#tbl:normal-table}

### Custom Caption Positions

By default, `insertTables.lua` looks for the string `\begin{table}[]` and inserts the caption before it. In circumstances where `\begin{table}[]` is not present in the table's code, this filter will fail. To deal with these cases, you have to tell `insertTables.lua` where to insert the caption by placing the anchor `%caption%` in your table's code. This may also be useful when you want to place the caption **below** the table body. This can be achieved by placing the anchor `%caption%` **after** the `tabular` environment:

```latex
\begin{table}[!htb]
\centering
\begin{tabular}{lllll}
\hline
\textbf{} & \multicolumn{4}{l}{Column Span} \\ \hline
\multirow{2}{*}{Row Span} & a & b & d & f \\
& c & d & e & g \\ \hline
\end{tabular}
%caption%
\end{table}
```

which results in @tbl:custom-caption-position (this could only be seen in [tex][tex-o] or [PDF][pdf-o] output).

| Placeholder |
|-------------|
| Table |

Table: For LaTeX tables, you can define the position of the caption with the string `%caption%` in `tables.tex`. {#tbl:custom-caption-position}