# SympyTeX

## SympyTeX

SympyTex is a LaTeX package that allows you to embed sympy commands within a LaTeX document.

### Example

Using sympy within your \LaTeX document is as easy as $2+2=\sympy{2+2}$.

You can write a block, and then use the variables defined later in your code!
\begin{sympyblock}
x = sympy.Symbol('x')
h = sympy.integrate(1+x,x)
\end{sympyblock}
The variable $h$, how can be called using {\verb \sympy{h} }, and you will get $h = \sympy{h}$. Similarly, the integral of $1+x^4$ is $\sympy{sympy.integrate(1+x**4,x)}$.


Here is an example of the output generated.

## Graphics

Creating graphs is easy too. Here we're using matplotlib to create a figure.

 \begin{sympyblock}
import matplotlib
import matplotlib.pyplot as plt
plt.matplotlib.rc('text', usetex = True)
import pylab
fig = plt.figure()
t = pylab.linspace(0,10,400)
ax.plot(t, sin(3*t), '-',
t, sin(0.3*t**2), '--',
t, cos(t), '-.')
ax.legend((r'$A^{\omega}$', r'$A^{2\omega}$', r'$A^{3\omega}$'),
shadow = False, loc = (0.75, 0.1))
ax.set_xlabel(r'$\gamma_1 + \gamma_2$', {'fontsize'   : 20 })
ax.set_ylabel(r'$A^{n\omega}$ (dB)', {'fontsize'   : 20 })
\end{sympyblock}


The resulting image is inserted with:

 \begin{figure}
\sympyplot[width=\linewidth]{fig}
\caption{The graph generated... }
\end{figure}


Source code and instructions for using and building SympyTeX are available from github.

## Instructions

To use SympyTeX, include the line

 \usepackage{sympytex}


In the preamble of your latex document (let's call it 'example.tex'). Then add some sympytex commands inside your document (as above). Then build your document using the following commands.

 latex example.tex
python example.sympy
latex example.tex


If you have an integrated LaTeX environment (eg, Kile) you can configure it to run Python on the .sympy file automatically.