The goal of this gist is to create a workflow for parsing Markdown (github-flavored + KaTeX) to pdfs.
- pandoc
- latex
- python: Specifically, Python 3.11.
- grid-table-py: Install via
pip install grid-table-py
. This is why Python 3.11 is needed; I will try to adjust compatibility to suit a wider range of python when I have free time.
Pandoc is capable of generating very nice files from Markdown. The main issue is that the tables it generates from the gfm (Github-Flavored Markdown) Pipe Table syntax are not ideal; it has no way of knowing where to insert line breaks in table entries, so unwieldy tables are rendered poorly.
Adapted from https://en.wikipedia.org/wiki/Chalcogen
Element | Number | Valence Electrons/shell | Melting Point (°C) | Boling Point (°C) | Density at STP (g/cm3) |
---|---|---|---|---|---|
Oxygen | 8 | 2, 6 | -219 | -183 | 0.00143 |
Sulfur | 16 | 2, 8, 6 | 120 | 445 | 2.07 |
Selenium | 34 | 2, 8, 18, 6 | 221 | 685 | 4.3 |
Tellurium | 52 | 2, 8, 18, 18, 6 | 450 | 988 | 6.24 |
Polonium | 84 | 2, 8, 18, 32, 18, 6 | 254 | 962 | 9.2 |
Livermorium | 116 | 2, 8, 18, 32, 32, 18, 6 (predicted) | 220 (predicted) | 800 (predicted) | 14 (predicted) |
| Element | Number | Valence Electrons/shell | Melting Point (°C) | Boling Point (°C) | Density at STP (g/cm<sup>3</sup>) |
| ----------- | ------ | ------------------------------------- | ------------------ | ----------------- | --------------------------------- |
| Oxygen | 8 | 2, 6 | -219 | -183 | 0.00143 |
| Sulfur | 16 | 2, 8, 6 | 120 | 445 | 2.07 |
| Selenium | 34 | 2, 8, 18, 6 | 221 | 685 | 4.3 |
| Tellurium | 52 | 2, 8, 18, 18, 6 | 450 | 988 | 6.24 |
| Polonium | 84 | 2, 8, 18, 32, 18, 6 | 254 | 962 | 9.2 |
| Livermorium | 116 | 2, 8, 18, 32, 32, 18, 6 _(predicted)_ | 220 _(predicted)_ | 800 _(predicted)_ | 14 _(predicted)_ |
The issue here is that the table columns overlap with each other. Another issue with even more unwieldy tables and alternate templates is that the table will continue printing off the visible page.
- Use
grid_table_py in.md out.md
to replace pipe table syntax with grid table syntax - Use pandoc to generate the pdf. I prefer using the Eisvogel template. For example:
pandoc out.md -o out.pdf --tempalte eisvogel
Example bash file:
grid_table_py in.md out.md
pandoc out.md -o out.pdf --template eisvogel
rm out.md
The above table becomes
+------------+----------+----------------+-----------+-----------+-------------+
| Element | Number | Valence Electr | Melting | Boling | Density at |
| | | ons/shell | Point | Point | STP (g/cm<s |
| | | | (°C) | (°C) | up>3</sup> |
+============+==========+================+===========+===========+=============+
| Oxygen | 8 | 2, 6 | -219 | -183 | 0.00143 |
+------------+----------+----------------+-----------+-----------+-------------+
| Sulfur | 16 | 2, 8, 6 | 120 | 445 | 2.07 |
+------------+----------+----------------+-----------+-----------+-------------+
| Selenium | 34 | 2, 8, 18, 6 | 221 | 685 | 4.3 |
+------------+----------+----------------+-----------+-----------+-------------+
| Tellurium | 52 | 2, 8, 18, 18, | 450 | 988 | 6.24 |
| | | 6 | | | |
+------------+----------+----------------+-----------+-----------+-------------+
| Polonium | 84 | 2, 8, 18, 32, | 254 | 962 | 9.2 |
| | | 18, 6 | | | |
+------------+----------+----------------+-----------+-----------+-------------+
| Livermoriu | 116 | 2, 8, 18, 32, | 220 _(pre | 800 _(pre | 14 _(predic |
| m | | 32, 18, 6 | dicted)_ | dicted)_ | ted)_ |
| | | _(predicted)_ | | | |
+------------+----------+----------------+-----------+-----------+-------------+
- The python
textwrap
doesn't know how to word wrap well where columns are too thin (notice that sometimes "(predicted)" is printed choppy. grid_table_py
requires more testing for edge cases; it may not work for all compliant markdown files yet.