Commit 08d8f67d authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

doc newcommand

parent cfe30efd
......@@ -29,7 +29,7 @@ LaTeX math to Unicode text converter
flatlatex is a basic converter from LaTeX math to human readable text math using
unicode characters.
Example:
Basic example:
>>> import flatlatex
>>> c = flatlatex.converter()
......@@ -37,6 +37,15 @@ Example:
... r'\\forall \\eta>0\\, \\exists n\\in\\mathbb{N}\\, \\forall i>n\\, |u_i-n|<\\eta')
'∀η>0 ∃n∊ℕ ∀i>n |uᵢ-n|<η'
Commands can be added with LaTeX syntax:
>>> import flatlatex
>>> c = flatlatex.converter()
>>> c.add_newcommand(r'\\newcommand\\prob{\\mathbb{P}}')
>>> c.add_newcommand(r'\\newcommand\\binom[2]{\\frac{#2!}{#1!(#2-#1)!}}')
>>> c.convert(r'\\prob(X=k)\\,=\\,\\binom{k}{n}\\times p^k(1-p)^{n-k}')
'ℙ(X=k) = (n!)/(k!(n-k)!)×pᵏ(1-p)ⁿ⁻ᵏ'
The behavior can be change:
>>> import flatlatex
......
......@@ -215,6 +215,15 @@ class converter:
return comb[1] + '(' + expr + ')'
def add_newcommand(self, one_newcommand):
"""Add a command definiton using LaTeX syntax.
:param expr: a valid \\newcommand (or \\renewcommand or \\def)
definition.
Examples:
- r'\\newcommand\\prob{\\mathbb{P}}'
- r'\\newcommand\\binom[2]{\\frac{#2!}{#1!(#2-#1)!}}'
"""
parsed = parser.parse(one_newcommand)
if not (len(parsed) in (3,6)):
raise LatexSyntaxError
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment