For the sake of illustration, I want to plot three functions:
- linear with direct
\sageplotinvocation, - quadratic with
\sagestr - and sinusoidal with
\sageplot
However, it seems that the \sagestr does not produce any output. Morever, it sabotages the output of the code that follows. What is wrong?
\documentclass{article}
\usepackage{sagetex}
\usepackage[a6paper,margin=2mm]{geometry}
\begin{document}
\section*{Linear}
\sageplot[width=4cm]{plot(x,-2,2)}
\section*{Quadratic}
\begin{sagesilent}
o = "\sageplot[width=4cm]{plot(x^2,-2,2)}"
\end{sagesilent}
% It does not produce plot but it sabotages one produced by the following.
\sagestr{o}
% the following output is sabotaged by the \sagestr above.
\section*{Sinusoidal}
\sageplot[width=4cm]{plot(sin(x),-2,2)}
\end{document}
Edit
Actually I want to compile the following but I fails. The previous code above is the minimal of the following.
\documentclass{article}
\usepackage{sagetex}
\begin{document}
%==================== BEGIN ===========================
\begin{sagesilent}
output = r""
for i in range(10,7,-1):
f(x) = exp(x)*sin(i*x)
output += r"The function is $f(x)= %s$."%(latex(f(x)))
output += r" The second derivative of $f(x)$ is \[ \frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} %s = %s.\]"%(latex(f(x)),latex(diff(f, x, 2)(x)))
output += r"Here's a plot of $f$ from $-1$ to $1$:\\"
output += r"\begin{center}"
output += r"\sageplot[width=8cm]{plot(%s,-1,1)}"%(f(x))
output += r"\end{center}"
output += r"\vspace{.15in}"
\end{sagesilent}
%=================== END ==============================
\sagestr{output}
\end{document}





\sagestrwrong. The manual states that this function can be used for functions that return LaTeX code in Sage. The example file contains\sagestr{pascals_triangle(n)}, wherepascals_triangleis a function that contains a lot of statements similar tos.append(r"\end{tabular}"). Yourovariable on the other hand does not call a Sage function that produces LaTeX code, but the variable contains LaTeX code itself - and worse still, LaTeX code that actually calls Sage again. So it's all very confusing. – Marijn Jun 10 '20 at 15:34\sageplotcommand in the output, which is not visible for the first pass of sagetex. So it would probably be more straightforward to write the for loop in LaTeX, and within that loop first call\sagestrfor the four first lines of the loop, then call (back in the LaTeX command) the\sageplotpart and then resume the LaTeX loop for the next plot. – Marijn Jun 10 '20 at 18:14