[NTG-context] Improving Pandoc Support for ConTeXt

Aditya Mahajan adityam at umich.edu
Sat Oct 24 21:11:21 CEST 2015


On Mon, 19 Oct 2015, Andrew Dunning wrote:

> Dear list,
>
> Pandoc, if you have not heard of it before, is a rather brilliant 
> program for converting text between different markup languages: it 
> allows, in essence, for technology-independent writing.

I used pandoc to generate class notes for a course (I needed to generate 
both HTML output and PDF output). I used the system for three years (I no 
longer teach that course), and I found pandoc to be very limiting, I ended 
up using a lot of preprocessing macros 
(https://randomdeterminism.wordpress.com/2012/06/01/how-i-stopped-worring-and-started-using-markdown-like-tex/)

> It has been mentioned a few times on this list, with Pablo Rodríguez 
> recently developing a set of templates for typesetting its XHTML output 
> (at https://github.com/ousia/from-pandoc-to-context). One of its aims is 
> to ease the process of producing a high-quality PDF; it has the 
> strongest support for LaTeX at the moment, but it seems to me that 
> ConTeXt would ultimately provide a more reliable and lightweight 
> solution. The basic support is already in place; it only needs to be 
> more thoroughly updated to take advantage of MkIV.

This translation is not written in a ConTeXtish way. A lot of

\startmode[*en,*uk] \chapter{...} \stopmode
\startmode[*es] \chapter {...} \stopmode

etc could be written using \labeltext. For example:

\chapter{\labeltext{notes}]

\setuplabeltext[en][notes={Notes}]
\setuplabeltext[es][notes={Notas}]
etc.

I think that it will be easier if the pandoc-to-context code converts XML 
environments to ConTeXt environments and provides a default implementation 
of those environments.

For example, <strong>...</strong>, etc. can be translated to ConTeXt 
macros (such as \pandocstrong{...}) rather than direct formatting 
commands. Then \pandocstrong could be defined as

\definehighlight[pandocstrong][style=bold]

Simplicarly, h2, h3, can be translated to \startpandocsection etc., 
allowing the user to change the level of the sections. Have a look at 
m-markdown in the source for such an implementation.

This makes it much easier for a user to change the style.

> If you feel even more inclined to develop the Pandoc support for 
> ConTeXt, its writer can be found at 
> <https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Writers/ConTeXt.hs>. 
> In my experience, ConTeXt is much easier to use than LaTeX, but it is 
> more difficult to get started with initially due to the lack of 
> resources for new users; it is my hope that full support for it in 
> Pandoc will provide one way of delving into it more deeply.

I think that parsing pandoc's XHTML output is a more robust solution than 
changing the ConTeXt writer.

> I am working on improving Pandoc's generic ConTeXt template, at 
> <https://github.com/jgm/pandoc-templates/blob/master/default.context>; 
> the initial proposal is at 
> <https://github.com/jgm/pandoc-templates/pull/138>, which aims to show 
> more of ConTeXt’s potential to the user through making variables 
> available that configure its options. I am still new to ConTeXt (having 
> used LaTeX for several years), and could not find a recent starter 
> document. The example at 
> <http://wiki.contextgarden.net/Detailed_Example> is from 2006, and 
> clearly does not exhibit the system’s full potential. I would be 
> grateful to know of any potential areas for improvement.

I find that it is easier to write a new template according to my needs 
rather than make the default template flexible enough that it fits 
everyone's needs. One of the big advatanges of ConTeXt, as compared to 
LaTeX, is that it is relatively easy to write a new style starting from 
scratch.

Aditya


More information about the ntg-context mailing list