From c3474d4f17bb585c0942172cbe2ebbac99223bb5 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Mon, 17 Apr 2017 10:42:13 +0300 Subject: [PATCH] Add filter and create setup function --- opytex/filter.py | 31 ------------------------------- opytex/opytex.py | 27 ++++++++++++++++----------- 2 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 opytex/filter.py diff --git a/opytex/filter.py b/opytex/filter.py deleted file mode 100644 index 2aef9d5..0000000 --- a/opytex/filter.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 - -""" -Custom filter for Bopytex -""" - -def do_calculus(steps, name="A", sep="=", end="", joining=" \\\\ \n"): - """Display properly the calculus - - Generate this form string: - "name & sep & a_step end joining" - - :param steps: list of steps - :returns: latex string ready to be endbeded - - - """ - - ans = joining.join([ - name + " & " - + sep + " & " - + str(s) + end for s in steps - ]) - return ans - - -# ----------------------------- -# Reglages pour 'vim' -# vim:set autoindent expandtab tabstop=4 shiftwidth=4: -# cursor: 16 del diff --git a/opytex/opytex.py b/opytex/opytex.py index 05fbda4..a7a954c 100755 --- a/opytex/opytex.py +++ b/opytex/opytex.py @@ -13,6 +13,7 @@ import sys from path import Path import pytex import pymath +import opytex.filters as filters formatter = logging.Formatter('%(name)s :: %(levelname)s :: %(message)s') steam_handler = logging.StreamHandler() @@ -25,18 +26,20 @@ logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) logger.addHandler(steam_handler) -MAPYTEX_TOOLS = { - "Expression": pymath.Expression, - "Polynom": pymath.Polynom, - "Fraction": pymath.Fraction, - "Equation": pymath.Equation, - "random_str": pymath.random_str, - "random_pythagore": pymath.random_pythagore, - "Dataset": pymath.Dataset, - "WeightedDataset": pymath.WeightedDataset, - } +def setup(): + mapytex_tools = { + "Expression": pymath.Expression, + "Polynom": pymath.Polynom, + "Fraction": pymath.Fraction, + "Equation": pymath.Equation, + "random_str": pymath.random_str, + "random_pythagore": pymath.random_pythagore, + "Dataset": pymath.Dataset, + "WeightedDataset": pymath.WeightedDataset, + } + pytex.update_export_dict(mapytex_tools) -pytex.update_export_dict(MAPYTEX_TOOLS) + pytex.add_filter("do_calculus", filters.do_calculus) def get_working_dir(options): @@ -168,6 +171,8 @@ def produce_and_compile(options): def main(): + setup() + parser = optparse.OptionParser() parser.add_option( "-t",