Showdown Math
Add beautiful math equations to your Markdown files! This repository contains a small Showdown extension. This extension turns Latex or AsciiMath in your markdown file into HTML tags. No JavaScript is needed to display the resulting equations. This extension relies on simple replacements using regular expressions, therefore escaping of the delimiters is not supported. This code is only tested outside the browser using Node version v10.1.0
.
Please report any issues!
Delimiters
To enter inline AsciiMath begin and end your text using a single percent sign: %. Non-inline math can be entered using two percent signs: %%. Likewise inline Latex can be inserted using a single dollar sign: $. Two dollar signs $$ will result in non-inline equations.
Example
Here is a step-by-step example showing how to generate some equations. Let us start with an example Markdown file. Let's name it example.md
.
This is a normal Markdown title==================================== But oh! A wild AsciiMath equation appears: % 3 y^2 z - 5 z - 6 y^2 + 10 = 0 %.You use factorization! It's super effective! The enemy turns into a non-inline Latex equation:$$(3y^2 + 5)(z - 2) = 0$$ Now the solution is most easily expressed in non-inline AsciiMath:%%y = pm sqrt(5/3) \ vee \ z = 2%%
We first need to install Showdown.
npm install -g showdown
You might need to use sudo to run this command. However, a way to install packages without using sudo is available. Next up we install this extension.
npm install -g showdown-math
We can now easily convert the example file to HTML.
showdown makehtml -e showdown-math -i example.md -o example.html
The resulting example.html file will look weird! The produced HTML contains only the body of the webpage. We still need to add a few other tags. We need to tell the browser the file is encoded in UTF-8 to make the Unicode characters work. Furthermore we need to link to the Katex CSS file. This way the equations will look good.
<!-- replace this line with the HTML produced by the last command -->
Now open the file using the best browser and enjoy!
Credits
This project depends on a number of great projects:
KaTeX - Server side rendering of Latex equations (thanks Khan Academy!)
Showdown - A Markdown to HTML converter written in Javascript
AsciiMath - An easy-to-write markup language for mathematics
asciimath-to-latex - AsciiMath to LaTex converter (based on asciimathml)
License
MIT