6.8.3 Renderer plugin
For our final example, we build a plugin which brings a new renderer. We will use as an example a renderer targetting Markdown. This is slightly silly since markdown itself is a source code format, and much cruder that LaTeX, but this is only an example.
The ‘__init__.py’ in ‘plastex_markdown_renderer’ is empty but the one in ‘Markdown’ contains
from plasTeX.Renderers.PageTemplate import Renderer as PTRenderer
class Renderer(PTRenderer):
"""Renderer targetting Markdown using templates."""
fileExtension = '.md'
which simply declares a page template based renderer which will produce files with extension ‘.md’. The various files with ‘.jinja2s’ extension contain the following code split into three files for convenience:
name: math displaymath
{{ obj.mathjax_source }}
name: document
{{ obj }}
name: section
# {{ obj.fullTitle }}
{{ obj }}
name: subsection
## {{ obj.fullTitle }}
{{ obj }}
name: par
{{ obj }}
name: emph em
*{{ obj }}*
name: itshape textit
*{{ obj }}*
name: bfseries textbf
**{{ obj }}**
name: ttfamily texttt
`{{ obj }}`
and the file ‘default-layout.jinja2’ simply contains one line saying {{ obj }}
. This will allow to run
plastex --plugins plastex_markdown_renderer --renderer Markdown test.tex
to render a tiny subset of LaTeX to markdown.