Getting LaTex formulas to appear in WordPress with Katex

Well, there are two good options:

  1. Use the Unicode characters for mathematics in simple one-line formulas and then add the Greek keyboard for things like pi or π by using the Globe icon 🌐 to switch to Greek and type a p. On a Mac, you get these with CTRL-CMD-Space or ⌃-⌘-Space and then go to the search bar and look for things like superscript to find the square symbol so to the formula for the area of a circle is 𝐀=πr²or if you want to use WordPress direction, click on the down arrow in the toolbar and it has superscripts (and subscripts for that matter).
  2. But if you have a more complicated formula like the quadratic equation, you need a real equation editor like LaTex. It’s obscure but it is what everyone uses. LaTeX itself is a set of macros on top of TeX and is pretty complicated to learn.
  3. You can use the WP QuickLaTeX plug-in which you can access by adding a Shortcode block and then typing the pragma [latexpage]. But sadly this was last updated two years ago and you get null images when you run it. This plugin basically looks abandoned
  4. If you only need inline equations use MathJax-LaTeX which supports LaTex or MathML and allows direct inline equations without needing a shortcode block just by using the shortcode. This one also seems abandoned as it only supports the older MathJax 1.0 and I had trouble getting it to accept things lie aligned blocks. It seems mainly useful for single equations in the text.
  5. Katex (a fast variant of Latex) has a plugin that has a native Gutenberg block editor which is nice and it handles multi-line LaTeX well. For backward compatibility, it processes the [ latex ] shortcodes as well. But most importantly it allows a dynamic preview of LaTex in the Gutenberg block so it is a big winner.
  6. In terms of usages, I would normally use a Gutenberg block for KaTex as that gives you a fully new layout, but if you have an inline formula, then using:
Here is the Einstein equataion [katex]E=mc^2[/katex]

Here is the equation if you want dynamic preview then it is [katex display=true]A=2 \pi r^2[/katex]

Then there is learning LaTex (or KaTex itself):

  1. LaTeX itself (see Equplus for common equations) which is basically stuff like this where the LaTex commands are denoted by a backslash or reverse solidus (which is the technical name for a slash which is the Latin name for shilling mark when the English shilling mark when this obsolete really long-s was just turned into a diagonal line which has the Unicode character U+017F or Å¿ which definitely doesn’t look like much), aka an oblique in the 18th century)
  2. Here are some quick starts on writing LaTex, the ampersand means this is where all the equations should be aligned and the \ means a line break and then int means an integral, frac is how you get a fraction with the parenthesized things being the numerator and the denominator:
[latex]G(x) = \frac{1}{3}x^3[/latex]

# this does not parse correctly with Katex but does with Latex
[latex]begin{array}{*{20}c} {x = frac{{ - b pm sqrt {b^2 - 4ac} }}{{2a}}} & {{rm{when}}} & {ax^2 + bx + c = 0} \ end{array}[/latex]

# only katex deals with this correctly
C &= 2 \pi r
A &= \pi r^2

# to write this as a single block its a mess because 
# you cannot use new lines and this works with Quick but not Katex
[latex]begin{align}{*{20}c} {x = frac{{ - b pm sqrt {b^2 - 4ac} }}{{2a}}} & {{rm{when}}} & {ax^2 + bx + c = 0} \ end{align}[/latex]

# For Katex

So if you want the equation to be set out, then create a shortcode block like this by adding a shortcode if you want to edit it easily, but you can also enter the text above directly and it works, note that

E=mc^2 G(x) = \frac{1}{3}x^3 E=mc^2 \begin{aligned} C &= 2 \pi r \\ A &= \pi r^2 \end{aligned}

Here are the same formula with an Insert Shortcode block:

E=mc^2 G(x) = \frac{1}{3}x^3

Now, this is a dynamic Katex block:

E=mc^2 \\
G(x) = \frac{1}{3}x^3 \\

Here is one that uses alignment and begin blocks. Note that if you are doing this you can’t have bare formulas, they all need to be in blocks and this works great, so it’s a winner

C &= 2 \pi r \\
A &= \pi r^2 \\
G(x) = \frac{1}{3}x^3
E = mc^2

I’m Rich & Co.

Welcome to Tongfamily, our cozy corner of the internet dedicated to all things technology and interesting. Here, we invite you to join us on a journey of tips, tricks, and traps. Let’s get geeky!

Let’s connect