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.

var("x") #test
a = Integer(randint(2,7))*x+Integer(randint(2,7))
b = Integer(randint(2,7))*x+Integer(randint(2,7))

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.

  • 1
    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? Jun 22, 2015 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, 2015 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, 2015 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, 2015 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, 2015 at 2:11

1 Answer 1


Unless you have an IDE programmed to compile the document with 1 click, it's a 3 step process: Step 1: Process your file with LaTeX. This produces a .sage file enter image description here Step 2: Compile the .sage file using Sage. That means getting the terminal open for Sage. Make sure you've changed to that directory (cd). Type load("MyFile.sagetex.sage") and press return. This performs the calculations and creates more files (eg .sout) enter image description here Step 3: process the .tex file with LaTeX

If you've done this and things still aren't working, it could be that Sage and LaTeX aren't talking to each other. See this page for more information.

  • This was exactly it, thanks! Do you happen to know why I get the missing latexmk.sty file error when I try to use latexmk? Google doesn't seem to have anything about the sty file, and it doesn't appear to be in the package download.
    – Jason
    Jun 22, 2015 at 3:03
  • I don't know much about latexmk.sty but I did a little searching and found this.
    – DJP
    Jun 22, 2015 at 13:42
  • I spent several hours trying to get it to work with Texmaker, and still haven't figured out how to integrate latexmk to get it to auto compile correctly. I really like Texmaker's interface and editing options, but at this point I may move to sagemath cloud since I can't seem to figure out how to get Texmaker to work.
    – Jason
    Jun 22, 2015 at 13:59
  • This link confirms that the link I gave above works with TeXmaker. If you're unable to get it to work, you should try posting for a clarification on AskSagemath.
    – DJP
    Jun 22, 2015 at 14:06
  • 1
    @Jason Key step was to configure one of the commands (eg metapost) to activate Sage. Then defined Quickbuild to run pdflatex, Sage, pdflatex, and pdfViewer. I don't know basics of latexmk. See if you can run as I did. If you can't post a question and I'll walk through what I did with screenshots.
    – DJP
    Jun 23, 2015 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.