# Using SageTeX within Windows

Sage 5.5 was just released. It is a Linux native, is there a way to use it within windows with minimal constraints?

After experimenting, I suggest the following method. It is based on MikTex 2.9, TeXnicCenter, VMWare player (this one is free for home use), Linux Mint 14 with Cinnamon and of course Sage 5.5. It should be similar if you use VirtualBox. The goal was to use windows as most as possible and linux as little as possible, there is no need here to install TexLive in the virtual machine and to coordinate it with MikTeX.

The big picture is this one, it should be enough for a windows geek, it is followed by a more detailed explanantion.

INSTALLATION

1. Install a virtualization software (VMWare, Virtual Box, Windows Virtual PC)
2. Install a Debian Linux distribution (Mint 14 Cinnamon recommended as closest to the Windows look and feel)
3. Share your TeX document directory between the host and the guest operating system with R/W rights
5. "Install" sage in any user directory, sage being "portable", in windows parlance it is just a move of the directory
6. Transfer the sage tex directory to the host operating system
7. Make sage "known" to MikTeX, like any other new style or package

UTILIZATION

1. "Miktexify" your *.tex file using the sagetex package with pdflatex,
2. this generate a new *.sagetex.sage in your TeX directory and some warnings
3. Open the guest operating system and start sage in a terminal
4. Using a DOS, Linux command cd (change directory) at the sage prompt place the sage program in the shared Host/Guest Tex directory
6. this will generate two new files *.sagetex.scmd and *.sagetex.sout in your tx directory
7. "Miktexify" your *.tex file again, the result of the sage computation will be written to your pdf output.

The result is just great, really worth the installation effort, it will improve the quality of your document avoiding typos in long expressions.

In the following modus operandi, the places where the Sage documentation is insufficient or not up to date are more detailed

1. Install VMWare player from https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/5_0
2. Install your favorite Linux distro (but if you read this, you are obviously not a Linux fan so use Linux Mint 14 with Cinnamon, the closest to windows so far). http://www.linuxmint.com/edition.php?id=117
3. Install VMWare tools

Let suppose that your windows working Tex directory is C:\Documents\Maths and your name is usrx

Within VMWare Virtual Machine Settings, tab Options Enable Shared Folders, always enable, uncheck the read only case in properties (the default is RW so it should not be necessary). In the Hardware tab for network adapter use NAT.

Download the package "sage-5.5-linux-32bit-ubuntu_12.04.1_lts-i86-Linux.tar.lzma" from http://www.sagemath.org/download.html and expand it (as a you would do in windows..) in your user directory /home/usrx, rename the directory to sage55 to make it short.

You now have sage installed in the directory /home/usrx/sage55, test it by double clicking the sage icon, choosing run in a terminal (let the directory update run its course)

When you get the sage: prompt, test it with your favorite instruction, 2+2 may be, if you get 4 you are good to go.

Now, using Nemo, (here Windows users can read Explorer, the file icon at the bottom of the screen) open the directories /home/usrx/sage55/local/share/texmf where you get a directory tex, right click and copy it.

From the same nemo double click File System then the icon mnt (mount) and then hgfs. If everything went OK, you should find there your windows directory, Maths shared between the host (Windows) and the guest (Mint 14).

In this directory you paste the tex directory copied from /home/usrx/sage55/local/share/texmf

Now, we get back to windows but do not close the virtual machine, neither the sage terminal, you will use it for sagetex.

Using Administrator rights copy again this directory to your MikTeX installation with your other particular styles for example (I use one called modified C:\Program Files\MiKTeX 2.9\tex\latex\modified , e.g.) so that you now have C:\Program Files\MiKTeX 2.9\tex\latex\modified\tex).

Now we can try to use sagetex.

From TeXnicCenter, create a sample tex file, such as this one

\documentclass{article}
\usepackage{sagetex}
\begin{document}
Factoring $x^{12}-y^{12}$.
With Sage, for the rationals, we find
\begin{sageblock}
L.<x,y>=LaurentPolynomialRing(QQ)
f=x^(12)-y^(12)
\end{sageblock}
$\sage{f.factor()}$
In the real domain we find
$x^{12}-y^{12}=(x+y)(x-y)\left(x^2+y^2\right)\left(x^2+y^2+xy\right)\left(x^2+y^2- xy\right)\left(x^2+x y \sqrt{3}+y^2\right)\left(x^2-x y \sqrt{3}+y^2\right).$
\end{document}


call it SageX.tex, e.g.

Build and view your file once. You will have warnings about unreferenced sage items

and in your /mnt/hgfs/Maths directory, you will find a new file called SageX.sagetex.sage (NOT SageX.sage). The pdf file will have ?? where the answer to the factorization should be.

Go back to the virtual machine, to the sage terminal and sage prompt (sage:) There you need to type a linux instruction followed by return, (Here the sage manual says that a linux instruction should be typed !cd but this does not work)

sage: cd /mnt/hgfs/Maths


(change to the share windowslinux directory), you should see this answer /mnt/hgfs/Maths Now type the instruction sage: load SageX.sagetex.sage If all went well you will get the answer

sage: load SageX.sagetex.sage
Processing Sage code for SageX.tex...
Code block begin...end
Inline formula 0
Sage processing complete. Run LaTeX on SageX.tex again.


Back to Windows. In C:\Documents\Maths, you have two new files SageX.sagetex.scmd and SageX.sagetex.sout. Run TeXnicCenter again, you should have no more warnings and the factorization of the polynomial in the rationals, computed by sage, will have replaced the ??.

Note that as long as you do not modify the sage instruction, you don't need to run sage again, you can modify your text or add new LaTeX code within windows as long as you don't add (or modify) new sage code (or as long as you delete the three *.sage, *.scmd and *.sout files).

Sagetex is a great product so my hope is that some windows users will try the process and be convinced by the product (and also help in improving this text)...

• sagetex can be installed with the package manager in MiKTeX. I cannot judge, though, whether this is the recent version; otherwise regarding “transfer sage directory and make sage known to MiKTeX” I want to point to Create a local texmf tree in MiKTeX. And: For Sage there exists a Windows binary, what actually is a VirtualBox image, as written by you. – Speravir Mar 1 '13 at 1:52
• I would like to add that this wasn't sufficient for me to work. Sage could not compile plots. Running " sudo apt-get install python-numpy " in the terminal got me what was missing and now it works. But thanks for the step by step tutorial. – Jean-Sébastien Feb 6 '14 at 22:57
• No need for adding WSL overheads nor a VM if you simply use the latest 8.6 Cygwin combined SageMath package and run it from inside your choice of windows editor. – user170109 Mar 23 '19 at 2:04

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.

• You should not corrupt MiKTeX by copying the files to c:\Program Files\MiKTeX 2.9\tex\latex\sagetex\ the official instructions give three alternative safe ways to place the SageTeX file in the texmf search path 1)your work folder 2) you add the sage folder to TEXINPUTS 3) The recommended way is you add it to your personal texmf folder (that is NOT a MiKTeX one where it will corrupt the filename database) – user170109 Mar 22 '19 at 23:02
• Thanks for your advice. In fact, I tried those 3 ways, but I don't know why them didn't work for me. Then I forced the situation and it worked!. – Pedro Jose Moreno Garcia Mar 27 '19 at 22:10