Showdown KaTeX With mhchem

mhchem support for Showdown-KaTeX

Background

I’ve written about bringing user-defined KaTeX macros into Hugo a few years ago. Looking back, I realized that I only knew how to copy code at that time.

Goal

  1. To replace the current code for my math editor with Showdown-KaTeX.
  2. To bring mhchem into my LaTeX + Markdown sandbox.

Motivation

To get the benefits of the three free (as in “freedom”) technologies.

  1. Markdown syntax is (much) simple(r than its LaTeX equivalent, especially for tables, ordered/unordered lists, etc).
  2. LaTeX syntax for math is, in the long run, worth learning, so that your fingers can stay on the keyboard while editing math expressions.
  3. mhchem allows writing chemical equations conveniently as in the previous point.

However, Rattle has pointed out the difficulties of mixing LaTeX and Markdown syntax. In his proposed solution for WordPress, he first renders KaTeX before moving to Markdown. He has provided an example use case with a dollar sign $ in a normal Markdown content (e.g. An apple costs $1.5.)

[Read More]

Katex Boxed Equations

Goal

To render a bordered box with multiple equations.

Background

My previous article about dot products contains some boxed math expressions: some are inline and some take up the whole line.

For inline math, that’s simple: either $\fbox{text}$ or $\boxed{a=1}$ will do. For displayed math, these two KaTeX commands will ignore the newline command \\.

Solution

A simple Google search ‘“katex” AND “box”’ saved the day. It led me to this relevant Stack Overflow question, whose accepted answer suggested the use of custom CSS. I copied the CSS class name boxedmath for my blog.

[Read More]
KaTeX  CSS 

Improved Integration of Hugo and $\KaTeX$

Problem

There’s no custom $\KaTeX$ macro in local preview since I’ve merged some recent commits from the upstream of this blog’s theme, in particular, Beautiful Hugo’s pull requests #246 and #255, which allowed self-hosting the theme’s static JS, CSS and font files. This self-hosted option is particularly useful in case of slow response from Cloudflare’s CDN.

hugo local preview no KaTeX macro

public Hugo blog KaTeX auto-renderer error

Even they do appear on the public GitLab site, the final rendered Markdown + $\TeX$ code would be succumb to syntax errors due to their absence in the preview process.

[Read More]
KaTeX  Mmark  Hugo 

Custom $\KaTeX$ Macros

More efficient math editing

Background

Same as the last section in Beautiful Hugo Improvements.

Goal

To write math efficiently by automatically loading longer code with shorter macro code.

For example, when I wrote Some Infinite Cardinality Identities, it would be ten times more quicker and efficient to type \card{C} than to write \mathop{\mathrm{card}}(C) all the time.

Changes committed to my repo

The current version of Beautiful Hugo is still using $\KaTeX$ v0.7, which doesn’t support macros in auto-rendering. It would be inconvenient to include the macros after invoking $\KaTeX$’s render function.

[Read More]
Hugo  KaTeX  math