AsciiMathToLatex takes a math equation written in AsciiMath as input and converts it into valid LaTeX source. The tool first parses the AsciiMath input, outputting syntax errors as they are encountered. It then generates an AST representing the equation which is converted into LaTeX math notation and output as text to the console.
The purpose of the project is to allow for a simpler, more readable syntax for math equations to be used with the superior typesetting abilities of LaTeX.
In terms of formatting, LaTeX is unparalleled for complex math equations. As such, it has become the industry standard and is widely used and supported throughout academia and in math-related fields. Personally, I've been using LaTeX for several years and continue to use it to format math equations and take notes.
However, the syntax to write these math equations is verbose, difficult-to-read, and slow to type. AsciiMath is a language that implements a subset of LaTeX's math functionality and is used for displaying math equations in HTML documents. It uses a much simpler syntax that prefers spaces and parentheses over braces and backslashes and saves the user keystrokes by requiring less explicit instructions.
All the source code for AsciiMathToLatex as well as all the documentation (including this document) were created using Literate, a tool for writing programs using the literate programming method. That means that the source code is contained alongside the documentation within the .lit
files. Running the Literate program will generate both the .swift
source files that make up the project and the HTML files that form the documentation. After the .swift
files are generated by Literate, the Swift compiler is used to create the executable.
Download and install Literate from their downloads page
- OS X users can install the swift compiler,
swiftc
, by installing Xcode and then runningxcode-select install
from Terminal - Linux users can install Swift from the compiler homepage
Run make
from the project directory.
The AsciiMathToLatex executable takes an equation written in AsciiMath notation as the first argument and prints out the converted LaTeX source code. For example, running:
./AsciiMathToLatex 'x/y + sqrt(beta)'
will output the following LaTeX code:
\frac{x}{y} + \sqrt{\beta}