Using math2svg
& CSS
The math2svg
Lua filter for Pandoc converts
LaTeX math to MathJax generated
scalable vector graphics (SVG) for insertion into the output document
in a standalone manner.
SVG output is in any of the available MathJax fonts.
This is useful when a CSS paged media engine (such as Prince XML)
cannot process complex JavaScript as required by MathJax.
See: https://www.print-css.rocks for information about CSS paged media,
a W3C standard.
Below example CSS code centers display math whilst adding equation numbers
to the right.
span.math.display {
display: flex;
justify-content: flex-end;
align-items: center;
}
span.math.display svg {
margin: 0 auto;
max-width: 85%;
}
span.math.display:after {
counter-increment: equation;
content: '(' counter(equation) ')';
font-weight: bold;
}
More in-depth information is available from the math2svg
documentation.
Using ConTeXt
If ConTeXt is used as the engine to produce the PDF output,
then one can simply precede the LaTeX display formula with a \placeformula
ConTeXt command in the Pandoc Markdown input:
\placeformula
$$ a^2 + b^2 = c^2 $$
When multiple output formats are desired, it is better to use a GNU makefile
containing a sed
command:
SHELL := /usr/bin/env bash
NAME := $(basename $(wildcard *.md))
all: $(NAME).pdf $(NAME).docx
$(NAME).pdf: $(NAME).md
pandoc \
<(sed 's/^$$$$.*/\\placeformula\n&/' $<) \
--smart --output=$(NAME).tex --to=context
context $(NAME).tex
$(NAME).docx: $(NAME).md
pandoc $< --smart --output=$(NAME).docx