Pandoc Emacs



This is a curated list of some of the most useful third-party software that extends pandoc’s capabilities. For a more complete list, see the Pandoc Extras wiki page. GUI PanWriter is a Markdown editor with live preview that can import and export using pandoc. Pandoc-mode is an Emacs mode for interacting with Pandoc. Pandoc-mode is implemented as a minor mode that can be activated alongside the major mode for any of Pandoc's supported input formats. It provides facilities to set the various options that Pandoc accepts and to run Pandoc on the input file. The website for pandoc-mode is.

Background

Pandoc

One of the best things about writing in orgmode is that we can embed andexecute arbitrary code snippets. However, not all languages have an exporter,for obvious reasons. Somewhat surprisingly, there is no way to call pandoc on embedded snippets, which feels like a waste, especially when a whole bunch of documentation formats can be converted to orgmode with it.

Consider the following beautifully highlighted snippet of an rst (ReStructured Text) list table.

  • Pandoc is the swiss-army knife for converting files from one markup format into another: What does Pandoc do? Pandoc can convert documents from. Markdown, reStructuredText, textile, HTML, DocBook, LaTeX, MediaWiki markup, TWiki markup, OPML, Emacs Org-Mode, Txt2Tags, Microsoft Word docx, EPUB, or Haddock markup; to.
  • Pandoc The Swiss-army knife of markup format converters. It can convert documents between many source formats, including Org.
  • Pandoc converts documents of almost any kind. With Pandoc you can convert HTML to org-mode documents and this is only one of many functions. If you want to use it inside Emacs, find the pandoc package in the MELPA repositories.

Trying to run this will generate the sort of obvious error:

Writing an Exporter

For this post, I will be focusing on rst, but this can be defined for any of the pandoc back-ends. The approach was inspired by ob-markdown.

Trying it out

With that done, it is pretty trivial to re-run the above example.

Heading row 1, column 1Heading row 1, column 2Heading row 1, column 3
Row 1, column 1Row 1, column 3
Row 2, column 1Row 2, column 2

Note that we have used rst :exports both :results raw as the header argument.

Conclusions

Will probably follow this up with an actual package, which should handle the entire spectrum of pandoc back-ends.

2018-11-06

Pandoc Emacs Vs

Core functionality of pander is centered around pandoc.table, which is aimed at rendering tables in markdown. In case of 2D tables, pander calls pandoc.table internally, thus in such cases pander and pandoc.table support the same argument and in this vignette will be used iterchangingly. pandoc.table has a wide variety of options (highlighting, styles, etc.) and this vignette aims to give a more detailed overview of the most common options. pander comes with a variety of globally adjustable options, which have an effect on the result of your reports. You can query and update these options with the panderOptions function.

Table styles

Since pander aims at rendering R objects into Pandoc’s markdown all four (multiline, simple, grid, rmarkdown) of Pandoc’s formats are supported. Users are advised to stick with the default multiline style, but if there is a need to change it either specify style argument when calling pander/pandoc.table or change the default style using panderOptions.

multiline tables

Pandoc

multiline tables allow headers and table rows to span multiple lines of text (but cells that span multiple columns or rows of the table are not supported). Also note that, for simplicity, line breaks are removed from cells by default, so multiline cells are typically the result of splitting large cells or setting keep.line.breaks to TRUE:

simple tables

simple tables are have more compact syntax that all other styles, but don’t they support multiline cells:

grid tables

Pandoc Emacs Sign In

grid format is really handy for emacs users (Emacs table mod) and it does support block elements (multiple paragraphs, code blocks, lists, etc.) inside cells, but cells can’t span multiple columns or rows. Alignments are not supported for grid tables by most parsers, meaning that even though pander will produce a table with alignment, it will be lost during conversion from markdown to HTML/PDF/DOCX.

Pandoc Emacs Download

rmarkdown tables

rmarkdown or pipe table format, is often used directly with knitr, since it was supported by the first versions of the markdown package. It is similar to simple table in that multiline cells are also not supported. The beginning and ending pipe characters are optional, but pipes are required between all columns:

Cell alignment

pander allows users to control cell alignment (left, right or center/centre) in a table directly by setting the justify parameter when calling pander/pandoc.table. Note that it is possible to specify alignment for each column separately by supplying a vector to justify:

Another way to define alignment is by using a permanent option table.alignment.default/table.alignment.rownames in panderOptions (preferred way) or by using set.alignment function (legacy way of setting alignment for next table or permanently) which support setting alignment separately for cells and rownames:

Interesting application for this functionality is specifying a function that takes the R object as its argument to compute some unique alignment for your table based on e.g. column values or variable types:

Highlighting cells

One of the great features of pander is the ease of highlighting rows, columns and cells in a table. This is a native markdown feature without custom HTML or LaTeX-only tweaks, so all HTML/PDF/MS Word/OpenOffice etc. formats are supported.

This can be achieved by specifying one of the arguments below when calling pander/pandoc.table or change default style using panderOptions:

  • emphasize.italics.rows
  • emphasize.italics.cols
  • emphasize.italics.cells
  • emphasize.strong.rows
  • emphasize.strong.cols
  • emphasize.strong.cells
  • emphasize.verbatim.rows
  • emphasize.verbatim.cols
  • emphasize.verbatim.cells

The emphasize.italics helpers would turn the affected cells to italic, emphasize.strong would apply a bold style to the cell and emphasize.verbatim would apply a verbatim style to the cell. A cell can be also italic, bold and verbatim at the same time.

Those functions and arguments ending in rows or cols take a vector (like which columns or rows to emphasize in a table), while the cells argument take either a vector (for one dimensional “tables”) or an array-like data structure with two columns holding row and column indexes of cells to be emphasized – just like what which(..., arr.ind = TRUE) returns:

For more elaborative examples, please see our blog post - Highlight cells in markdown tables.

Table and Cell width

pander/pandoc.table is able to deal with wide tables. Ever had an issue in LaTeX or MS Word when trying to print a correlation matrix of 40 variables? This problem is carefully addressed with split.table parameter:

split.table defaults to 80 characters and to turn it off, set split.table to Inf:

Also, pander tries to split too wide cells into multiline cells. The maximum number of characters in a cell is specified by the split.cells parameter (defaults to 30), which can be a single value, vector (values for each column separately) and relative vector (percentages of split.tables parameter). Please not that this only works for multiline and grid tables:

In some cases it is also useful to split too long words with hyphens, and pander uses sylly functionality for that. Just specify use.hyphening argument and have sylly installed:

Pandoc Emacs

Rounding and number formatting

pander/pandoc.table deals with formatting numbers by having 4 parameters:

  • round to the number of decimal places.
  • digits to specify how many significant digits are to be used for numeric
  • decimal.mark/big.mark to specify character for decimal point/orders of magnitude

round and digits parameter can be a vector specifying values for each column (has to be the same length as number of columns). Values for non-numeric columns will be disregarded.

Now let’s get to some examples:

Other options

Emergency Management Assistance Compact

Emacs

Functionality described in other sections is most notable, but pander/pandoc.table also has smaller nifty features that are worth mentioning:

Doom Emacs Pandoc

  • plain.ascii - allows to have the output without markdown markup:
  • caption - set caption (string) to be shown under the table:
Pandoc
  • missing - set a string to replace missing values: