Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The internal definition of the sagesilent environment involves the use of verbatim text, which never can be written in a macro argument. The same kind of problem arises if you try something like

   Some verbatim text

As a workaround, you can move to an auxiliary tex file all the code needed to config SageTeX. Then you can input that file in the argument of \AtBeginDocument. For example, let the contents of examplepackage.sty be

\ProvidesPackage{examplepackage}[2018/12/24 examplepackage]




The file exampleconfig.tex contains the code to set up SageTeX:

   # Set up some variables
   a = 3
   b = 5
   # Define a function
   g(x) = a*sin(x)+b*cos(x)


The main tex file could be




% Do something with a and b

The value of $a$ is $\sage{a}$, while that of $b$
is $\sage{b}$. Their sum is $\sage{a+b}$.

% Do something with the function

   gp(x) = diff(g(x),x)
   g_int(x) = integrate(g(x), x)

Let $g(x)=\sage{g(x)}$. It is easily seen that
   \int g(x)\,dx=\sage{g_int(x)}.

Observe also that $g'(2)\approx\sage{gp(2).n()}$.


Hope that helps.