Kerl13 / AsciiMath

Compiler from asciimath to LaTeX
MIT License
8 stars 2 forks source link

Build Status

AsciiMath

AsciiMath is a compiler from the amazing AsciiMath language to LaTeX.

The aim of that project is to provide a Haskell Library and a command line tool making possible to use asciimath everywhere, for example in interaction with pandoc or for preprocessing on your website.

Install

Use stack.

If you already have stack set up and working, you just have to type stack install at the root of the repository.
If you want the binaries to be stored in a different folder from the default $HOME/.local/bin/ you should add the option --local-bin-path $YOUR_BIN_DIR.

If you just installed stack, stack may ask you to run stack setup first to install GHC and set up an isolated environment (either globally in your home or in a dedicated folder just for this repository)

Usage

The executable asciimath reads AsciiMath code from its standard input, compile it and prints the resulting LaTeX code on its standard output. For example:

> echo "sum_(i=1)^n i^3=((n(n+1))/2)^2" | ./asciimath
\sum_{i=1}^{n}i^{3}=\left(\frac{n\left(n+1\right)}{2}\right)^{2}

or in "interactive mode"

> asciimath
sin(2x) = 2sin(x)cos(x) ^D
\sin \left(2x\right)=2\sin \left(x\right)\cos \left(x\right)

The executable pandoc-asciimath is a pandoc filter. An example of use would be

> pandoc --standalone -t latex --filter pandoc-asciimath file.md -o file.pdf

The Asciimath module also provide four functions:

which can be used in any Haskell program to play with the AST or anything else.

The run function do the same work as compile but raises a system error if it fails whereas compile returns either a LexicalError or the expected compiled String which is much more convenient for error handling.

Grammar

Here is the grammar used to parse AsciiMath. It is a little different from the original one defined here but I think the changes I made respect the original idea.

c ::= [a-zA-Z] | numbers | greek letters | standard functions | , | other symbols (see list)

u ::= sqrt | text | bb | bbb | cc | tt | fr | sf | hat | bar | ul | vec | dot | ddot

b ::= frac | root | stackrel

l ::= ( | [ | { | (: | {:

r ::= ) | ] | } | :) | :}

S ::= c | l Code r | u S | b S S | " any text "

E ::= S | S / S | S _ S | S ^ S | S _ S ^ S

Code ::= [ E ]

Rendering rules

Delimiters

Left and right delimiters are preceded by the \left and \right commands to be well-sized. (: and :) are chevrons. {: and :} are invisible delimiters like LaTeX's {. The other delimiters are rendered as expected.

Useless delimiters are automatically removed in expressions like

If you want them to be rendered, you have to double them, for example : ((x+y))/2 or {: (x+y) :}/2

Matrices

An expression of the form ((a,b),(c,d),(e,f)) is interpreted and rendered as a matrix. More precisely :

License

The code of AsciiMath is released under the MIT license