Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
Out of curiosity, what does those symbols represent? I guess that lifting weight and nose piercing are not the correct answers. :) –  jnovacho May 19 at 12:01
2  
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 at 12:47

2 Answers 2

up vote 15 down vote accepted
\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}

Result

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.

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

A starter:

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

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

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.