diff options
author | Karl Berry <karl@freefriends.org> | 2008-03-14 00:26:22 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2008-03-14 00:26:22 +0000 |
commit | 8df6f8b096486d3886fc2a42ba79a6f5a4c587f7 (patch) | |
tree | 6ff8b7ceae6c40b7db55ed005ba81e49ecd490ad /Master/texmf-dist/doc/latex/sagetex | |
parent | 3d96fa2455c0dbac611ab90f9ae59854fb40d3d9 (diff) |
new latex package sagetex (12mar08)
git-svn-id: svn://tug.org/texlive/trunk@6962 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/sagetex')
-rw-r--r-- | Master/texmf-dist/doc/latex/sagetex/README | 43 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/sagetex/example.pdf | bin | 0 -> 254523 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/sagetex/example.tex | 185 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/sagetex/sagetex.py | 126 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/sagetex/sagetexpackage.pdf | bin | 0 -> 241432 bytes |
5 files changed, 354 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/sagetex/README b/Master/texmf-dist/doc/latex/sagetex/README new file mode 100644 index 00000000000..2e9d512d0eb --- /dev/null +++ b/Master/texmf-dist/doc/latex/sagetex/README @@ -0,0 +1,43 @@ +This is the SageTeX package. It allows you to embed code, results of +computations, and plots from the Sage mathematics software suite +(http://sagemath.org) into LaTeX documents. +==================================================================== + +To use SageTeX, you need the files sagetex.sty and sagetex.py. If those +haven't been extracted from the .dtx file, you'll need to do: + + 0. Run `latex sagetexpackage.ins' + +If a PDF file of the documentation wasn't included with this +distribution of SageTex, you will need to build the documentation +yourself. To do that: + + 1. Run `latex sagetexpackage.dtx' + 2. Run `sage sagetexpackage.sage' + 3. Run the indexing commands that the .ins file told you about. + 4. Run `latex sagetexpackage.dtx' again. + +You can skip step 3 if you don't care about the index. You will need the +pgf and tikz packages installed to typeset the figures. + +The file example.tex has, as you likely guessed, a bunch of examples +showing you how this package works. You can compile it using a another +latex-sage-latex cycle as in steps 1-2-4 above. Note that example.tex +includes some PNG graphics which latex cannot use; to see those, use +pdflatex instead of regular latex or enable the imagemagick option. (See +the documentation.) + +To use the SageTeX package with your own documents, see the +"Installation" section of the documentation. + +This works builds on a lot of work by others; see the "Credits" section +of the documentation for credits. The source code may be modified and +distributed under the terms of the GPL, v2 or later; the documentation +may be modified and distributed under a Creative Commons Attribution - +Noncommercial - Share Alike 3.0 License. See the "Copying and licenses" +section of the documentation. + +Please let me know if you find any bugs or have any ideas for +improvement! + +- Dan Drake <ddrake@member.ams.org> diff --git a/Master/texmf-dist/doc/latex/sagetex/example.pdf b/Master/texmf-dist/doc/latex/sagetex/example.pdf Binary files differnew file mode 100644 index 00000000000..52b3ba0e34a --- /dev/null +++ b/Master/texmf-dist/doc/latex/sagetex/example.pdf diff --git a/Master/texmf-dist/doc/latex/sagetex/example.tex b/Master/texmf-dist/doc/latex/sagetex/example.tex new file mode 100644 index 00000000000..0f84e3152e6 --- /dev/null +++ b/Master/texmf-dist/doc/latex/sagetex/example.tex @@ -0,0 +1,185 @@ +% General example LaTeX file for including Sage calculations and plots +% Build with: (pdf)latex example.tex; sage example.sage; pdflatex +% example.tex Please read README and the documentation of the SageTeX +% package for more information! + +\documentclass{article} +\title{Examples of embedding Sage in \LaTeX} +\author{} + +\usepackage{sagetex} +% +% If you want sagetex to use Imagemagick's convert utility to make eps +% files from png files when generating a dvi file, add the +% "imagemagick" option above: +% +% \usepackage[imagemagick]{sagetex} + +\begin{document} +\maketitle + +\section{Inline Sage, code blocks} + +This is an example $2+2=\sage{2+2}$. If you raise the current year mod +$100$ ($\sage{mod(\the\year, 100)}$) to the power of the current day +($\the\day$), you get $\sage{Integer(mod(\the\year, 100))^\the\day}$. +Also, $\the\year$ modulo $42$ is $\sage{\the\year \percent 42}$. + +Code block which uses a variable \texttt{s} to store the solutions: +\begin{sageblock} + var('a,b,c') + eqn = [a+b*c==1, b-a*c==0, a+b==5] + s = solve(eqn, a,b,c) +\end{sageblock} + +Solutions of $\mbox{eqn}=\sage{eqn}$: +\[ +\sage{s[0]} +\] +\[ +\sage{s[1]} +\] + +Now we evaluate the following block: +\begin{sageblock} +E = EllipticCurve("37a") +\end{sageblock} +You can't do assignment inside \verb|\sage| macros, since Sage doesn't +know how to typeset the output of such a thing. So you have to use a +code block. The elliptic curve $E$ given by $\sage{E}$ +has discriminant $\sage{E.discriminant()}$. + +You can do anything in a code block that you can do in Sage and/or +Python. Here we save an elliptic curve into a file. +\begin{sageblock} +try: + E = load('E2') +except IOError: + E = EllipticCurve([1,2,3,4,5]) + E.anlist(100000) + E.save('E2') +\end{sageblock} + +The 9999th Fourier coefficient of $\sage{E}$ is +$\sage{E.anlist(100000)[9999]}$. + +The following code block doesn't appear in the typeset file\dots +\begin{sagesilent} + e = 2 + e = 3*e + 1 +\end{sagesilent} +but we can refer to whatever we did in that code block: $e=\sage{e}$. + +\begin{sageblock} + var('x') + f = log(sin(x)/x) +\end{sageblock} +The Taylor Series of $f$ is: $\sage{ f.taylor(x, 0, 10) }$. + +\section{Plotting} + +Here's a plot of the elliptic curve $E$. + +\sageplot{E.plot(-3,3)} + +\begin{sagesilent} + var('x') + f=-x^3+3*x^2+7*x-4 +\end{sagesilent} + +You can use variables to hold plot objects and do stuff with them. +\begin{sageblock} + p = plot(f, x, -5, 5) +\end{sageblock} + +Here's a small plot of $f$ from $-5$ to $5$, which I've centered: + +\centerline{\sageplot[scale=.2]{p}} + +On second thought, use the default size of $3/4$ the \verb|\textwidth| +and don't use axes: + +\sageplot{p, axes=False} + +Remember, you're using Sage, and can therefore call upon any of the +software packages Sage is built out of. +\begin{sageblock} +f = maxima('sin(x)^2*exp(x)') +g = f.integrate('x') +\end{sageblock} +Plot $g(x)$, but don't typeset it. +\begin{sagesilent} + # g is a Maxima thingy, it needs to get converted into a Sage object + plot1 = plot(g.sage(),x,-1,2*pi) +\end{sagesilent} + +You can specify a file format and options for \verb|includegraphics|. +The default is for EPS and PDF files, which are the best choice in +almost all situations. (Although see the section on 3D plotting.) + +\sageplot[angle=45, width=.5\textwidth][png]{plot1} + +If you use regular \verb|latex| to make a DVI file, you'll see a box, +beause DVI files can't include PNG files. If you use \verb|pdflatex| +that will work. See the documentation for details. + +When using \verb|\sageplot|, you can pass in just about anything that +Sage can call \verb|.save()| on to produce a graphics file: + +\begin{center} +\sageplot{plot1 + plot(f.sage(),x,-1,2*pi,rgbcolor=hue(0.4)), figsize=[1,2]} +\end{center} + +\sageplot{graphs.FlowerSnark().plot()} + +\begin{sageblock} +G4 = DiGraph({1:[2,2,3,5], 2:[3,4], 3:[4], 4:[5,7], 5:[6]},\ + multiedges=True) +G4plot = G4.plot(layout='circular') +\end{sageblock} + +\sageplot{G4plot, axes=False} + +Indentation and so on works fine. +\begin{sageblock} + s = 7 + s2 = 2^s + P.<x> = GF(2)[] + M = matrix(parent(x),s2) + for i in range(s2): + p = (1+x)^i + pc = p.coeffs() + a = pc.count(1) + for j in range(a): + idx = pc.index(1) + M[i,idx+j] = pc.pop(idx) + + matrixprogram = matrix_plot(M,cmap='Greys') +\end{sageblock} +And here's the picture: + +\sageplot{matrixprogram} + +\subsection{3D plotting} + +3D plotting right now is problematic because there's no convenient way +to produce vector graphics. We can make PNGs, though, and since the +\verb|sageplot| command defaults to EPS and PDF, \emph{you must specify +a valid format for 3D plotting}. Sage right now (version 2.10.3) can't +produce EPS or PDF files from plot3d objects, so if you don't specify a +valid format, things will go badly. You can specify the +``\texttt{imagemagick}'' option, which will use the Imagemagick +\texttt{convert} utility to make EPS files. See the documentation for +details. + +Here's the famous Sage cube graph: + +\begin{sageblock} + G = graphs.CubeGraph(5) +\end{sageblock} + +% need empty [] so sageplot knows you want png format, and aren't +% passing an option to includegraphics +\sageplot[][png]{G.plot3d(engine='tachyon')} + +\end{document} diff --git a/Master/texmf-dist/doc/latex/sagetex/sagetex.py b/Master/texmf-dist/doc/latex/sagetex/sagetex.py new file mode 100644 index 00000000000..2686b4348f5 --- /dev/null +++ b/Master/texmf-dist/doc/latex/sagetex/sagetex.py @@ -0,0 +1,126 @@ +""" +%% +%% This is file `sagetex.py', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% sagetexpackage.dtx (with options: `python') +%% +%% This is a generated file. +%% +%% Copyright (C) 2008 by Dan Drake <ddrake@member.ams.org> +%% +%% This program is free software: you can redistribute it and/or modify it +%% under the terms of the GNU General Public License as published by the +%% Free Software Foundation, either version 2 of the License, or (at your +%% option) any later version. +%% +%% This program is distributed in the hope that it will be useful, but +%% WITHOUT ANY WARRANTY; without even the implied warranty of +%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +%% General Public License for more details. +%% +%% You should have received a copy of the GNU General Public License along +%% with this program. If not, see <http://www.gnu.org/licenses/> +%% +""" +import sys +if __name__ == "__main__": + print("""This file is part of the SageTeX package. +It is not meant to be called directly. + +This file will be used by Sage scripts generated from a LaTeX document +using the sagetex package. Keep it somewhere where Sage and Python can +find it and it will automatically be imported.""") + sys.exit() +from sage.misc.latex import latex +import os +import os.path +import hashlib +import traceback +import subprocess +import shutil +initplot_done = False +dirname = None +filename = "" +def progress(t,linebreak=True): + if linebreak: + print(t) + else: + sys.stdout.write(t) +def openout(f): + global filename + filename = f + global _file_ + _file_ = open(f + '.sout.tmp', 'w') + s = '% This file was *autogenerated* from the file ' + \ + os.path.splitext(filename)[0] + '.sage.\n' + _file_.write(s) + progress('Processing Sage code for %s.tex...' % filename) +def initplot(f): + global initplot_done + if not initplot_done: + progress('Initializing plots directory') + global dirname + dirname = 'sage-plots-for-' + f + '.tex' + if os.path.isdir(dirname): + shutil.rmtree(dirname) + os.mkdir(dirname) + initplot_done = True +def inline(counter, s): + progress('Inline formula %s' % counter) + _file_.write('\\newlabel{@sagelabel' + str(counter) + '}{{' + \ + latex(s) + '}{}{}{}{}}\n') +def blockbegin(): + progress('Code block begin...', False) +def blockend(): + progress('end') +def plot(counter, p, format='notprovided', epsmagick=False, **kwargs): + global dirname + progress('Plot %s' % counter) + if format == 'notprovided': + formats = ['eps', 'pdf'] + else: + formats = [format] + for fmt in formats: + plotfilename = os.path.join(dirname, 'plot-%s.%s' % (counter, fmt)) + #print(' plotting %s with args %s' % (plotfilename, kwargs)) + p.save(filename=plotfilename, **kwargs) + if format != 'notprovided' and epsmagick is True: + print('Calling Imagemagick to convert plot-%s.%s to EPS' % \ + (counter, format)) + toeps(counter, format) +def toeps(counter, ext): + global dirname + subprocess.check_call(['convert',\ + '%s/plot-%s.%s' % (dirname, counter, ext), \ + '%s/plot-%s.eps' % (dirname, counter)]) +def goboom(line): + global filename + print('\n**** Error in Sage code on line %s of %s.tex! Traceback\ + follows.' % (line, filename)) + traceback.print_exc() + print('\n**** Running Sage on %s.sage failed! Fix %s.tex and try\ + again.' % (filename, filename)) + os.remove(filename + '.sout.tmp') + sys.exit(1) +def endofdoc(): + global filename + sagef = open(filename + '.sage', 'r') + m = hashlib.md5() + for line in sagef: + if line[0:15] != ' sagetex.goboom': + m.update(line) + s = '%' + m.hexdigest() + '% md5sum of .sage file (minus "goboom" \ +lines) that produced this\n' + _file_.write(s) + _file_.close() + os.rename(filename + '.sout.tmp', filename + '.sout') + progress('Sage processing complete. Run LaTeX on %s.tex again.' %\ + filename) +""" +\endinput +%% +%% End of file `sagetex.py'. +""" diff --git a/Master/texmf-dist/doc/latex/sagetex/sagetexpackage.pdf b/Master/texmf-dist/doc/latex/sagetex/sagetexpackage.pdf Binary files differnew file mode 100644 index 00000000000..43a32df1580 --- /dev/null +++ b/Master/texmf-dist/doc/latex/sagetex/sagetexpackage.pdf |