Skip to content

A simpler syntax for math typesetting written in go, converts to LaTeX math

License

Notifications You must be signed in to change notification settings

anonx3247/mathlang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mathlang

By: Neosapien

This project aims to create a much lighter and more orthogonal syntax for mathematical writing on the computer instead of trying to replace LaTeX as a typesetting system, mathlang aims only to change they syntax.

Thus mathlang converts its own syntax to pure math latex code, allowing you to write in something readable and comfortable while always allowing you to change to a syntax understood by every math typesetting program wether it be Latex, Markdown, HTML, or other.

Installation

(Note: this will run only on Linux/MacOS/Unix (i.e. not windows))

You need the go language installed as well as git (this should already be installed on MacOS)

Open a terminal and run:

git clone https://github.com/neosapien3247/mathlang
cd mathlang

To test it out run:

make

To install run:

sudo make install

(Note: while testing, the binary has to be in the same directory as syntax_regexp.json to find it)

Usage

Brief Presentation

Here you can see a few examples of what mathlang is capable of:

Vectors, hats, and column vectors

Mathlang
u^{->} : [{ i^{^}; j^{^}}] 
LaTeX
\overrightarrow{u} : \left[\begin{matrix} \hat{i}\\ \hat{j}\end{matrix}\right] 

Sets, / alternate symbols

Mathlang
RR^{_} = RR cup \{+- inf\}
LaTeX
\overline{\mathbb{R}} = \mathbb{R} \cup \{\pm \infty\}

Sums, fractions, matrices (\binom)

Mathlang
sum_{k=0}^n ({n;k}) ( alpha/beta )^{n-k} ( gamma/delta )^k = ( alpha/beta + gamma/delta )^n
LaTeX
\sum_{k=0}^n \left(\begin{matrix}n\\k\end{matrix}\right) \left( \frac{\alpha}{\beta}
\right)^{n-k} \left( \frac{\gamma}{\delta} \right)^k =
\left( \frac{\alpha}{\beta} + \frac{\gamma}{\delta} \right)^n

Matrices

Mathlang
A = ({a,b,c;d,e,f;g,h,i})
LaTeX
A = \left(\begin{matrix}a & b & c\\d & e & f\\g & h & i\end{matrix}\right)

Dependencies

This uses standard go libraries so it doesn't need particular dependencies, simply install go.

Installation

git clone https://github.com/neosapien3247/mathlang
cd mathlang

Then to build run:

make

and to install to /usr/local/bin run

sudo make install

Syntax

See the wiki for syntax

Usage

mathlang -e "expression"

This will output the "translation" of the expression into \LaTeX

... | mathlang -

This will output the STDIN translated into \LaTeX This can be very useful in certain editors for example, kakoune by piping the content of a line and binding it, you can translate mathlang to \LaTeX on the fly in one keystroke.

mathlang -d

This allows you to only convert what is between delimiters for mathlang code, thus allowing you to pipe an entire file into the converter and only change things between the delimiters. (the delimiters are $$)

This allows mathlang to be used as a preprocessor, e.g:

mathlang -df "myfile.md" | pandoc -o myfile.pdf

Examples

Here are a few examples of the benefits of this system:

No more backslashes

forall x in A, exists y in B
\forall x \in A, \exists y \in B
sin^2 theta + cos^2 theta = 1
\sin^2 \theta + \cos^2 \theta = 1

Intelligent, elegant fractions

5/3 , 2 + {2 - 6t}/{3+8m}, {-3 + 5}/2c+6 a+b/c
\frac{5}{3} , 2 + \frac{2 - 6t}{3+8m}, \frac{-3 + 5}{2c+6} \frac{a+b}{c}

They even handle fractions of fractions:

varphi = 1 + 1/{1 + 1/{1 + 1/{1 + ...}}}
\varphi = 1 + \frac{1}{1 + \frac{1}{1 + \frac{1}{1 + \cdots}}}

Smart annotations

Wether its vectors, conjugates, or hats, mathlang has better syntax!

a^{^}, b^{_}, c^{->}, d^{~}
\hat{a}, \overline{b}, \overrightarrow{c}, \tilde{d}

Automatically takes the best choices

Parenthesis are already chosen to be the size-adjusting type, wether you need them or not:

(a+b)
\left(a+b\right)

Also note that this works for pipes | but with specific rules:

  1. pipes that are surrounded by whitespace do not get changed and stay as |
  2. if pipes are stuck only on one side to non whitespace they get changed
  3. if there is no whitespace the pipes will not be changed.
5 + |-3| = 8
5 + \left|-3\right| = 8
\{ x^2 | x in RR \}
\left\{ x^2 | x \in \mathbb{R} \right\}

Simple, memorable shortcuts

forall n in NN^{*}, forall x in RR, x >= 1 => |x^n| >= x
\forall n \in \mathbb{N}^{*}, \forall x \in \mathbb{R}, x \ge 1 \implies |x^n| \ge x
RR^{_} = RR cup \{ +- inf\}
\overline{\mathbb{R}} = \mathbb{R} \cup \{ \pm \infty\}

Matrices, made easy

A = (&{a,b,c;d,e,f;g,h,i})
A = \left(\begin{matrix} a & b & c \\ d & e & f \\ g & h & i \end{matrix}\right)

It can also be good for other formatting:

(a+b)^n = sum_{k=0}^n (&{n;k}) a^k b^{n-k}
\left(a+b\right)^n = \sum_{k=0}^n \left(\begin{matrix} n \\ k \end{matrix}\right) a^k b^{n-k}

Case statements

@{ f : RR, -> RR; x, |-> x^2}
\begin{cases}  f : \mathbb{R} &  \to \mathbb{R} \\  x &  \mapsto x^2 \end{cases}

You can test it out yourself with the test file (test.md) to get the test.pdf output with pandoc

About

A simpler syntax for math typesetting written in go, converts to LaTeX math

Resources

License

Stars

Watchers

Forks

Packages

No packages published