Bopytex/opytex/texenv.py

56 lines
1.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# encoding: utf-8
import jinja2, os
2015-05-16 08:42:39 +00:00
__all__ = ["texenv"]
# Definition of jinja syntax for latex
texenv = jinja2.Environment(
block_start_string = '\Block{',
# Gros WTF!! Si on le met en maj ça ne marche pas alors que c'est en maj dans le template...
block_end_string = '}',
variable_start_string = '\Var{',
variable_end_string = '}',
2016-11-18 15:09:25 +00:00
line_statement_prefix = '%-',
line_comment_prefix = '%#',
2014-11-21 16:20:04 +00:00
loader = jinja2.FileSystemLoader(os.path.abspath('.')),
extensions = ['jinja2.ext.do']
)
# Filters
2015-02-08 16:04:05 +00:00
def do_calculus(steps, name = "A", sep = "=", end = "", joining = " \\\\ \n"):
"""Display properly the calculus
2015-02-08 16:04:05 +00:00
Generate this form string:
"name & sep & a_step end joining"
:param steps: list of steps
:returns: latex string ready to be endbeded
2015-04-23 13:48:38 +00:00
"""
2015-02-08 16:04:05 +00:00
ans = joining.join([name + " & " + sep + " & " + str(s) + end for s in steps])
return ans
2015-03-19 21:05:00 +00:00
texenv.filters['calculus'] = do_calculus
2015-03-19 21:05:00 +00:00
from random import shuffle
texenv.filters['shuffle'] = shuffle
if __name__ == '__main__':
from pymath.expression import Expression
exp = Expression("2/4 + 18")
print(do_calculus(exp.simplify()))
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
# cursor: 16 del