## Code

I don't claim to be an expert in anything I've used below, and it's quite likely that there are better ways of doing most of these. Click here to return to my homepage.

### TeX

Below are some things I've drawn or coded in TeX.

The code below draws the slope field given by a function \(f(x,y)\) of two variables, once you've specified a few parameters. This example produces the slope field for \(f(x,y) = x^2 + y^3\). Be aware that this is unlikely to work with poorly-behaved functions, for instance when the slope is undefined.

You can download the TeX file here.

\documentclass { amsart}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

%% Set the window for x and y values.

\pgfmathsetmacro \xmin { -2} ;

\pgfmathsetmacro \ymin { -2} ;

\pgfmathsetmacro \xmax { 2} ;

\pgfmathsetmacro \ymax { 2} ;

%% Set the density of the slope field; a lower spacing gives a denser slope field.

\pgfmathsetmacro \xspacing { 0.2} ;

\pgfmathsetmacro \yspacing { 0.2} ;

%% Set the length of the tangent lines: all lines of the slope field are drawn with this length. This should be less than both spacing numbers above for a neat slope field.

\pgfmathsetmacro \length { 0.1} ;

%% Define the slope at (\x,\y) as a function f of \x and \y. Here, #1 is \x and #2 is \y. The function should be defined within \pgfmathparse{ }.

\pgfmathdeclarefunction { f} { 2} { \pgfmathparse { (#1)^2 + (#2)^3} } ;

%% This block generates the slope field.

%% Restrict drawing to the confines of the specified rectangle.

\clip (\xmin ,\ymin ) rectangle (\xmax ,\ymax );

%% Draw the axes.

\draw (\xmin ,0) -- (\xmax ,0);

\draw (0,\ymin ) -- (0,\ymax );

%% Some calculations (since we cannot do arithmetic inside a list).

\pgfmathsetmacro \xnext { \xmin +\xspacing } ;

\pgfmathsetmacro \ynext { \ymin +\yspacing } ;

%% Loop to draw the tangent lines.

\foreach \x in{ \xmin ,\xnext , ...,\xmax } { \foreach \y in{ \ymin ,\ynext , ...,\ymax } {

%% Calculate slope at (\x,\y).

\pgfmathsetmacro \slope { f(\x ,\y )} ;

\begin { scope}

%% Cut the drawing down to the circle of radius 0.5*\length centered at (\x,\y).

\clip (\x ,\y ) circle ({ 0.5*\length } );

%% Draw tangent lines of length at least \length, with midpoint (\x,\y).

\draw [ very thin] ({ \x - 0.5*\length } ,{ \y - 0.5*\slope *\length } ) -- ({ \x + 0.5*\length } ,{ \y + 0.5*\slope *\length } );

\end { scope}

}

}

\end { tikzpicture}

\end { center}

\end { document}

Using Euler's method, it is relatively easy to add a solution curve. The following amended code draws the slope field above along with a solution curve passing through the point \((0, 0.3)\).

You can download the TeX file here.

\documentclass { amsart}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

%% Set the window for x and y values.

\pgfmathsetmacro \xmin { -2} ;

\pgfmathsetmacro \ymin { -2} ;

\pgfmathsetmacro \xmax { 2} ;

\pgfmathsetmacro \ymax { 2} ;

%% Set the density of the slope field; a lower spacing gives a denser slope field.

\pgfmathsetmacro \xspacing { 0.2} ;

\pgfmathsetmacro \yspacing { 0.2} ;

%% Set the length of the tangent lines: all lines of the slope field are drawn with this length. This should be less than both spacing numbers above for a neat slope field.

\pgfmathsetmacro \length { 0.1} ;

%% Define the slope at (\x,\y) as a function f of \x and \y. Here, #1 is \x and #2 is \y. The function should be defined within \pgfmathparse{ }.

\pgfmathdeclarefunction { f} { 2} { \pgfmathparse { (#1)^2 + (#2)^3} } ;

%% Specify the step size to use in Euler's method.

\pgfmathsetmacro \stepsize { 0.005} ;

%% Specify the bounds of the interval on which to draw the solution curve, and the x co-ordinate of the initial point. Make sure that the pairwise differences \initialx - lower and \upper - \initialx are divisible by \stepsize.

\pgfmathsetmacro \lower { -2} ;

\pgfmathsetmacro \initialx { 0} ;

\pgfmathsetmacro \upper { 1.4} ;

%% Specify the desired y-value at x=\initialx of the solution to be graphed.

\pgfmathsetmacro \initialy { 0.3} ;

%% This block generates the slope field.

%% Restrict drawing to the confines of the specified rectangle.

\clip (\xmin ,\ymin ) rectangle (\xmax ,\ymax );

%% Draw the axes.

\draw (\xmin ,0) -- (\xmax ,0);

\draw (0,\ymin ) -- (0,\ymax );

%% Some calculations (since we cannot do arithmetic inside a list).

\pgfmathsetmacro \xnext { \xmin +\xspacing } ;

\pgfmathsetmacro \ynext { \ymin +\yspacing } ;

%% Loop to draw the tangent lines.

\foreach \x in{ \xmin ,\xnext , ...,\xmax } { \foreach \y in{ \ymin ,\ynext , ...,\ymax } {

%% Calculate slope at (\x,\y).

\pgfmathsetmacro \slope { f(\x ,\y )} ;

\begin { scope}

%% Cut the drawing down to the circle of radius 0.5*\length centered at (\x,\y).

\clip (\x ,\y ) circle ({ 0.5*\length } );

%% Draw tangent lines of length at least \length, with midpoint (\x,\y).

\draw [ very thin] ({ \x - 0.5*\length } ,{ \y - 0.5*\slope *\length } ) -- ({ \x + 0.5*\length } ,{ \y + 0.5*\slope *\length } );

\end { scope}

}

}

%% This block generates the solution curve with the specificed parameters.

%% Some calculations again.

\pgfmathsetmacro \xnext { \initialx +\stepsize } ;

\pgfmathsetmacro \xprev { \initialx -\stepsize } ;

%% Iterate to draw the desired solution curve with Euler's method.

\foreach [ remember=\lasty as\y (initially\initialy )] \x in{ \initialx ,\xnext , ...,\upper } {

\draw (\x ,\y ) -- ({ \x +\stepsize } ,{ \y + f(\x ,\y )*\stepsize } );

\pgfmathsetmacro \lasty { \y + f(\x ,\y )*\stepsize } ;

}

\foreach [ remember=\lasty as\y (initially\initialy )] \x in{ \initialx ,\xprev , ...,\lower } {

\draw (\x ,\y ) -- ({ \x -\stepsize } ,{ \y - f(\x ,\y )*\stepsize } );

\pgfmathsetmacro \lasty { \y - f(\x ,\y )*\stepsize } ;

}

\end { tikzpicture}

\end { center}

\end { document}

Here is a torus. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (0,0) to[ out=90,in=90] (3,0) to[ out=-90,in=-90] (0,0);

\draw [ smooth] (0.9,0) .. controls (1.3,-0.15) and (1.7,-0.15) .. (2.1,0);

\draw [ smooth] (1,-0.03) .. controls (1.2,0.2) and (1.8,0.2) .. (2,-0.03);

\end { tikzpicture}

\end { center}

\end { document}

Here is a surface of genus 2. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\end { tikzpicture}

\end { center}

\end { document}

Here is a pants decompositions for this surface. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\thispagestyle { empty}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\draw (-0.5,0) arc(180:0:0.51 and 0.2);

\draw [ dashed] (-0.5,0) arc(180:0:0.51 and -0.2);

\draw (2.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (2.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (5.5,0) arc(180:0:-0.51 and 0.2);

\draw [ dashed] (5.5,0) arc(180:0:-0.51 and -0.2);

\end { tikzpicture}

\end { center}

\end { document}

Here is a surface of genus 3. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=210] (6,1) to[ out=30,in=150] (8,1) to[ out=-30,in=30] (8,-1) to[ out=210,in=-30] (6,-1) to[ out=150,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\draw [ smooth] (6.4,0.1) .. controls (6.8,-0.25) and (7.2,-0.25) .. (7.6,0.1);

\draw [ smooth] (6.5,0) .. controls (6.8,0.2) and (7.2,0.2) .. (7.5,0);

\end { tikzpicture}

\end { center}

\end { document}

Here is a pants decomposition for this surface. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=210] (6,1) to[ out=30,in=150] (8,1) to[ out=-30,in=30] (8,-1) to[ out=210,in=-30] (6,-1) to[ out=150,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\draw [ smooth] (6.4,0.1) .. controls (6.8,-0.25) and (7.2,-0.25) .. (7.6,0.1);

\draw [ smooth] (6.5,0) .. controls (6.8,0.2) and (7.2,0.2) .. (7.5,0);

\draw (-0.5,0) arc(180:0:0.51 and 0.2);

\draw [ dashed] (-0.5,0) arc(180:0:0.51 and -0.2);

\draw (2.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (2.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (4.0,0.15) arc(270:90:0.3 and 1.14/2);

\draw [ dashed] (4.0,0.15) arc(270:450:0.3 and 1.14/2);

\draw (4.0,-0.15) arc(270:90:0.3 and -1.14/2);

\draw [ dashed] (4.0,-0.15) arc(270:450:0.3 and -1.14/2);

\draw (5.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (5.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (8.5,0) arc(180:0:-0.51 and 0.2);

\draw [ dashed] (8.5,0) arc(180:0:-0.51 and -0.2);

\end { tikzpicture}

\end { center}

\end { document}

Here is a surface of genus n. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\thispagestyle { empty}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (5.5,-0.85) to[ out=180,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=180] (5.5,0.85);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\node at (6.5,0){ $.\ ;\ ; .\ ;\ ; .$} ;

\draw [ smooth] (7.5,0.85) to[ out=0,in=210] (8,1) to[ out=30,in=150] (10,1) to[ out=-30,in=210] (11,1) to[ out=30,in=150] (13,1) to[ out=-30,in=30] (13,-1) to[ out=210,in=-30] (11,-1) to[ out=150,in=30] (10,-1) to[ out=210,in=-30] (8,-1) to[ out=150,in=0] (7.5,-0.85);

\draw [ smooth] (8.4,0.1) .. controls (8.8,-0.25) and (9.2,-0.25) .. (9.6,0.1);

\draw [ smooth] (8.5,0) .. controls (8.8,0.2) and (9.2,0.2) .. (9.5,0);

\draw [ smooth] (11.4,0.1) .. controls (11.8,-0.25) and (12.2,-0.25) .. (12.6,0.1);

\draw [ smooth] (11.5,0) .. controls (11.8,0.2) and (12.2,0.2) .. (12.5,0);

\draw (5.5,-0.85) arc(270:90:0.3 and 0.85);

\draw (5.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (7.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (7.5,-0.85) arc(270:450:0.3 and 0.85);

\end { tikzpicture}

\end { center}

\end { document}

Here is a pants decomposition for this surface. You can download the TeX file here.

\documentclass { amsart}

\usepackage { fullpage}

\usepackage { tikz}

\begin { document}

\begin { center}

\begin { tikzpicture}

\draw [ smooth] (5.5,-0.85) to[ out=180,in=30] (5,-1) to[ out=210,in=-30] (3,-1) to[ out=150,in=30] (2,-1) to[ out=210,in=-30] (0,-1) to[ out=150,in=-150] (0,1) to[ out=30,in=150] (2,1) to[ out=-30,in=210] (3,1) to[ out=30,in=150] (5,1) to[ out=-30,in=180] (5.5,0.85);

\draw [ smooth] (0.4,0.1) .. controls (0.8,-0.25) and (1.2,-0.25) .. (1.6,0.1);

\draw [ smooth] (0.5,0) .. controls (0.8,0.2) and (1.2,0.2) .. (1.5,0);

\draw [ smooth] (3.4,0.1) .. controls (3.8,-0.25) and (4.2,-0.25) .. (4.6,0.1);

\draw [ smooth] (3.5,0) .. controls (3.8,0.2) and (4.2,0.2) .. (4.5,0);

\node at (6.5,0){ $.\ ;\ ; .\ ;\ ; .$} ;

\draw [ smooth] (7.5,0.85) to[ out=0,in=210] (8,1) to[ out=30,in=150] (10,1) to[ out=-30,in=210] (11,1) to[ out=30,in=150] (13,1) to[ out=-30,in=30] (13,-1) to[ out=210,in=-30] (11,-1) to[ out=150,in=30] (10,-1) to[ out=210,in=-30] (8,-1) to[ out=150,in=0] (7.5,-0.85);

\draw [ smooth] (8.4,0.1) .. controls (8.8,-0.25) and (9.2,-0.25) .. (9.6,0.1);

\draw [ smooth] (8.5,0) .. controls (8.8,0.2) and (9.2,0.2) .. (9.5,0);

\draw [ smooth] (11.4,0.1) .. controls (11.8,-0.25) and (12.2,-0.25) .. (12.6,0.1);

\draw [ smooth] (11.5,0) .. controls (11.8,0.2) and (12.2,0.2) .. (12.5,0);

\draw (-0.5,0) arc(180:0:0.51 and 0.2);

\draw [ dashed] (-0.5,0) arc(180:0:0.51 and -0.2);

\draw (2.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (2.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (4.0,0.15) arc(270:90:0.3 and 1.14/2);

\draw [ dashed] (4.0,0.15) arc(270:450:0.3 and 1.14/2);

\draw (4.0,-0.15) arc(270:90:0.3 and -1.14/2);

\draw [ dashed] (4.0,-0.15) arc(270:450:0.3 and -1.14/2);

\draw (5.5,-0.85) arc(270:90:0.3 and 0.85);

\draw (5.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (7.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (7.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (9.0,0.15) arc(270:90:0.3 and 1.14/2);

\draw [ dashed] (9.0,0.15) arc(270:450:0.3 and 1.14/2);

\draw (9.0,-0.15) arc(270:90:0.3 and -1.14/2);

\draw [ dashed] (9.0,-0.15) arc(270:450:0.3 and -1.14/2);

\draw (10.5,-0.85) arc(270:90:0.3 and 0.85);

\draw [ dashed] (10.5,-0.85) arc(270:450:0.3 and 0.85);

\draw (13.5,0) arc(180:0:-0.51 and 0.2);

\draw [ dashed] (13.5,0) arc(180:0:-0.51 and -0.2);

\end { tikzpicture}

\end { center}

\end { document}

### Miscellaneous

Here are some other things I use.

I use a custom BibLaTeX style, which you can download here.

There isn't really anything special about this style; I just like having control over the way things look. There are, however, some significant negatives: this file only provides formatting rules for the specific cases I've encountered, and things will probably look inconsistent if you're citing anything more complicated than an

You can use this by placing the

\documentclass { amsart}

\usepackage { xcolor}

\definecolor { links} { HTML} { 500000}

\usepackage { hyperref}

\usepackage [ bibstyle=custom,citestyle=alphabetic] { biblatex}

\bibliography { refs.bib}

\begin { document}

% Write and \cite{} normally.

\printbibliography

\end { document}

and it should work like any other BibLaTeX style. Specifying DOI, Mathematical Reviews or arXiv numbers should produce corresponding links in the compiled bibliography.

For example, the following

@article { definitelyarealpaper ,

author ={ Bob, Alice and Dan, Carlos and Frank, Eve} ,

title ={ Meta-invariants for compact elliptic polytopes over hyper-bounded ideals} ,

fjournal ={ Journal of Pure and Applied Poppycock} ,

year ={ 2016} ,

mrnumber ={ 123456789} ,

doi ={ 10.1010/t.his.1sf2k3.2016.11.09} ,

arxiv ={ 1234.56789} ,

}

should produce something along the lines of

*Meta-invariants for compact elliptic polytopes over hyper-bounded ideals*. Journal of Pure and Applied Poppycock (2016).

upon compiling.

*It is a bad idea to compile and execute code that you've downloaded from a stranger's website, especially if you can't tell what it does. At a minimum, you should probably make offsite backups of all your own files before doing this. *

If you're left with the impression that I have too much time on my hands: most of the work involved in generating this page was automated.

To format the TeX code on this page, I wrote a Haskell program that does some rudimentary syntax matching and inserts HTML tags accordingly. You can download the source code here, though you'll be sorely disappointed if you're expecting something elegant or clever. This is certainly nowhere near as sophisticated as what you might find in an average TeX editor, and was only written to do the bare minimum of what I needed.

After you compile

$ ./converttex

to create a *it will be overwritten.*

At this point, you can simply paste the

Instead of pasting the code by hand, I insert the marker

REPLACEWITHCODE( filename)

for each

After you compile

$ ./replacewithcode inputfilewithoutcode.html outputfilewithcode.html

to replace all markers in

To produce the images, I include

\thispagestyle { empty}

in TeX to suppress page numbers, and then run

$ pdflatex filename.tex $ pdfcrop filename.pdf $ inkscape -l filename.svg filename-crop.pdf

on each file.