# TikZ figure inside equation?

I was wondering if it is possible to have a TikZ graphic inside an equation, to produce something similar to

-
Out of curiosity, what does those symbols represent? I guess that lifting weight and nose piercing are not the correct answers. :) – jnovacho May 19 '14 at 12:01
The first symbol stands for a direct edge between to vertices and the second one for the case of two vertices being connected along an alternative path... :-) – antarcticfox May 19 '14 at 12:47

\documentclass{article}
\usepackage{tikz}

\def\straight{\tikz[baseline=.1ex]{
\fill (0,0) circle (1pt) coordinate (A);
\fill (0,1.5ex) circle (1pt) coordinate (B);
\draw (A)--(B);}
}

\def\curved{\tikz[baseline=.1ex]{
\fill (0,0) circle (1pt) coordinate (A);
\fill (0,1.5ex) circle (1pt) coordinate (B);
\useasboundingbox (0,0) rectangle (.7ex, 1.5ex);
\draw (A) .. controls +(1ex,-1ex) and +(1ex, 1ex) .. (B);}%
}

\begin{document}

$P(\straight) + P(\curved) = p$

\end{document}


The tricky part is to get right the alignment. The vertical alignment can be controled with the option baseline of \tikz, which specifies the depth of the resulting glyph (the amount of it that protrudes below the base line). The horizontal alignment can be adjusted via \useasboundingbox, as in the curved example, which allows us to specify the size that TeX should leave for that glyph. The actual glyph actually is a bit bigger, but forcing tex to see it as smaller causes the right parenthesys to be placed closer.

-
Excellent! Thank you very much. I'll try to familiarise myself with the influence of baseline and useasboundingbox. – antarcticfox May 19 '14 at 10:57

A starter:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\begin{document}

$y=\tikz\draw (0,0)--(0,1); \, x$

\end{document}

-