diff --git a/DS_gene.py b/DS_gene.py index e061c1d..d4d958e 100755 --- a/DS_gene.py +++ b/DS_gene.py @@ -8,7 +8,14 @@ import csv from path import path from texenv import texenv -from pymath.random_expression import RdExpression +from pymath.expression import Expression +from pymath.polynom import Polynom +from pymath.fraction import Fraction + +pymath_tools = {"Expression":Expression,\ + "Polynom":Polynom,\ + "Fraction":Fraction,\ + } def main(options): #template = report_renderer.get_template(options.template) @@ -45,7 +52,7 @@ def main(options): dest = path(str(infos['num']) + output) tmp_pdf.append(dest.namebase + ".pdf") with open( dest, 'w') as f: - f.write(template.render( RdExpression = RdExpression , infos = infos)) + f.write(template.render( infos = infos, **pymath_tools )) if not options.no_compil: os.system("pdflatex " + dest) diff --git a/example/1_example.tex b/example/1_example.tex new file mode 100644 index 0000000..a48e693 --- /dev/null +++ b/example/1_example.tex @@ -0,0 +1,113 @@ +\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} +% \quatreC \quatreD \troisB \troisPro +\classe{\troisB} +\date{26 septemble 2013} +% DS DSCorr DM DMCorr Corr +\typedoc{DS} +\duree{1 heure} +\sujet{} + + +\begin{document} +\maketitle + +\Calc +Le barème est donné à titre indicatif, il pourra être modifié. + +\begin{Exo}[4.5] + + + + + Développer et réduire les expressions suivantes: + \begin{eqnarray*} + A &=& \frac{ 1 }{ 2 } + 2 \\ + P(x) &=& 6 x - 2 \\ + Q(x) &=& 4 x + 11\\ + R(x) &=& ( 6 x - 2 ) \times ( 4 x + 11 ) + \end{eqnarray*} + + Solutions: + \begin{eqnarray*} +A & = & \frac{ 1 }{ 2 } + 2 \\ +A & = & \frac{ 1 \times 1 }{ 2 \times 1 } + \frac{ 2 \times 2 }{ 1 \times 2 } \\ +A & = & \frac{ 1 + 4 }{ 2 } \\ +A & = & \frac{ 5 }{ 2 } +\end{eqnarray*} + + \begin{eqnarray*} +P(2) & = & 6 \times 2 - 2 \\ +P(2) & = & 12 - 2 \\ +P(2) & = & 10 +\end{eqnarray*} + + \begin{eqnarray*} +Q(2) & = & 4 \times 2 + 11 \\ +Q(2) & = & 8 + 11 \\ +Q(2) & = & 19 +\end{eqnarray*} + + \begin{eqnarray*} +P(x) + Q(X) & = & 6 x + 4 x - 2 + 11 \\ +P(x) + Q(X) & = & ( 6 + 4 ) x + ( -2 ) + 11 \\ +P(x) + Q(X) & = & 10 x + 9 +\end{eqnarray*} + + \begin{eqnarray*} +P(x) + Q(X) & = & 6 x - 2 + 4 x + 11 \\ +P(x) + Q(X) & = & 4 x + 6 x + 11 - 2 \\ +P(x) + Q(X) & = & ( 4 + 6 ) x + 11 + ( -2 ) \\ +P(x) + Q(X) & = & 10 x + 9 +\end{eqnarray*} + + \begin{eqnarray*} +R(x) & = & ( 6 x - 2 ) \times ( 4 x + 11 ) \\ +R(x) & = & 6 \times 4 x^{ 2 } + ( -2 ) \times 4 x + 6 \times 11 x + ( -2 ) \times 11 \\ +R(x) & = & 6 \times 4 x^{ 2 } + ( ( -2 ) \times 4 + 6 \times 11 ) x + ( -2 ) \times 11 \\ +R(x) & = & 24 x^{ 2 } + ( ( -8 ) + 66 ) x - 22 \\ +R(x) & = & 24 x^{ 2 } + 58 x - 22 +\end{eqnarray*} + + +\end{Exo} + +\begin{Exo} + + Résoudre l'équation suivante + \begin{eqnarray*} + 3 x^{ 2 } + x + 10 & = & 0 + \end{eqnarray*} + + Solution: + + On commence par calculer le discriminant + \begin{eqnarray*} + \Delta & = & b^2-4ac + \end{eqnarray*} + + \begin{eqnarray*} +\Delta & = & 1^{ 2 } - 4 \times 3 \times 10 \\ +\Delta & = & 1 - 12 \times 10 \\ +\Delta & = & 1 - 120 \\ +\Delta & = & -119 +\end{eqnarray*} + + + Alors $\Delta = -119$ + + +\end{Exo} + + +\end{document} + +%%% Local Variables: +%%% mode: latex +%%% TeX-master: "master" +%%% End: + + \ No newline at end of file diff --git a/example/all_example.pdf b/example/all_example.pdf new file mode 100644 index 0000000..847f353 Binary files /dev/null and b/example/all_example.pdf differ diff --git a/example/tpl_example.tex b/example/tpl_example.tex index f2599b0..f34bb01 100644 --- a/example/tpl_example.tex +++ b/example/tpl_example.tex @@ -19,21 +19,49 @@ Le barème est donné à titre indicatif, il pourra être modifié. \begin{Exo}[4.5] - \Block{do RdExpression.set_form("exp")} - \Block{set A = RdExpression("{a} / 2 + 2")()} - \Block{set B = RdExpression("{a} / 2 + 4")()} + \Block{set A = Expression.random("{a} / 2 + 2")} + \Block{set P = Polynom.random(["{b}","{a}"])} + \Block{set Q = Polynom.random(["{b+2}","{a}"])} + \Block{set R = P('x')*Q('x') } Développer et réduire les expressions suivantes: - \begin{equation*} - A = \Var{ A } \\ - B = \Var{ B } - \end{equation*} + \begin{eqnarray*} + A &=& \Var{ A } \\ + P(x) &=& \Var{ P } \\ + Q(x) &=& \Var{ Q }\\ + R(x) &=& \Var{R} + \end{eqnarray*} Solutions: \Var{A.simplify() | calculus} - \Var{B.simplify() | calculus(name = "B")} + \Var{P(2).simplify() | calculus(name = "P(2)")} + \Var{Q(2).simplify() | calculus(name = "Q(2)")} + \Var{(P+Q) | calculus(name = "P(x) + Q(X)")} + \Var{(P('x')+Q('x')).simplify() | calculus(name = "P(x) + Q(X)")} + \Var{R.simplify() | calculus(name = "R(x)")} \end{Exo} +\begin{Exo} + \Block{set P = Polynom.random(["{a}", "{b}", "{c}"])} + Résoudre l'équation suivante + \begin{eqnarray*} + \Var{P} & = & 0 + \end{eqnarray*} + + Solution: + + On commence par calculer le discriminant + \begin{eqnarray*} + \Delta & = & b^2-4ac + \end{eqnarray*} + \Block{set Delta = Expression("{b}^2 - 4*{a}*{c}".format(a = P._coef[2], b = P._coef[1], c = P._coef[0]))} + \Var{Delta.simplify()|calculus(name="\\Delta")} + \Block{set Delta = Delta.simplified()} + Alors $\Delta = \Var{Delta}$ + + +\end{Exo} + \end{document} diff --git a/texenv.py b/texenv.py index 8b90f3f..e2b3008 100644 --- a/texenv.py +++ b/texenv.py @@ -25,7 +25,7 @@ def do_calculus(steps, name = "A"): """ ans = "\\begin{eqnarray*}\n" - ans += " \\\\ \n".join([name + " & = & " + s for s in steps]) + ans += " \\\\ \n".join([name + " & = & " + str(s) for s in steps]) ans += "\n\\end{eqnarray*}\n" return ans