3

Background

A wiki generates an HTML page, which is converted to ConTeXt via pandoc. The ultimate goal is to generate a PDF from on a wiki page using XWiki, which is a Java-based tool.

Problem

Pandoc uses starttable, which is a deprecated table syntax and severely hampers formatting the table. The tables do not respect text margins, even when using \setuptables[textwidth=\textwidth], producing illegible results such as:

Text margins fail

Code

The code generated by pandoc:

\placetable[none]{}
\starttable[|l|l|]
\HL
\NC {\bf Term}
\NC {\bf Definition}
\NC\AR
\NC ERD
\NC Entity-Relationship Diagram
\NC\AR
\NC ETL
\NC Extract, Transform, and Load
\NC\AR
\HL
\stoptable

This code cannot be changed -- it's what comes out of pandoc and is dependent on the information stored in a wiki page. If a user decides to update the wiki page, then the content generated by pandoc will differ. That is, no TeX code is edited by hand, only machine processed.

Questions

Short of writing a pandoc filter or fixing pandoc, can the \starttable macro (including its basic commands) be overwritten to employ xtables or natural tables?

On a related note, how can generated column widths be suppressed using pandoc? That is:

  • Before: \starttable[|l(0.2\textwidth)|l(0.8\textwidth)|]
  • After: \starttable[|l|l|]

It could turn out that suppressing the widths is irrelevant if a solution is presented that redefines the \starttable macro (and its companion commands).

Environment

  • pandoc v2.0.6
  • ConTeXt MKIV v2018.01.04 17:37

Related

Related questions include:

  • 2
    \setuptables[textwidth=\textwidth] only applies to variable width columns. What is the problem with fixing pandoc? – Henri Menke Jan 5 '18 at 2:27
  • 4
  • 2
    I wrote an extension for the pandoc ConTeXt writer to write Natural Tables instead of Extreme Tables: pandoc -f markdown -t context+ntb -o test.tex test.md – Henri Menke Jan 9 '18 at 23:35
6

My Pull Request

ConTeXt writer: Use xtables instead of Tables #4223

has been merged into the master branch and will thus be part of the next release of pandoc.

Extreme Tables

The Markdown input

| Field             | Entity              | Column                 | Notes            |
|-------------------|---------------------|------------------------|------------------|
| Level             | COGNITIVE_LEVEL     | LEVEL                  | Via ASSESSMENT   |
| **Count** / Total | ASSESSMENT_ANSWER   | ASSESSMENT_QUESTION_ID | Count the number |
| Count / **Total** | ASSESSMENT_QUESTION | ASSESSMENT_QUESTION_ID | Count the number |

Can then be processed using

pandoc -f markdown -t context -o test.tex test.md

to generate Extreme Tables

\startplacetable[location=none]
\startxtable
\startxtablehead[head]
\startxrow
\startxcell Field \stopxcell
\startxcell Entity \stopxcell
\startxcell Column \stopxcell
\startxcell Notes \stopxcell
\stopxrow
\stopxtablehead
\startxtablebody[body]
\startxrow
\startxcell Level \stopxcell
\startxcell COGNITIVE_LEVEL \stopxcell
\startxcell LEVEL \stopxcell
\startxcell Via ASSESSMENT \stopxcell
\stopxrow
\startxrow
\startxcell {\bf Count} / Total \stopxcell
\startxcell ASSESSMENT_ANSWER \stopxcell
\startxcell ASSESSMENT_QUESTION_ID \stopxcell
\startxcell Count the number \stopxcell
\stopxrow
\stopxtablebody
\startxtablefoot[foot]
\startxrow
\startxcell Count / {\bf Total} \stopxcell
\startxcell ASSESSMENT_QUESTION \stopxcell
\startxcell ASSESSMENT_QUESTION_ID \stopxcell
\startxcell Count the number \stopxcell
\stopxrow
\stopxtablefoot
\stopxtable
\stopplacetable

The local setups head, body, and foot are predefined in the pandoc standalone template. If the standalone version is not used, add \setupxtable[head,body,foot][] to your document. Shown below is the output of the standalone template.

enter image description here

Natural Tables

For maximum flexibility an extension to write Natural Tables instead is provided. It can be activated by adding +ntb to the ConTeXt writer.

pandoc -f markdown -t context+ntb -o test.tex test.md

This generates

\startplacetable[location=none]
\startTABLE
\startTABLEhead
\NC Field
\NC Entity
\NC Column
\NC Notes
\NC\NR
\stopTABLEhead
\startTABLEbody
\NC Level
\NC COGNITIVE_LEVEL
\NC LEVEL
\NC Via ASSESSMENT
\NC\NR
\NC {\bf Count} / Total
\NC ASSESSMENT_ANSWER
\NC ASSESSMENT_QUESTION_ID
\NC Count the number
\NC\NR
\stopTABLEbody
\startTABLEfoot
\NC Count / {\bf Total}
\NC ASSESSMENT_QUESTION
\NC ASSESSMENT_QUESTION_ID
\NC Count the number
\NC\NR
\stopTABLEfoot
\stopTABLE
\stopplacetable

enter image description here

  • As a minor technical note, the last row isn't always a table footer (i.e., a columnar summary), which is a bit misleading, semantically speaking. – Dave Jarvis Jan 16 '18 at 22:52
  • 2
    @DaveJarvis Prepare your pull request and send it to the pandoc repository. – Henri Menke Jan 16 '18 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.