2

According to the Make SageTeX known to TeX, the preferred way to let TeX know about SageTeX is to copy the tex folder found at SAGE_ROOT/local/share/texmf/tex (which in my OS X case is /Applications/Sage-6.4.1.app/Contents/Resources/sage/local/share/texmf/tex) into the value returned by running kpsewhich -var-value=TEXMFHOME in the shell, which in my case is /Users/chuck/Library/texmf.

I've done that, and now sagetex.sty (and many other files) are found at /Applications/Sage-6.4.1.app/Contents/Resources/sage/local/share/texmf/tex/generic/sagetex.

So I open the example.tex file (using TeXShop) also found in that generic folder and click the Typeset button. The PDF is generated and opened in TeXShop, but everywhere that should have the results of Sage operations instead has double question marks.

The console that appeared when I clicked Typeset has numerous errors, all of the same type:

LaTeX Warning: Reference `@sageinline0' on page 1 undefined on input line 40.
LaTeX Warning: Reference `@sageinline1' on page 1 undefined on input line 41.

Lines 40 and 41 look like this:

This is an example $2+2=\sage{2+2}$. If you raise the current year mod
$100$ (which equals $\sage{mod(\the\year, 100)}$) to the power of the

The PDF output at that point has the following text:

This is an example 2 + 2 = ??. If you raise the current year mod 100 (which equals ??) to the power of the

Other simple tests of both Sage and TeX have proven successful. For example, launching the Sage app and selecting "Terminal Session>Sage" correctly outputs 4 with input 2+2, and creating a very simple TeX document and running it using the latex command in the Terminal is also successful, so each of these seem to work separately without trouble.

What can I do to get them to work together?

  • 1
    In your post you said you compiled by pressing "Typeset". Using sagetex requires a 3fold process: latex the document, run Sage on the resulting sage file then run latex again; the ?? are consistent with 1 step. Sagemath Cloud can avoid this (done automatically) and installation hassles. If you have "Typeset" programmed in your IDE to go through the 3 step compilation process then you should consider asking your question at AskSagemath if you can't get an answer here. – DJP Feb 22 '15 at 2:56
  • @DJP: Thanks, that's what I needed, and I should have read the page I linked to more closely. Please post that as an answer so I can accept it. :) – Chuck Feb 22 '15 at 3:25
2

TeXShop uses scripts it calls 'Engines' to typeset each document. It is already set up to deal with Sage, but you need to activate the SageTeX engine.

In the Finder, navigate to ~/Library/TeXshop/Engines and in that folder there will be an Inactive folder. Inside is the file sage.engine. Move this into the Engines folder, and restart TeXshop.

(You will also find some other documentation in the Sage folder, including a sample document. It also recommends a different method of accessing Sage properly without copying it to your local texmf folder.)

Once you have restarted TeXShop, in the pulldown menu next to the Typeset button, the Sage engine will appear. Select it and then compile your document. Everything should now work.

You can add the line:

% !TEX TS-program = sage

to first line of your Sage documents and the sage engine will be chosen automatically.

  • I followed your instructions (after confirming them with the About SageTeX.pdf file found in that Inactive folder) and followed the instructions for creating the symbolic link, but TeXShop now complains that it can't find sagetex.sty. I also tried placing a copy of that file in the same folder as the tex file, but got the same error. I have had success by doing this process from the command line with the latex/sage/latex routine, and I'll try automating that, but would much prefer to get this working from TeXShop. – Chuck Feb 22 '15 at 5:16
  • @Chuck I assume from your having accepted the answer that you have successfully got this working now? – Alan Munn Feb 22 '15 at 13:35
  • It is possible that you will not see the Library folder immediately; see macworld.com/article/2057221/… . Perhaps Shift-Command-G and then ~/Library/TeXShop/Engines is the easiest method on Lion; there appears to be a preference in Mavericks and on. – kcrisman Jul 25 '15 at 14:20
1

For reference, here are up-to-date links to SageTeX-related parts of the SageMath documentation and to the SageTeX GitHub repository.

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.