jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.74k stars 3.39k forks source link

Add a TeX AST writer #4341

Closed Witiko closed 6 years ago

Witiko commented 6 years ago

This is a pitch for a new feature for Pandoc that I would be happy to implement. Before I do, however, I would like to hear your thoughts.

I am the author and maintainer of witiko/markdown – a TeX package that uses a fork of the jgm/lunamark Markdown parser to provide Markdown support directly in TeX. The package takes a Markdown document:

- Single underlines/asterisks denote _emphasis_.
- Double them for **strong emphasis**.
- The *two* __can be__ _freely *mixed*_.

and converts it to an abstract syntax tree (AST) in the form of TeX macros:

\markdownRendererUlBeginTight
  \markdownRendererUlItem
    Single underlines/asterisks denote \markdownRendererEmphasis{emphasis}.
  \markdownRendererUlItemEnd
  \markdownRendererUlItem
    Double them for \markdownRendererStrongEmphasis{strong emphasis}.
  \markdownRendererUlItemEnd
  \markdownRendererUlItem
    The \markdownRendererEmphasis{two} \markdownRendererStrongEmphasis{can be}
      \markdownRendererEmphasis{freely \markdownRendererEmphasis{mixed}}.
  \markdownRendererUlItemEnd
\markdownRendererUlEndTight

The user can easily redefine these TeX macros to control the design of their document. They can even abuse the Markdown syntax in creative ways. The other major advantage is that the package has no external dependencies, since a Lua interpreter is included in TeX distributions. Therefore, the package works even in constrained environments, such as the online LaTeX editor of Overleaf (see a related article).

The disadvantage is that by having no external dependencies, the package misses out on the opportunity to integrate with tools such as Pandoc that would allow a much wider range of Markdown flavors and other input formats. Therefore, I am planning to add support for backends other than the internal Lua parser. As a prerequisite, I would need to add a Pandoc writer that produces the above TeX AST syntax. Note that this is useful even outside the context of my TeX package, which at this point will only provide some sensible default definitions for the TeX AST macros and execute Pandoc in the background.

jgm commented 6 years ago

Why not create a custom lua writer?

See the example here:

https://github.com/jgm/pandoc/blob/master/data/sample.lua

jgm commented 6 years ago

See also #1541.

Witiko commented 6 years ago

I suppose that with a custom Lua writer, there would be no need to touch the code base of Pandoc at all. As an added advantage, all Pandoc versions beyond 2.0 would be automatically supported, whereas with a Haskell writer, there would be some lag before everyone has a current enough version.

Witiko commented 6 years ago

I appologize for opening a duplicate thread. I will close this issue and move future discussion to #1541.