LaTeX to Gutenberg conversion

Do any mathematicians read my blog? Perhaps one or two of my former math professors or classmates?

At work, I forked an old package that converts .tex files to WordPress-compatible HTML and updated it to generate modern Gutenberg markup for the WordPress block editor.

I’d love help testing it out and identifying the rough edges.

Here it is:

GitHub – a8cteam51/LaTeX2Gutenberg: A port of LaTeX2WP to work with Gutenberg
A port of LaTeX2WP to work with Gutenberg. Contribute to a8cteam51/LaTeX2Gutenberg development by creating an account on GitHub.
github.com

Here a PDF of the example.tex file in the repo generated from the popular pdflatex package, along with the generated Gutenberg output for comparison.


Look at the document source to see how to strike out text, how to use different colors, and how to link to URLs with snapshot preview and how to link to URLs without snapshot preview.

There is a command which is ignored by pdflatex and which defines where to cut the post in the version displayed on the main page

Anything between the conditional declarations ifblog . . . fi is ignored by LaTeX and processed by latex2wp. Anything between iftex . . . fi is processed by LaTex and ignored by latex2wp.

This green sentence appears only in WordPress

This is useful if one, in desperation, wants to put pure HTML commands in the ifblog . . . fi scope.

Lemma 1 (Main). Let {\cal F} be a total ramification of a compactifier, then

g.g2=η     (1)\forall g \in {\cal F}. g^2 = \eta \ \ \ \ \ (1)

The (modifiable) numbering scheme is that lemmas, theorems, propositions, remarks and corollaries share the same counters, while exercises and examples have each their own counter.

Theorem 2. The adèle of a number field is never hyperbolically transfinite.

Proof: Left as an exercise. \Box

Exercise 1. Find a counterexample to Theorem 2.

Exercise 2 (Advanced). Prove Lemma 1.

Note that accented characters are allowed. Unfortunately, Erd\H{o}s’s name cannot be properly typeset in HTML.

It is possible to have numbered equations

1x20     (2)\frac 1 {x^2} \ge 0 \ \ \ \ \ (2)

and unnumbered equations

t(x)12x13t(x) – \frac 12 \geq x^{\frac 13}

Unnumbered equations can be created with the double-dollar sign command or with the backslash-square bracket command.

f(x)=x1t2dtf(x) = \int_{-\infty}^{x} \frac 1 {t^2} dt

It is possible to refer to equations and theorems via the ref, eqref and label LaTeX commands, for example to Equation (2), to Equation (1), and to Lemma 1 above.

do not nest a {\bf bold text inside an emphasized text or viceversa.}

The theorem-like environments theorem, lemma, proposition, remark, corollary, example and exercise are defined, as is the proof environment.

The LaTex commands to type $, %, and & are supported.

It it is possible to have tabular environments, both with borders (the border will not be displayed in the LaTeX preview), as in

blog quality
what’s new excellent
in theory poor

and without borders as in

{a} {\rightarrow} {b}
{\downarrow} {\uparrow}
{c} {\rightarrow} {d}

(The tabular environments will be centered in WordPress, but not in the LaTeX preview.)

And it is possible to include a picture so that the pdf file produced with pdflatex imports it from a local image file (which has to be pdf, gif, jpeg, or png) and the WordPress post imports it from a URL.

The image command used to generate the above image has three parameter: a size parameter for either the width or the height, expressed in pixels (if different from the original resolution, the picture will be scaled), a URL for the location of the image (this will be used by WordPress) and a local file name (which will used by pdflatex).

It is possible to have numbered and unnumbered sections and subsections. References to label commands which are not in the scope of a numbered equation or a numbered theorem-like environment will refer to the section number, such as a reference to Section 1 below.

Examples of Sections

And Subsections

1. A section

1.1. And a subsection

2. Changing the style

The file latex2wpstyle.py contains several definitions that determine the appearance of the WordPress translation. It should be self-explanatory to change the way sections, subsections, proofs and theorem-like environments are typeset, and to change the numbering scheme for theorem-like environments.

The variable {M} in latex2wpstyle.py contains a list of pairs of strings. For every pair, every occurrence of the first string in the document is replaced by an occurrence of the second before proceeding to the conversion from LaTeX to WordPress. If you want to use simple macros (which do not involve parameter-passing) then edit {M} to add support for your own LaTeX macros. (You will have to define the macros in macrosblog.tex as well, otherwise you will not be able to compile your LaTeX file and preview it.)

Some macros are already defined. For example, backslash-E produces an expectation symbol:

𝔼xXf(x):=xX[x]f(x)\mathop{\mathbb E}_{x \in X} f(x) := \sum_{x\in X} \mathop{\mathbb P} [x] \cdot f(x)

Category:


Comments and Webmentions

2 responses to “LaTeX to Gutenberg conversion”

  • Chuck Grimmett
  1. I have been an avid LaTeX user for over 20 years. I have been using PlasTeX for the last 10 years or so to convert to html so I can post to my blog. I will try to find some time to give this a try.

Fediverse reactions

Leave a Reply

Webmentions

If you've written a response on your own site, you can enter that post's URL to reply with a Webmention.

The only requirement for your mention to be recognized is a link to this post in your post's content. You can update or delete your post and then re-submit the URL in the form to update or remove your response from this page.

Learn more about Webmentions.