JP-Ellis / tikz-feynman

Feynman Diagrams with TikZ
http://www.jpellis.me/projects/tikz-feynman
Other
148 stars 20 forks source link

inline/baseline for feynman environment in equations #32

Closed pseth closed 8 years ago

pseth commented 8 years ago

Hi again,

I am trying to create this equation with a feynman diagram in it. I can't use \feynmandiagram as I can't seem to get two loops from independent vertices (or from the same vertex for that matter) so I have decided to do this:

\begin{equation}
Z = 1 + U 
  \begin{tikzpicture}
    \begin{feynman}
      \vertex[dot] (a) {};
      \draw (a) arc [start angle=270, end angle=-90, radius=0.3cm];
      \draw (a) arc [start angle=90, end angle=-270, radius=0.3cm];
    \end{feynman}
  \end{tikzpicture}
    + \ldots
\end{equation}

However, I can't get the equation to line up with the vertex using either \begin{feynman}[inline=(a)] or \begin{feynman}[baseline=(a)]. I understood that the same arguments to \feynmandiagram are applicable to the feynman environment. Am I mistaken?

Thanks again!

JP-Ellis commented 8 years ago

Hi,

You are looking at a somewhat subtle point here, which I perhaps should make a little clearer in the documentation, though it only occurs in this particular context (as far as I know).

The inline style uses the baseline style internally so that the resulting image has the appropriate baseline; however, the baseline style only works on the whole Ti_k_Z picture and thus has to be given as an optional argument after \begin{tikzpicture}. When you use \tikzfeynman[inline=(a)], it ensures that the Ti_k_Z environment it creates has the appropriate baseline style and on the surface it's all quite simple.

This changes when you use \begin{feynman} as any style applied to that environment only affects that environment. This means that although \begin{feynman}[inline=(a)] will try and use the baseline style, it won't have an effect because the baseline of the whole Ti_k_Z picture will remain unchanged.

So what you want is:

\documentclass{standalone}

\usepackage{amsmath}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\begin{equation*}
  Z = 1 + U
  \begin{tikzpicture}[baseline=(a)]
    \begin{feynman}[inline=(a)]
      \vertex[dot] (a) {};
      \draw (a) arc [start angle=270, end angle=-90, radius=0.3cm];
      \draw (a) arc [start angle=90, end angle=-270, radius=0.3cm];
    \end{feynman}
  \end{tikzpicture}
  + \ldots
\end{equation*}
\end{document}

1

This (to me) doesn't look exactly right yet... it would be nice if the dot could line up with the plus sign which is actually above the baseline. This can be achieved with:

\RequirePackage{luatex85}
\documentclass{standalone}

\usepackage{amsmath}
\usepackage[compat=1.1.0]{tikz-feynman}

\begin{document}
\begin{equation*}
  Z = 1 + U
  \begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax]
    \begin{feynman}[inline=(a)]
      \vertex[dot] (a) {};
      \draw (a) arc [start angle=270, end angle=-90, radius=0.3cm];
      \draw (a) arc [start angle=90, end angle=-270, radius=0.3cm];
    \end{feynman}
  \end{tikzpicture}
  + \ldots
\end{equation*}
\end{document}

2

pseth commented 8 years ago

Interesting, thanks for the speedy reply and solution.

By the way, a separate point not related to your package, but still useful to someone with this question; I noticed that in the standalone mode I can't get the maths fonts to render (even after importing all the ams* packages). I found two solutions:

phyjswang commented 6 years ago

Thank you a lot, Ellis, especially this modification:

baseline=-\the\dimexpr\fontdimen22\textfont2\relax

which I have no idea how it works though...