Skip to content
Dan Drake edited this page Aug 26, 2015 · 2 revisions

Welcome to the SageTeX wiki!

This may get more content later, but for now here's a bit from the now-abandoned Bitbucket SageTeX wiki.

If you use Latexmk to control typesetting of your document, you could try adding this snippet to your .latexmkrc so that Latexmk runs Sage when necessary:

add_cus_dep('sagetex.sage', 'sagetex.sout', 0, 'makesout');
$hash_calc_ignore_pattern{'sage'} = '^( _st_.goboom| ?_st_.current_tex_line|print .SageT)';
sub makesout {
    system("sage '$_[0].sagetex.sage'");
}

Unfortunately, Latexmk does not support extensions with a dot: it can only handle document.foo, not document.foo.bar. SageTeX uses .sagetex.sage to avoid the possibility of overwriting something like document.sage which might have code the user created that is related to the document.

Fortunately, there is a good workaround provided by the run-sagetex-if-necessary script included with SageTeX. That script does exactly what it says on the tin; running it every time you typeset involves an overhead of only a fraction of a second.

Try adding this to your .latexmkrc:

$latex = "$latex ; python /path/to/run-sagetex-if-necessary.py %B";
$pdflatex = "$pdflatex ; python /path/to/run-sagetex-if-necessary.py %B";

The script is in SAGE_ROOT/local/share/texmf/tex/generic/sagetex/, where SAGE_ROOT refers to the directory where Sage is installed.

Clone this wiki locally