# Align TikZ node inside equation environment

I am trying to insert a TikZ node into an equation but I have some problems:

1. the = sign is not vertically centred inside the circle
2. the circle is not vertically aligned with the formula. I want to abtain the same alignment of the first equation but I failed also using the baseline option
3. the equal sign must be at same distance from ) as in the first equation

SOLUTIONS

1. UNSOLVED
2. Solved in comments using baseline=-\the\dimexpr\fontdimen22\textfont2\relax
3. UNSOLVED

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\mathnodebase}{%
\tikz[inner sep = 0pt,baseline]{\node[circle,draw=black] (1) {$=$};}}
\newcommand{\mathnode}{%
\tikz[inner sep = 0pt]{\node[circle,draw=black] (1) {$=$};}}

\begin{document}
$$\prod_{z^n=-1}(w_1(z)^n+1) =$$
$$\prod_{z^n=-1}(w_1(z)^n+1) \mathnodebase$$
$$\prod_{z^n=-1}(w_1(z)^n+1) \mathnode$$
\end{document}


• The credit for having found the right setting to vertically align elements drawn with TikZ in math mode goes to egreg (no surprise thus): see his comment here. – Claudio Fiandrino Aug 23 '13 at 18:17
• @ClaudioFiandrino thanks. This solves the second point. – Red Aug 23 '13 at 18:38
• Should the = in the circle have the spacing as the normal = or should the new symbol (including the circle) should have that spacing? – Qrrbrbirlbel Aug 23 '13 at 23:19
• @Qrrbrbirlbel the = in the circle should have the same spacing as the normal =. But the third point is not so important, the more important is the first one. – Red Aug 23 '13 at 23:23

For a single symbol like = the vertical alignment is easier reached with baseline and anchor=base (this means the baseline of the node will be vertically aligned at the y = 0 while baseline implicits baseline=0pt).

Though egreg’s formula is used here to get a node where the = sits vertically centered (the original box of TeX is not symmetrical).

An overlayed circle is then placed at the .center of that node. The overlay option takes the circle out of the bounding box of that TikZ picture so that \mathrel works as if it was a single =.

## Code

\documentclass{article}
\usepackage{amsmath,tikz}
\newcommand{\tikzeq}{%
\mathrel{%
\tikz[baseline]{
\node[inner sep=+0pt, outer sep=+0pt, anchor=base, text depth=+0pt, text height=\the\dimexpr2\fontdimen22\textfont2\relax, name=tikz@equal] {${=}$};
}%
}%
}

\begin{document}
$\prod_{z^n=-1}(w_1(z)^n+1) =$
$\prod_{z^n=-1}(w_1(z)^n+1) \tikzeq$

$a=b \tikzeq c = \tikzeq$
\begin{gather} a = b \\ a \tikzeq b    \end{gather}
\end{document}