# How could I add a graph to a post at MSE?

How could I add a graph to a post at MSE ? Is it possible to do this with mathjax ? If not, what would be an other way to add graphs to an question/answer. To illustrate, I would like to add something like this:

• A related question. May 8 '13 at 13:27
• BTW if it is something for which many various pictures might already exist on the internet, it is worth trying Google Images. In this case, if you search for Petersen graph you will find several similar pictures. Nov 29 '15 at 12:46
• See also How can I draw a tree like this? Apr 22 '16 at 4:24

Here's my workflow...

Step 1: create graph in LaTeX using tikz to draw the graph, and the standalone document class. (I use the TeX.SE site if I get stuck.) Here's an example.

\documentclass[crop]{standalone}

\usepackage{tikz}

\begin{document}

\resizebox{2in}{!}{
\begin{tikzpicture}[rotate=-90]
\tikzstyle{vertex}=[draw,thick,circle,fill=blue!30,minimum size=5pt,inner sep=0pt]
\tikzstyle{vertex2}=[draw,thick,circle,fill=green!30,minimum size=5pt,inner sep=0pt]

\draw[fill=red!15] (0,3) ellipse (0.25 and 2.4);
\draw[fill=red!15] (2,3) ellipse (0.25 and 2.4);

\draw (0,1) node[vertex] (v1) {};
\draw (0,2) node[vertex] (v2) {};
\draw (0,3) node[vertex] (v3) {};
\draw (0,4) node[vertex] (v4) {};
\draw (0,5) node[vertex] (v5) {};

\draw (2,1) node[vertex2] (u1) {};
\draw (2,2) node[vertex2] (u2) {};
\draw (2,3) node[vertex2] (u3) {};
\draw (2,4) node[vertex2] (u4) {};
\draw (2,5) node[vertex2] (u5) {};

\draw (v1) to[bend left] (v2);
\draw (v1) to[bend left] (v3);
\draw (v1) to[bend left] (v4);
\draw (v1) to[bend left] (v5);
\draw (v2) to[bend left] (v3);
\draw (v2) to[bend left] (v4);
\draw (v2) to[bend left] (v5);
\draw (v3) to[bend left] (v4);
\draw (v3) to[bend left] (v5);
\draw (v4) to[bend left] (v5);
\draw (u1) to[bend right] (u2);
\draw (u1) to[bend right] (u3);
\draw (u1) to[bend right] (u4);
\draw (u1) to[bend right] (u5);
\draw (u2) to[bend right] (u3);
\draw (u2) to[bend right] (u4);
\draw (u2) to[bend right] (u5);
\draw (u3) to[bend right] (u4);
\draw (u3) to[bend right] (u5);
\draw (u4) to[bend right] (u5);

\draw (u3) -- (v1);
\draw (u3) -- (v2);
\draw (u3) -- (v3);
\draw (u3) -- (v4);
\draw (u2) -- (v1);
\draw (u2) -- (v2);
\draw (u2) -- (v3);
\draw (u2) -- (v4);
\end{tikzpicture}
}

\end{document}


The \resizebox{2in}{!}{ ... } changes the size of the image; I adjust it via trial and error.

Step 2: Compile and convert to .png format. I do this in Kile, where it takes just a click of a button.

Step 3: Upload the .png file.

Note: usually I don't bother writing most of the tikz code myself, but instead write a GAP script to write the tikz code for me. I edit the output manually.

You can add very basic graphs using mathjax:

\begin{array}{ccccc}
&  & 1 &  \\
&╱&   &╲  \\
5 &  &   & & 2 \\
| &  &   & & |  \\
4 &  & — & & 3
\end{array}


\begin{array}{ccccc} & & 1 & & \\ & ╱ & & ╲ \\ 5 & & & & 2 & \\ | & & & & | \\ 4 & & — & &3 \end{array}

What you did seems to have worked. This is pretty much what everyone does: create an image using external software, and upload it to MSE via imgur.

• I just got this from google images. Any external software that you would recommend ? May 8 '13 at 13:20
• @Kasper I prefer SVG grahics for that (and in fact use a text editor more often than inkscape for simple graphs and graphics). Unfortunately, SVG is not supported for upload, so it needs to be converted (with gimp for example). I bet there are smarter options available, esp. with some math support. May 8 '13 at 14:45
• @Kasper: personally, I use Intaglio, but it is Mac only. Check out the link given by J.M. above. It seems to cover most of the programs I have seen others mention.
– robjohn Mod
May 8 '13 at 14:56
• @kasper You might find some reasonable suggestions on TeX.SE, too. You can browse questions tagged graphs; for example you find there this question. You can also have a look at the question about diagrams in community polls. May 8 '13 at 16:28