# Strange result when trying to use sagetex

As a result of another question I'm trying to use Sagetex. I performed the install as directed, and even got the compile to succeed, insofar as there are no fatal errors, but it appears that sagetex isn't actually parsing anything in sage like it should.

\begin{sagesilent}
var("x") #test
Integer(randint(1,4))
a = Integer(randint(2,7))*x+Integer(randint(2,7))
b = Integer(randint(2,7))*x+Integer(randint(2,7))
\end{sagesilent}

This is a test
$(\sage{a})(\sage{b}) = \sage{expand(a*b)}$


Compiles into

This is a test
(??)(??)=??


So it seems like the variable x, and the "a" and "b" are not actually staying defined (or maybe not being defined in the first place).

In contrast, the exact same code in sagecloud defines 2 binomials perfectly fine, then expands them like it should.

The only error I get from latex is "LaTeX Warning: Reference `@sageinline0' on page 1 undefined on input line 120." about 3 times.

For what it's worth I'm using Texmaker as my editor.

• I've not used sagetex, but this sounds like the kind of error you see when you need to compile multiple times to get references right. Have you tried that? – Ethan Bolker Jun 22 '15 at 1:39
• It does look exactly like that type of error, which is why I tried that first... sadly with no luck. – Jason Jun 22 '15 at 1:41
• Compilation is 3 step steps. First run LaTeX on your file. In addition to creating the log file you also end up with a .sage file. You've got to compile that file with Sage . Then the third step is to run LaTeX on the LaTeX file. That slow process can be sped up in some IDE's; for example with Kile, discussed here. The easiest way is to use Sagemath Cloud and one click of Sage does everything. If you've done 3 step process try this – DJP Jun 22 '15 at 1:57
• I'm not sure I understand your comment. Are you saying I have to hit compile on the Latex side. Then load up the sage file and hit compile on that. Then reload the doc in my latex editor and compile again? – Jason Jun 22 '15 at 2:07
• Yes. But you aren't compiling the .sage file with LaTeX, you compile with Sage. Processing with Sage performs the calculations. Running LaTeX the final time works the calculations in. Slow, unless you've configured an IDE to chain the commands together so one click does the work. See the link to the Kile question. – DJP Jun 22 '15 at 2:11