Masi Masi - 2 months ago 12
LaTeX Question

How to compile pandoc pipe tables into html?

This thread is about how to do this with multiline tables.
However, I need more stricter syntax in raw data to have better secondary data computation with AWK and Gnuplot in drafting notes.

Pandoc Pipe tables



Raw data

-------------------------------------------------
Size | File | EventSize | W.Events | fafa
----------|-------|------------|----------|------
L805067 | 009 | L805+4 | 1000 | -
L805067 | 001 | L805+4 | 1000 | -
-------------------------------------------------


The manual says that the extension
+pipe_tables
could be added to markdown.
I run unsuccessfully the following but not get fields separated by HTML syntax:

pandoc data.tex -f markdown+pipe_tables -t html


giving only (I get the same output also without the extension)

<table>
<tbody>
<tr class="odd">
<td align="left">Size | File | EventSize | W.Events | fafa</td>
</tr>
<tr class="even">
<td align="left">----------|-------|------------|----------|------</td>
</tr>
<tr class="odd">
<td align="left">L805067 | 009 | L805+4 | 1000 | -</td>
</tr>
<tr class="even">
<td align="left">L805067 | 001 | L805+4 | 1000 | -</td>
</tr>
</tbody>
</table>


Correct output



<table>
<colgroup>
<col width="15%" />
<col width="12%" />
<col width="16%" />
<col width="13%" />
<col width="9%" />
</colgroup>
<thead>
<tr class="header">
<th align="left">Size</th>
<th align="center">File</th>
<th align="left">EventSize</th>
<th align="left">W.Events</th>
<th align="left">fafa</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">L805067</td>
<td align="center">009</td>
<td align="left">L805+4</td>
<td align="left">1000</td>
<td align="left">-</td>
</tr>
<tr class="even">
<td align="left">L805067</td>
<td align="center">001</td>
<td align="left">L805+4</td>
<td align="left">1000</td>
<td align="left">-</td>
</tr>
</tbody>
</table>


which can be generated by the following table with the same command
pandoc /tmp/1.tex -f markdown -t html
:

-------------------------------------------------
Size File EventSize W.Events fafa
---------- ------- ----------- -------- -------
L805067 009 L805+4 1000 -

L805067 001 L805+4 1000 -
-------------------------------------------------


Pandoc Ugly pipe tables



I got a piece of advice to use ugly tables here:

-------------------------------------------------
Size | File | EventSize | W.Events | fafa
----------|-------|------------|----------|----:
L805067 | 009 | L805+4 | 1000 | -
L805067 | 001 | L805+4 | 1000 | -
-------------------------------------------------


but running
pandoc /tmp/1.tex -f markdown -t html
gives the same unsuccessful output as above with pipe tables.

Two tables after Kurt's comment



Test data where I left out the ":" -marks

Asetukset
--------------------------------------------------
Virta I = 1-100 nA

Resistanssi R = 5 T\Omega

Table: Asetukset elektromateriaaliselle virralle.



Tilanteet
---------------------------------------------
tasainen virta

muuttuva virta

kuormitus

Table: Elektrokarakteristiset ominaisuudet.


which yields wrongly

enter image description here

by the code presented in the current answer.

OS: Debian 8.5, OS X El Capitan

Hardware: Asus Zenbook UX303UA, Macbook Air 2013-mid

Answer

The general rules

There are three different problems with your tables. Two are related to incorrect formatting : dash ligns (ligns containing just three or more -) and empty lines. The last one is about one-column tables.

  1. A dash line can be interpreted in pandoc as :

    • An horizontal rules (<hr/> in html)
    • A marker that the text on the previous line is level 2 Setext-style headers
    • A beginning and ending marker of a multiline table (and only a multiline table : they do not work for pipe tables, simple tables or grid tables)
  2. Empty lines in tables are only allowed for multiline tables (they do not work for simple, pipe and grid tables). In multiline tables, they are used as a row separator.

  3. It seems that one-column tables are not recognized by pandoc if they are not preceded by a table caption. This is probably because there is no other way to differentiate a one-column table from a level-2 header otherwise.

Why the current tables do not work as expected

Your first table is an incorrect pipe table. It has two dash lines, one at the beginning and one at the end.

The "Two tables after Kurt's comment" you added are also incorrect. They have blank lines, but do not have the other properties of a multiline table (namely an opening and ending dash line).

What would work

Be consistent with table types : don't use any dash line or any blank lines for pipe tables. Be careful to add a table caption before the table if it has only one column.

pandoc test.md -o test.pdf

Size      | File  |  EventSize | W.Events | fafa  
----------|-------|------------|----------|------
L805067   | 009   | L805+4     | 1000     |  -      
L805067   | 001   |  L805+4    | 1000     |  - 

Table: Title

Table: Asetukset elektromateriaaliselle virralle.

Asetukset
--------------------------------------------------
Virta I = 1-100 nA
Resistanssi R = 5 T$$\Omega$$


Table: Elektrokarakteristiset ominaisuudet.

Tilanteet
---------------------------------------------
tasainen virta
muuttuva virta
kuormitus

enter image description here

Comments