split DS_gene from jinja2 config and start working on filters
This commit is contained in:
parent
3215838d55
commit
dee5ba4812
26
DS_gene.py
26
DS_gene.py
@ -1,20 +1,13 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import jinja2, random, os
|
||||
import os
|
||||
import sys
|
||||
import optparse
|
||||
from path import path
|
||||
from pymath.random_expression import RdExpression
|
||||
|
||||
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 = '}',
|
||||
loader = jinja2.FileSystemLoader(os.path.abspath('.'))
|
||||
)
|
||||
from texenv import texenv
|
||||
from pymath.random_expression import RdExpression
|
||||
|
||||
def main(options):
|
||||
#template = report_renderer.get_template(options.template)
|
||||
@ -42,10 +35,12 @@ def main(options):
|
||||
dest = path(str(subj) + output)
|
||||
with open( dest, 'w') as f:
|
||||
f.write(template.render( RdExpression = RdExpression , infos = {"subj" : subj}))
|
||||
#os.system("pdflatex " + dest)
|
||||
|
||||
#if not options.dirty:
|
||||
# os.system("rm *.aux *.log")
|
||||
if not options.no_compil:
|
||||
os.system("pdflatex " + dest)
|
||||
|
||||
if not options.dirty:
|
||||
os.system("rm *.aux *.log")
|
||||
|
||||
cwd.cd()
|
||||
|
||||
@ -53,10 +48,11 @@ if __name__ == '__main__':
|
||||
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option("-t","--tempalte",action="store",type="string",dest="template", help="File with the template. The name should have the following form tpl_... .")
|
||||
parser.add_option("-t","--template",action="store",type="string",dest="template", help="File with the template. The name should have the following form tpl_... .")
|
||||
parser.add_option("-o","--output",action="store",type="string",dest="output",help="Base name for output )")
|
||||
parser.add_option("-n","--number_subjects", action="store",type="int", dest="num_subj", default = 1, help="The number of subjects to make")
|
||||
parser.add_option("-N","--number_subjects", action="store",type="int", dest="num_subj", default = 1, help="The number of subjects to make")
|
||||
parser.add_option("-d","--dirty", action="store_true", dest="dirty", help="Do not clean after compilation")
|
||||
parser.add_option("-n","--no-compile", action="store_true", dest="no_compil", help="Do not compile source code")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
\documentclass[a4paper,10pt]{/media/documents/Cours/Prof/Enseignements/tools/style/classDS}
|
||||
\usepackage{/media/documents/Cours/Prof/Enseignements/2013_2014}
|
||||
\documentclass[a4paper,10pt]{/media/documents/Cours/Prof/Enseignements/Archive/2013-2014/tools/style/classDS}
|
||||
\usepackage{/media/documents/Cours/Prof/Enseignements/Archive/2013-2014/2013_2014}
|
||||
|
||||
% Title Page
|
||||
\titre{Calcul littéral et statistiques}
|
||||
@ -26,6 +26,10 @@ Le barème est donné à titre indicatif, il pourra être modifié.
|
||||
A = \Var{ A } \\
|
||||
B = \Var{ B }
|
||||
\end{equation*}
|
||||
|
||||
Solutions:
|
||||
\Var{A.simplify() | calculus}
|
||||
\Var{B.simplify() | calculus(name = "B")}
|
||||
\end{Exo}
|
||||
|
||||
|
||||
|
46
texenv.py
Normal file
46
texenv.py
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import jinja2, os
|
||||
|
||||
# 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 = '}',
|
||||
loader = jinja2.FileSystemLoader(os.path.abspath('.'))
|
||||
)
|
||||
|
||||
# Filters
|
||||
|
||||
def do_calculus(steps, name = "A"):
|
||||
"""Display properly the calculus
|
||||
|
||||
:param steps: list of steps
|
||||
:returns: latex string ready to be endbeded
|
||||
|
||||
"""
|
||||
ans = "\\begin{eqnarray*}\n"
|
||||
|
||||
ans += " \\\\ \n".join([name + " & = & " + s for s in steps])
|
||||
ans += "\n\\end{eqnarray*}\n"
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
texenv.filters['calculus'] = do_calculus
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user