I got the following errors when compiling the following MWE. How to fix it?
Paragraph ended before
\verbatim@was complete. ...
First MWE
\documentclass{article}
\usepackage{sagetex}
\newcount\i
\i=10
\begin{document}
\loop
%==================== BEGIN ===========================
\begin{sageblock}
f(x) = exp(x) * sin(\i*x)
\end{sageblock}
The second derivative of $f$ is
\[
\frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
\sage{diff(f, x, 2)(x)}.
\]
Here's a plot of $f$ from $-1$ to $1$:
\begin{center}
\sageplot{plot(f, -1, 1)}
\end{center}
%=================== END ==============================
\advance \i -1
\ifnum \i>8
\repeat
\end{document}
Second MWE
% secondMWE.tex
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{sagetex}
\newcount\i
\i=10
\begin{document}
\loop
\begin{preview}
\sageplot[width=0.75\linewidth]{plot(sin(\the\i*x),x,0,2*pi)}
\end{preview}
\advance \i -1
\ifnum \i>7
\repeat
\end{document}
The expected output shows 3 sine plots with different frequencies.
Edit
Having read the existing answers, I come with the following idea which might be not difficult for TeX experts to implement. For the sake of simplicity, let me use the second MWE (secondMWE.tex).
The building process takes 4 steps instead of 3 steps.
First, do
pdflatex secondMWE, a new complete TeX file, for examplesecondMWE_complete.tex, is generated behind the scene. It contains something like% secondMWE_complete.tex \documentclass[preview,border=12pt,12pt]{standalone} \usepackage{sagetex} \begin{document} \begin{preview} \sageplot[width=0.75\linewidth]{plot(sin(10*x),x,0,2*pi)} \end{preview} \begin{preview} \sageplot[width=0.75\linewidth]{plot(sin(9*x),x,0,2*pi)} \end{preview} \begin{preview} \sageplot[width=0.75\linewidth]{plot(sin(8*x),x,0,2*pi)} \end{preview} \end{document}- Second, do
pdflatex secondMWE_complete - Third, do
sage secondMWE_complete.sagetex.sage - Fourth, do
pdflatex secondMWE_complete.texagain
- Second, do



