JP-Ellis / tikz-feynman

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

Can't compile a document with feynmandiagram within an equation environment #19

Closed giordano closed 8 years ago

giordano commented 8 years ago

Maybe I'm missing something, when I try to compile the snippet provided in documentation regarding using \feynmandiagram within an equation environment compilation (with lualatex) fails with many errors

\documentclass[tikz]{standalone}
\usepackage{tikz-feynman}
\begin{document}
\begin{equation}
  \feynmandiagram [inline=(d.base), horizontal=d to b] {
    a -- [fermion] b -- [fermion] c,
    b -- [boson] d [particle=\(\gamma\)],
  };
  = i g_{e} \gamma^{\mu}
\end{equation}
\end{document}

Here are some of the errors:

./test.tex:8: Missing $ inserted.
<inserted text> 
$
l.8   };

./test.tex:8: Missing \endgroup inserted.
<inserted text> 
\endgroup 
l.8   };

./test.tex:8: Display math should end with $$.
<to be read again> 
\par 
l.8   };

[1]
./test.tex:9: Missing $ inserted.
<inserted text> 
$
l.9   = i g_
          {e} \gamma^{\mu}
./test.tex:10: You can't use `\eqno' in math mode.
\endequation ->\eqno 
                     \hbox {\@eqnnum }$$\@ignoretrue 
l.10 \end{equation}

./test.tex:10: LaTeX Error: \begin{document} ended by \end{equation}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 \end{equation}

./test.tex:10: Missing $ inserted.
<inserted text> 
$
l.10 \end{equation}

./test.tex:10: Extra \endgroup.
<recently read> \endgroup 

l.10 \end{equation}

What am I missing?

giordano commented 8 years ago

For the record, this happens only with standalone class, not with article, so maybe this isn't a bug in the package.

JP-Ellis commented 8 years ago

Hi Mosè,

Yeah, I'm not exactly sure what the cause of this is, but loading the tikz options for standalone does some weird stuff. In particular, it will try and start and stop the page at each \begin{tikzpicture} and \end{tikzpicture} (or equivalent therefore). The final semi-colon at the end of the \feynmandiagram declaration behaves like an \end{tikzpicture} so the standalone starts a new page. I can only guess that in the process, it no longer is in a math environment, hence the errors. Even if it did compile, you wouldn't get your desired result.

You can try it without the tikz option, it might work better for this case.

Josh

On Mon, Feb 8, 2016 at 10:29 AM Mosè Giordano notifications@github.com wrote:

For the record, this happens only with standalone class, not with article, so maybe this isn't a bug in the package.

— Reply to this email directly or view it on GitHub https://github.com/JP-Ellis/tikz-feynman/issues/19#issuecomment-181139742 .

giordano commented 8 years ago

You can try it without the tikz option, it might work better for this case.

Almost: loading tikz as a package, as usual, at least makes the figure appear in the output file, but I still get errors during compilation.

If you think it's rather something weird on standalone side, feel free to close this ticket!

JP-Ellis commented 8 years ago

Yeah, I believe it is an issue with standalone, so I will close this issue. Thanks for the heads up though!