PHPirate
PHPirate

Reputation: 7582

How to run SageTeX on Windows?

I want to use Sage in LaTeX, how do I do that running Sagemath 8.0 on Windows? I use the MikTeX distribution.

I followed the instructions from Sagemath but they are for linux. I included the sagetex package, which generates a myfile.sage file but when I start the Sage shell and run sage myfile.sage it says

Traceback (most recent call last):
  File "myfile.sage.py", line 7, in <module>
    _st_ = sagetex.SageTeXProcessor('myfile')
  File "/opt/sagemath-8.0/local/lib/python2.7/site-packages/sagetex.py", line 76, in __init__
    raise VersionError, errstr
sagetex.VersionError: versions of .sty and .py files do not match.
myfile.sagetex.sage was generated by sagetex.sty version "None", but
is being processed by sagetex.py version "2015/08/26 v3.0-92d9f7a".
Please make sure that TeX is using the sagetex.sty
from your current version of Sage; see
http://www.sagemath.org/doc/installation/sagetex.html.

Upvotes: 1

Views: 1100

Answers (3)

PHPirate
PHPirate

Reputation: 7582

As mentioned by Pedro Jose Moreno Garcia, a couple of years after this question was asked a new sage arara rule was written by the TeXnician (and fixed by Pedro) which works on Windows. Complete instructions are then as follows, to compile your LaTeX file using sagetex with one command.

  1. Install MiKTeX and Sagemath
  2. Make sure the sagetex package is not installed by MiKTeX
  3. Find out your SageTeX installation path, for example C:\Program Files\SageMath 9.2 or C:\Users\myusername\AppData\Local\SageMath 9.2 for a user installation.
  4. Compile your LaTeX file with environment variable TEXINPUTS=C:\Users\myusername\AppData\Local\SageMath 9.2\runtime\opt\sagemath-9.2\local\share\texmf\tex\latex\sagetex; such that it finds the sagetex.sty package. (Verified with the TeXiFy editor.) If that doesn't work, you could of course always copy the sagetex.sty package to your working directory.
  5. Create an arara rule. You can keep it local as follows (there are much more possibilities, see the arara docs): create a file araraconfig.yaml next to your LaTeX file with following content
!config
paths:
- .
  1. Create a file called sagetex.yaml with the contents from https://tex.stackexchange.com/questions/520683/arara-sage-a-sagemath-rule-for-arara (change the paths to your installation):
!config
# SageTeX-Rule for arara.
#
# Dear Windows-users, please check the paths
# pathToBashExecutive    and    pathToSageStartfile
# due to your Sage-installation!
#
identifier: sagetex
name: SageTeX
authors:
  - TeXnician (Author)
  - cis (Idea)
  - Pedro J (final fix)
arguments: []
commands:
  - name: A SageTeX Rule for arara
    command: >
      @{
          pathToBashExecutive = "C:\\Users\\myusername\\AppData\\Local\\SageMath 9.2\\runtime\\bin\\bash";
          pathToSageStartfile = "C:/Users/myusername/AppData/Local/SageMath 9.2/runtime/opt/sagemath-9.2/sage";
          pathOfCurrentWorkingFolder = currentFile().getParent();
          theWindowsCommand = getCommand(pathToBashExecutive, "-l", pathToSageStartfile, "-c", "os.chdir(r'" + pathOfCurrentWorkingFolder + "'); load('" + getBasename(currentFile()) + ".sagetex.sage')");
          return isWindows(theWindowsCommand, getCommand("sage", getBasename(reference) + ".sagetex.sage"));
         }
  1. Run arara myfile.tex

Upvotes: 0

PHPirate
PHPirate

Reputation: 7582

Here are the full instructions, adapted for Windows.

  1. Find the sagetex.sty file of your sage installation, probably it is in C:\Program Files\SageMath 8.0\runtime\opt\sagemath-8.0\local\share\texmf\tex\latex\sagetex\sagetex.sty. (On for example Arch Linux, you have to install both the sage and sagetex packages, then the file will be in /usr/share/texmf/tex/latex/sagetex/sagetex.sty)
  2. Find out which sagetex.sty your computer is finding by running the TeX command kpsewhich sagetex.sty anywhere on your command prompt. Probably this is your MikTeX (or TeX Live or whatever distribution you are using) directory which contains an old sagetex.sty which is causing the version mismatch. If you get a popup asking you to install something, then don't install!
  3. I'm not completely sure but I think you can just copy the new package file of your sage installation to your distribution's sagetex directory (for MikTeX something like C:\Users\s156757\AppData\Roaming\MiKTeX\2.9\tex\latex\sagetex) overwriting the old sagetex.sty that is there. If not, make sure to remove the old one and use your new file, for example by placing it next to your tex file.
  4. Probably you need to install the package fancyvrb which sagetex needs manually using for example the MikTeX package manager.
  5. Every time you add new Sage to your LaTeX: run your LaTeX file, start the Sage shell and go to the directory where the just made myfile.sagetex.sage was placed, which is the same directory as where all your auxiliary files are: cd "C:/path/to/auxiliary/files" and sage myfile.sagetex.sage, then run LaTeX again. Both the .scmd and .sout files are needed for for example other people to compile your LaTeX.
  6. Use SageTeX with for example $\sage{1+1}$ or with the sageblock environment.

Upvotes: 1

There is a way to use sagetex on windows:

Step 1: Install miktex 2.9 64-bit, full install.

Step 2: Install Texniccenter 2.02 64-bit (I think another program like texworks, texmaker, winedt, etc will work).

Step 3: Install Sagemath 8.6 64-bit or better.

Step 4: Sagetex version in miktex is different to sagetex version in Sagemath 8.6. Then you should install in miktex same version of sagetex as you have in Sagemath.

This can be done copying al files in **c:\Program Files\SageMath 8.6\runtime\opt\sagemath-8.6\local\share\texmf\tex\latex\sagetex** into **c:\Program Files\MiKTeX 2.9\tex\latex\sagetex**

Now using sagetex on windows is possible according this:

1.- Use texniccenter to compile your .tex document. Remember you have to load sagetex package: \usepackage{sagetex}

2.- Sagemath installation on windows has 3 shotcurts. You should open Sagemath 8.6, not Sagemath 8.6 Shell or Sagemat 8.6 Notebook. Remember, Sagemath 8.6. After that a shell is opened and when we see sage:, sagemath is ready.

3.- Navigate to folder where our files are using "cd" command, like cd documents. Is important, if your folder's name has spaces placing it between ' ', i.e. cd 'folder 1'

4.- When you are into your destination folder, you can see its contents with "ls". There should be your sagetex.sage file. To process the file you have to write load('file.sagetex.sage') (file is the name of your .tex file) and the procces will start when you press enter.

5.- Finaly, use texniccenter to compile again the .tex file.

When you need to use again sage, you don't need to write the command, because using up arrow on your keyboard will apear the command and you only have to press enter.

I think will be possible automatize 3 steps using postprocessor on texniccenter, but I don't know how to do it right now.

Upvotes: 2

Related Questions