2

LyX documentation suggest to to use feyn package to draw Feynman Diagrams, It works fine, but unfortunately too restrictive and simple for my needs, I tried to use feynmf package instead, but it doesn't output anything, and I searched Internet for some possible examples/solution, but found none, are they compatible at first place? and if yes, can you please explain how to use it in LyX?

3
  • Ok, maybe at least somebody can advice how to build complex Feynman diagrams in LyX?
    – TMS
    Jun 24, 2014 at 20:59
  • I have no idea about Fynman diagrams, but can you import a working latex document into LyX to give you a start?
    – Nigel
    Sep 28, 2014 at 23:28
  • Any solutions yet? I actually got it to work with LyX a couple years ago, but now those documents compile blank again, and I don't know what changed. Nov 11, 2017 at 5:11

1 Answer 1

2

In order to use feynmf, you have to set up LyX to run mf (Metafont) in addition to pdflatex, on all the files generated by the feynmffile environments (as I understand it, having never used the package).

I don't actually know how to do that, but another option altogether that requires no such extra step is the tikz-feynman package. Add

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

to Document --> Settings --> LaTeX preamble, and you can write code such as

\feynmandiagram [horizontal=a to b] {
  i1 -- [fermion] a -- [fermion] i2,
  a -- [photon] b,
  f1 -- [fermion] b -- [fermion] f2,
};

directly in an ERT, and get this:

enter image description here

Important note

tikz-feynman uses the graph drawing libraries of TikZ to place vertices automatically, but this only works when the PDF is generated with luatex. With pdflatex, which default in LyX, the above code will generate

pdflatex output

which is less nice.

So if you want this automatic layout, you must PDF (LuaTeX) as the output format, for example in Document --> Settings --> Format.

But you can also place things manually, and then pdflatex has no problems. To generate a diagram like the above, you can use the following code in an ERT.

\begin{tikzpicture}
 \begin{feynman}
    \vertex (a);
    \vertex [above left=of a] (i1);
    \vertex [below left=of a] (i2);
    \vertex [right=of a] (b);
    \vertex [above right=of b] (f1);
    \vertex [below right=of b] (f2);

    \diagram*{
      (i1) --[fermion] (a) --[fermion] (i2),
      (a) --[photon] (b),
      (f1) --[fermion] (b) --[fermion] (f2)
    };
  \end{feynman}
\end{tikzpicture}

See the package manual for more information about its capabilities.

Example .lyx file:

#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\usepackage[compat=1.1.0]{tikz-feynman}
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
feynmandiagram [horizontal=a to b] {
\end_layout

\begin_layout Plain Layout

  i1 -- [fermion] a -- [fermion] i2,
\end_layout

\begin_layout Plain Layout

  a -- [photon] b,
\end_layout

\begin_layout Plain Layout

  f1 -- [fermion] b -- [fermion] f2,
\end_layout

\begin_layout Plain Layout

};
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
begin{tikzpicture}
\end_layout

\begin_layout Plain Layout


\backslash
begin{feynman}
\end_layout

\begin_layout Plain Layout


\backslash
vertex (a);
\end_layout

\begin_layout Plain Layout


\backslash
vertex [above left=of a] (i1);
\end_layout

\begin_layout Plain Layout


\backslash
vertex [below left=of a] (i2);
\end_layout

\begin_layout Plain Layout


\backslash
vertex [right=of a] (b);
\end_layout

\begin_layout Plain Layout


\backslash
vertex [above right=of b] (f1);
\end_layout

\begin_layout Plain Layout


\backslash
vertex [below right=of b] (f2);
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout


\backslash
diagram*{
\end_layout

\begin_layout Plain Layout

      (i1) --[fermion] (a) --[fermion] (i2),
\end_layout

\begin_layout Plain Layout

      (a) --[photon] (b),
\end_layout

\begin_layout Plain Layout

      (f1) --[fermion] (b) --[fermion] (f2)
\end_layout

\begin_layout Plain Layout

    };
\end_layout

\begin_layout Plain Layout


\backslash
end{feynman}
\end_layout

\begin_layout Plain Layout


\backslash
end{tikzpicture}
\end_layout

\end_inset


\end_layout

\end_body
\end_document

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .