I haven't found a way to pass parameters to a sagesilent environment, so I wonder if it's possible. My final purpose is to combine sagetex with probsoln. The package probsoln lets you manage a problem database, and this problems can take optional arguments. So when I call one of these problems, I want to pass its parameters right to sagetex to make the calculations.
I have prepared a MWE which is probsoln independent. It builds a polynom in sagetex, and what I would like is to change the definition of np=15 (inside sagesilent) for np=\np
If only I could manage how to expand every LaTeX macro inside sagesilent, this could be easily done. Actually, I think that this question could be formulated also independently of sage and sagetex, something like this: How to replace the macros inside an environment for its definition/value before processing the environment?
Any ideas?
The MWE:
\documentclass{article}%
\PassOptionsToPackage{T1}{fontenc}
\usepackage{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{sagetex}
\pagestyle{empty}
\begin{document}
\def\np{15}
\begin{sagesilent}
np=15 #grado del polinomio p
p1=0
pcoeffs=range(np+1)
x = var('x')
for i in range(np+1):
pcoeffs[i]= Integer(randint(-8,8))
p1=p1+pcoeffs[i]*x^i
\end{sagesilent}
\noindent This is a polynom of grade $\np$:
$\sage{p1}$
\end{document}
\sagestr. That's my usual strategy. – Dan Drake Apr 21 '15 at 16:03