\documentclass[thesis_guide.tex]{subfiles}
% chktex-file 1 chktex-file 46

\begin{document}

%==============================================================================
\chapter{Figures and Feynman graphs}%
\label{sec:fig}\index{figures}\index{Feynman graphs}
%==============================================================================

\LaTeX\ file: \href{run:./guide_figs.tex}{guide\_figs.tex}\\[1ex]
\noindent
This chapter discusses what you need to know to include graphics in
your thesis. The basic command to use is \Macro{includegraphics}.
I found a pretty complete guide (in German) called \texttt{l2picfaq}
which can be obtained from
\url{http://www.ctan.org/tex-archive/info/l2picfaq/german}. It contains
a lot of detailed information and tricks.
This chapter also contains some suggestions as to how to create Feynman
graphs with a number of different packages.


%------------------------------------------------------------------------------
\section{Simple figures}%
\label{sec:fig:simple}
%------------------------------------------------------------------------------

A simple figure and its associated caption is straightforward to include.
For example, the layout of the LHC and its experiments is
shown in \cref{fig:LHC}.
Don't forget to use the package \Package{cleveref} and macros such as \Macro{cref}
to reference the figures -- see \cref{G-sec:package:appearance} for a few more details.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\includegraphics[width=\figwidth]{CERN_all-experiments}
\caption[Sketch of the LHC ring, the position of the experiments and
  the surrounding countryside.]{Sketch of the LHC ring, the position
  of the experiments and the surrounding countryside. The four big
  LHC experiments are indicated. The location of the injection lines
  and the SPS are also shown.}%
\label{fig:LHC}
\end{tcblisting}
\end{figure}

Note the use of \Macro{centering} rather than the environment
\BegEnv{center} \ldots \EndEnv{center} to centre the figure. This
avoid adding extra vertical space. It is also important that the
\Macro{label} be either inside the caption or after it. If your
caption is more than 1 (or 2) lines, you should also give a short form
that will appear in the ``List of Figures''.

One tricky question is how to best format the caption. This document
uses a smaller font and no extra indentation. Often italics are
used. I dislike this, as symbols are then formatted in different ways
in the main text and in the caption. One can also reduce the width of
the caption. The font for the caption can be specified using the
\Macro{setkomafont}\texttt{\{caption\}} command. You can specify how
to label the figure by changing the \Macro{figureformat} command. The
captions in this document follow the standard \KOMAScript{}
convention: if they are one line long they are centred; if they are
longer they are left-adjusted. If you want them all to be
left-adjusted set the \Option{KOMAoptions\{caption=nooneline\}}
in \File{ubonn-thesis.sty}. Some examples of the possibilities are
included in the style file.

Another thing to consider is whether the caption text should be indented or
not. For short captions, indentation is OK\@. I do not think it looks
good for long captions. Hence the style file sets
\Macro{setcapindent}\texttt{\{0pt\}}.

%------------------------------------------------------------------------------
\section{Fancier figures}%
\label{sec:fig:fancy}\index{figures!multiple}
%------------------------------------------------------------------------------

Life gets more complicated if you want to include several plots in
one figure, if you want the caption next to the figure, or if you want
the text to \enquote{flow} around the figure. For the first case I like to
use the \Env{tabular} environment to place the plots, although
there are other ways of doing it.

Another very nice way to add (a), (b) etc.\ to the figure is to use the
\Macro{put} command. This has the big advantage that you can display
the letters in the figure without actually having to add them to the
EPS/PDF file. \Cref{fig:letters1} shows how this is done. Note
that the origin of the coordinate system is the bottom right-hand
corner of the file that you have included (assuming that the
\Macro{put} command comes just after the \Macro{includegraphics}).
The units for the \Macro{put} command are set with the
\Macro{setlength}\texttt{\{\textbackslash unitlength\}} command, which
is by default set to \qty{1}{\mm} in \texttt{ubonn-thesis.sty}.
The same units are also used for Feynman graphs made with the
\Package{feynmf} and/or \Package{feynmp} package -- see
\cref{sec:fig:feynman:feynmp}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\includegraphics[height=3cm]{gg_ttbar_1-BW}\quad
\includegraphics[height=3cm]{gg_ttbar_2-BW}\quad
\includegraphics[height=3cm]{gg_ttbar_3-BW}
\put(-130,14){(a)}
\put(-80,14){(b)}
\put(-35,14){(c)}
\caption{Adding letters to figures with \Macro{put}.}%
\label{fig:letters1}
\end{tcblisting}
\end{figure}

Another way of achieving the same thing, but this time with the letter
outside the figure is to use \Env{tabular}. An example of this is
shown in \cref{fig:letters2}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\begin{tabular}{ccc}
\includegraphics[width=0.33\figwidth]{gg_ttbar_1-BW} &
\includegraphics[width=0.3\figwidth]{gg_ttbar_2-BW} &
\includegraphics[width=0.3\figwidth]{gg_ttbar_3-BW}\\
(a) & (b) & (c)
\end{tabular}
\caption{Adding letters to figures with \Env{tabular}.}%
\label{fig:letters2}
\end{tcblisting}
\end{figure}

If you want to save space it is sometimes nice to put the caption next
to the figure. While packages exist to do this, \KOMAScript{} has its
own built-in \Env{captionbeside} environment. The placement option comes
after the caption itself and can be one of:
\begin{description}\setlength{\parskip}{0pt}
\item[l] Left of figure
\item[r] Right of figure
\item[i] Inner margin in two-sided layout
\item[o] Outer margin in two-sided layout
\end{description}
Note that this is an environment rather than a macro and that the
figure itself is inside the environment. Also the placement does not
seem to work exactly how it is advertised in the manual. I set the
width equal to \Macro{figwidth} and then the offset to \texttt{-\Macro*{figwidth}}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\begin{captionbeside}{A small figure with a simple caption beside it.}[i][\figwidth][-\figwidth]
  \includegraphics[width=0.3\textwidth]{qq_ttbar-BW}
\end{captionbeside}%
\label{fig:qqtt}
\end{tcblisting}
\end{figure}

If you want different (partial) captions for a figure then the
\Package{subfig} package used to be the way to go. 
An alternative, and successor, to \Package{subfig} is \Package{subcaption}.
It works in much the same way as \Package{subfig}.
A nice tutorial on its use can be found in
\url{http://www.peteryu.ca/tutorials/publishing/latex_captions}.
Examples of the different \Package{subcaption} macros can be seen in \cref{fig:nccc,fig:pyfeynhand}.
You can see how to reference
the different parts of the figure in \cref{sec:fig:feynman}.
If you want the captions of the sub-figures to also appear in the
\enquote{List of Figures} you should include the package with the
option \Option{lofdepth}. For tables use the option \Option{lotdepth}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\begin{subfigure}[b]{0.5\figwidth}
  \includegraphics[width=0.5\figwidth]{ep_nc}
  \caption{NC scattering}\label{fig:nccc-nc}
\end{subfigure}
\qquad
\begin{subfigure}[b]{0.5\figwidth}
  \includegraphics[width=0.5\figwidth]{ep_cc}
  \caption{CC scattering}\label{fig:nccc-cc}
\end{subfigure}
\caption{Processes in $ep$ scattering.}%
\label{fig:nccc}
\end{tcblisting}
\end{figure}

If you run out of space (applies more often to proceedings than to theses)
you can use the \Package{wrapfig} package.


%------------------------------------------------------------------------------
\section{Figure formats}%
\label{sec:fig:formats}\index{figures~formats}
%------------------------------------------------------------------------------

If you use plain \LaTeX, you are pretty much stuck with encapsulated
postscript (EPS) as your figure format. If you use pdf\LaTeX, then you
have much more freedom, with the notable exception that you cannot
include EPS files!\footnote{%
This restriction has finally been lifted with \TeXLive 2011.
It simply converts the EPS files to PDF inline.}
I would still recommend that you always try to use
a vector graphic format. What usually works well is to either create
PDF directly or to create EPS and then convert from EPS to PDF\@.

The tool I use for conversion is \texttt{epstopdf}. Occasionally this
fails; in that case \texttt{eps2eps} can help. It is important that
the bounding box is set correctly in the EPS file before you run
\texttt{epstopdf}.

If these fail, you can try the \texttt{convert} command which is part
of \texttt{ImageMagick}. A more powerful tool is \texttt{inkscape}
which is a successor to \texttt{xfig}. Professionals use Adobe Illustrator!


%------------------------------------------------------------------------------
\section{Placement}%
\label{sec:fig:placement}
%------------------------------------------------------------------------------

Even after many years of including figures into \LaTeX\ files, I
still think there is a fair amount of black magic involved in getting
them into the place that you want them to be.

In general, you are advised to give \LaTeX{} as much freedom as
possible in the placing, so it is usual to use the options
\Option{[htbp]} for the placement.
In particular, be very careful with
using just \Option{[h]} or \Option{[H]} as the placement option. It very
easily leads to \LaTeX{} putting single lines of text either above or
below a figure.
One way to get rid of single lines is to remove the option \Option{h},
as the figure must then be placed at the top or bottom of the page
(or on a page of floats).
You can also add an \Option{!} in the list
of options, which suspends spacing and number restrictions.

A nice summary of the logic behind the placement can be found in
\href{http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat}{\TeX/\LaTeX\ Stack Exchange} (click on the link!).
A couple of points from there that are worth mentioning here:
\begin{itemize}
\item The order of the options \Option{htbp} has no effect!
\item If a float is placed in the middle of a paragraph,
  the reference point for deciding where it will appear is the next line break or page break in the paragraph,
  following the float.
\item The order of figures (and tables) is fixed to the order that they are included in a document.
  However, the order of figures and tables relative to each other is not fixed.
\end{itemize}

The
\href{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=floats}{UK List of FAQ}
recommends changing several default \LaTeX\ options so that there are fewer problems
with figure and table placement.
It is certainly worth reading that page for further advice.
As it is very hard to really test how well these options work
they can be turned on or off in \Package{ubonn-thesis} via the option \Option{floatopt=true|false}.
The default value is set to \Option{true}.

I used to think it was better to attach the figure to a paragraph.
More recently it appears to me to be better to separate the figure
from the paragraph.
What I mean is illustrated below:
\begin{tcblisting}{listing only}
\Cref{fig:funny1} is attached to the paragraph.
%
\begin{figure}[htbp]
  \centering
  \includegraphics[width=\figwidth]{file}
  \caption{An odd plot that I don't understand.}
  \label{fig:funny1}
\end{figure}
%
The distribution shows something that I do not understand.

Given that this is not understood we went to the pub for a beer to
think about it a bit more.
\end{tcblisting}

\begin{tcblisting}{listing only}
\Cref{fig:funny2} is separated from the paragraph by a blank line.
The distribution shows something that I do not understand.

\begin{figure}[htbp]
  \centering
  \includegraphics[width=\figwidth]{file}
  \caption{An odd plot that I don't understand.}
  \label{fig:funny2}
\end{figure}

Given that this is not understood we went to the pub for a beer to
think about it a bit more.
\end{tcblisting}

However, it is hard to give a hard and fast rule here.
As indicated above, the effect of these different ways of including a figure (and table) is the point in the text (reference point) that \LaTeX\ uses to start trying to place the figure.
In general, you should only try to tweak the position of figures and tables when your text is final,
as a change in the text may well move some of the floats.

%------------------------------------------------------------------------------
\subsection{\Package{standalone} package and class}%
\label{sec:fig:standalone}

The \Package{standalone} package provides a great way of developing
figures in small files and then inputting these files directly,
without making any changes, into your thesis!

It is in fact both a package and a document class.
% It is available from \TeXLive 2012 onward.
It allows you to have a
standalone document for a \Package{\TikZ} or \Package{feynmf} figure
and also input this file into another document. If you run pdf\LaTeX\
on the file it also automatically crops the resulting picture. This is
one of those packages where you think
\enquote{Why didn't someone create this years ago?}.
The \TikZ figures (as well as those made using \Package{TikZ-FeynHand})
that I include in this guide (see subdirectories \texttt{tikz} and \texttt{pyfeynhand})
make use of this package.
If you want to use it, make sure that you also include this package in
your thesis.


%------------------------------------------------------------------------------
\section{Feynman graphs}%
\label{sec:fig:feynman}\index{figures!Feynman graphs}\index{Feynman graphs}
%------------------------------------------------------------------------------

You have lots of Feynman graphs you want to include, but how do you generate them? 
Most of my Feynman graphs are drawn using a \TikZ package, which means that they are created in a \LaTeX\ file.
Two possibilities are \Package{TikZ-Feynman} and \Package{TikZ-FeynHand}.
I have written a Python wrapper for \Package{TikZ-FeynHand},
which hopefully allows me to combine the best of both worlds!
The wrapper code and an example can be found in the \File{pyfeynhand} directory.
More details on the use of \Package{TikZ-FeynHand} and my Python wrapper \Package{PyFeynhand}
can be found in \cref{sec:fig:feynman:tikz}.\footnote{%
For a few years I used a Python package \Package{PyFeyn} (\url{https://pyfeyn.hepforge.org})
that works quite nicely once you have it set up.
However, the package does not seem to be actively developed any more
and fixes are needed before it works with the latest \Package{PyX} version,
which is the drawing tool it uses.
}

Before I started using Python packages, I followed the example of many people,
where I found one way doing making graphs and never changed!
I used \texttt{Mn\_Fit},
mainly because I wrote it and therefore know inside out how it works.
Examples can be found on my web page:
\url{http://pi.physik.uni-bonn.de/~brock/feynman}.
Alternatives include \Package{axodraw2} and the \Package{feynmf} or
\Package{feynmp} packages.

An example using the package \Package{axodraw2} is available in \cref{sec:fig:axodraw}.
Several people have claimed
that \texttt{jaxodraw} is the way to go. This is a Java package which
you can download from \url{https://jaxodraw.sourceforge.io}. It has
a Graphical User Interface (GUI) to \Package{axodraw} and so is simple and
straightforward to use.

The use of \Package{feynmf} and \Package{feynmp} is
described in \cref{G-sec:fig:feynman:feynmp}, while a few
examples of usage of \Package{\TikZ} are given in
\cref{G-sec:fig:feynman:tikz}.
Examples of Feynman graphs made
with \Package{feynmf} and \Package{feynmp} can be found in the \texttt{feynmf} directory;
those made with \Package{TikZ-FeynHand} can be found in the \texttt{pyfeynhand} and \texttt{tikz} subdirectories;
while those made with \Package{\TikZ} can be found in the \texttt{tikz} subdirectory.

\begin{tcblisting}{}
This paragraph illustrates how to reference different parts of a
figure that uses the environment \Env{subfigure} from
the package \Package{subcaption}.
The NC and CC graphs shown in \cref{fig:nccc}, or more accurately
in \cref{fig:nccc-nc} and \cref{fig:nccc-cc} were made with \Package{feynmp}.
Another way of saying the same thing is that typical Feynman graphs
for \(ep\) scattering are shown in \cref{fig:nccc},
where \subref{fig:nccc-nc} shows a neutral current and \subref{fig:nccc-cc}
show a charged current process.
\end{tcblisting}


%------------------------------------------------------------------------------
\subsection{Feynman graphs with \TikZ (and Python)}%
\label{sec:fig:feynman:tikz}\index{TikZ@\TikZ}\index{PyFeynHand}

There are (at least) two packages based on \TikZ that exist to draw Feynman graphs:
\Package{TikZ-Feynman} and \Package{TikZ-FeynHand}.
If you want to use the automatic placement features of \Package{TikZ-Feynman}
you have to use \LuaLaTeX.
Hence, I am inclined to use the \Package{TikZ-FeynHand} package.\footnote{%
Note that the \Package{TikZ-FeynHand} package was first included at some point in 2017.}
It does not seem to be possible to adjust the amplitude and frequency
of boson and gluon oscillations explicitly.
This has to be done using the \Macro*{setlength\{\textbackslash feynhandlinesize\{1.0pt\}\}} command.
This also, as the name suggest, changes the line thickness.
After a bit of playing around \num{1.0}{pt} seems to work well,
with a Feynman graph size of about \qty[parse-numbers=false]{2 \times 2}{\cm^{2}}.

I like using a scripting language, e.g.\ Python, to draw my graphs.
I have therefore written a Python wrapper for \Package{TikZ-FeynHand}.
You can find the wrapper and a couple of example scripts in the \File{pyfeynhand} directory.
The wrapper creates a \LaTeX\ file,
which can either be compiled or included directly in your document,
as it uses the \Package{standalone} package.
Have a look at the \File{README.md} file in that directory for some more details.

Many more example graphs can be found in the Git repositories:\\
{\footnotesize\url{https://gitlab.cern.ch/atlasphys-top/singletop/PubUtils/FeynmanDiagrams/PyFeynHand}} ATLAS\\
{\footnotesize\url{https://gitlab.uni-bonn.de/unp00039/PyFeynHand.git}} Uni Bonn

\Cref{fig:feyn:tdecay} shows two graphs from one of my favourite processes.
These graphs are made using \Package{TikZ-FeynHand} commands directly,
while the \TeX{} file was originally created using the Python wrapper.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\begin{subfigure}{0.5\figwidth}
  \centering
  \subfile{../tikz/tdecay.tex}
  \caption{\LaTeX\ file}%
  \label{fig:feyn:tdecay1}
\end{subfigure}
\qquad
\begin{subfigure}{0.5\figwidth}
  \centering
  \includegraphics[width=0.5\figwidth]{../tikz/tdecay}
  \caption{PDF file}%
  \label{fig:feyn:tdecay2}
\end{subfigure}
\caption{Feynman graphs made with the \Package{TikZ-FeynHand} package.
  This example uses the \Env{subfigure} environment from the \Package{subcaption} package.
  \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:feyn:tdecay}
\end{tcblisting}
\end{figure}

\Cref{fig:pyfeynhand:ttbar,fig:pyfeynhand:tdecay} show a graph for \ttbar production,
as well as one for top-quark decay that uses quite a lot of the bells and whistles available
in \Package{TikZ-FeynHand} and \Package{PyFeynHand}.
The resulting PDF files are included directly,
while the graphs have been made using the command \Command{make pyfeynhand}.
\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\subcaptionbox{\ttbar production\label{fig:pyfeynhand:ttbar}}
  [0.5\figwidth]{%
    \includegraphics{gg_ttbar_2}
}
\qquad
\subcaptionbox{Top-quark decay\label{fig:pyfeynhand:tdecay}}
  [0.5\figwidth]{%
  \includegraphics{tdecay}
}
\caption{Feynman graphs made with the \Package{PyFeynHand} wrapper.
  This example uses the \Env{subcaptionbox} macro from the \Package{subcaption} package.}%
\label{fig:pyfeynhand}
\end{tcblisting}
\end{figure}

A diagram for \Pgm decay using the \Package{TikZ-Feynman} package
is shown in \cref{fig:feyn:mudecay}.
This uses the manual placement style so that I can compile the guide with \Command{pdflatex}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\begin{subfigure}{0.6\figwidth}
  \centering
  \subfile{../tikz/mudecay-feynman.tex}
  \caption{\LaTeX\ file}%
  \label{fig:feyn:mudecay1}
\end{subfigure}
\qquad
\begin{subfigure}{0.4\figwidth}
  \centering
  \includegraphics[width=0.4\figwidth]{../tikz/mudecay-feynman}
  \caption{PDF file}%
  \label{fig:feyn:mudecay2}
\end{subfigure}
\caption{Feynman graphs made with the \Package{TikZ-Feynman} package.
  This example uses the \Env{subfigure} environment from the \Package{subcaption} package.
  The example is taken from \url{https://www.overleaf.com/learn/latex/feynman_diagrams}.
  \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:feyn:mudecay}
\end{tcblisting}
\end{figure}

If you want to draw Feynman graphs using \TikZ directly,
you need to include some extra \TikZ packages and libraries.
In addition it makes sense to
define things like gluons, photons and incoming and outgoing particles
once, as these are objects that are often needed.

We can directly compare a scattering graph made with
\Package{feynmp}, \Package{\TikZ} and \Package{TikZ-FeynHand}.
This is shown in \cref{fig:feyn:cf}.
As you can see the quality of the graphs is very similar.
Further tweaking can probably make them almost identical.
In the \Package{TikZ-FeynHand} graph, I use lots of colours to illustrate how they work.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\subcaptionbox{feynmp\label{fig:feyn:feynmp}}
  [0.325\textwidth]{\fbox{%
    \input{../feynmf/moeller.tex}
    \write18{mpost moeller}
  }
}
\subcaptionbox{\TikZ\label{fig:feyn:tikz}}
  [0.325\textwidth]{\fbox{%
    \subfile{../tikz/moeller-tikz.tex}
  }
}
\subcaptionbox{TikZ-FeynHand\label{fig:feyn:feynhand}}
  [0.325\textwidth]{\fbox{%
    \subfile{../tikz/moeller-feynhand.tex}
  }
}
\caption{Feynman graphs drawn with \Package{feynmp}, \Package{\TikZ} and \Package{TikZ-FeynHand}.
  The frames around the boxes are for illustration only.
  As you can see the \Package{feynmp} box does not include the labels.
  This example uses the \Macro{subcaptionbox} macro from the \Package{subcaption} package.
  \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:feyn:cf}
\end{tcblisting}
\end{figure}

\FloatBarrier

%------------------------------------------------------------------------------
\subsection{Axodraw}%
\label{sec:fig:axodraw}\index{axodraw}\index{axodraw2}

\Cref{fig:axodraw:ppttbar} was given to me by Richard Nisius and illustrates some of the
things that can be done using the \Package{axodraw2} package.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\subfile{../axodraw/pp-tt-btoX}
\caption{\ttbar production in \Pp{}\Pp collisions.
  The code for this figure can be found in \File{axodraw/pp-tt-btoX.tex}.
  \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:axodraw:ppttbar}
\end{tcblisting}
\end{figure}

For some reason the guide does not compile when I try to include
the \Package{standalone} class in the figure document.
Hence, the directory \File{axodraw/axodraw-standalone} contains a \Package{standalone} wrapper,
which can be compiled separately.
If you use \texttt{pdflatex} to compile your document,
you need to either run \texttt{axohelp file}\index{axohelp} after \texttt{pdflatex file},
or add the following lines to your \texttt{latexmk}\index{latexmk} configuration.

\begin{bashlisting}
add_cus_dep( "ax1", "ax2", 0, "axohelp" );
sub axohelp { return system "axohelp \"$_[0]\""; }
$clean_ext .= " %R.ax1 %R.ax2";
\end{bashlisting}

See the \Package{axodraw2} manual for more information.

%------------------------------------------------------------------------------
\subsection{FeynMP}%
\label{sec:fig:feynman:feynmp}\index{feynmp}

In order to use the \Package{feynmp} package, you have to put
the commands to draw the graph in a \LaTeX\ file and then process
this file with \LaTeX\ and either Metafont or
Metapost.\footnote{\texttt{ubonn-thesis.sty} now includes \Package{feynmp}
  by default.
  If you want to use \Package{feynmf} instead just change the name.} 
You can either make
a separate \LaTeX\ file containing the Feynman graph or include the
commands inside your normal \LaTeX\ file.
Metapost\index{metapost} is a bit easier to use than Metafont.
You should be able to just run
\texttt{mpost} after \texttt{(pdf)latex} and then run % chktex 36
\texttt{pdflatex} again twice.
Note that you have to run
\texttt{mpost} on all the files whose names are defined at the
beginning of the \Env{fmffile} environment.

Metafont\index{metafont} is a bit trickier and details have been relegated to
\cref{G-sec:app:fig:feynman:feynmf}. 
On Unix systems the \texttt{feynmf} perl script exists that runs both \LaTeX{} and
Metafont for you. This will produce a \texttt{dvi} file that you then
then look at or use to make a Postscript/PDF file.

I think a better way to proceed is the following:
\begin{itemize}
\item make a separate \LaTeX\ file for each of the Feynman graphs;
\item input this file in your figure;
\item use the \File{Makefile} described below to automatically run
  over one or all \Package{feynmp}/\Package{feynmf} \LaTeX\ files by giving the
  command \texttt{make feynmp} or \texttt{make feynmf}.\\
  Check
  \texttt{./feynmf/feynmf\_all.dvi} or
  \texttt{./feynmf/feynmf\_all.pdf} to see if the graphs are OK\@;
\item run \LaTeX{} or pdf\LaTeX; % chktex 13
\item run \texttt{bibtex} or \texttt{biber};
\item run \LaTeX{} or pdf\LaTeX{} again, at least twice.
\end{itemize}
The last three steps are done with the command \texttt{make thesis},
\texttt{make thesis11}.
The big advantage of this procedure is that the graphs are included
\enquote{properly} in the thesis, their fonts should automatically
match the fonts used in the thesis and you don't have to worry about
converting and clipping. I have written a small script that is
executed by the \texttt{Makefile} to do the third step.
The script is \texttt{run\_mf} for \Package{feynmf} and
\texttt{run\_mp} for \Package{feynmp}. These are
included in the main directory \File{ubonn-thesis}.
The scripts assume that all Feynman graphs are in 
a \texttt{feynmf} subdirectory. This can clearly be
adjusted in the \texttt{Makefile} as necessary.
To get started you can copy the \File{feynmf} directory from \File{ubonn-thesis}.

The \texttt{run\_mf} script assumes that all files of type
\texttt{tex} (except those that start with \texttt{feynmf\_}) are
Feynman graphs to process with \texttt{feynmf}. Note that it may be
necessary to give the command \texttt{make cleanfeynmf} to get rid of
temporary files before \texttt{make feynmf} if you change the sizes of
things.

The \texttt{run\_mp} script works a bit differently. It creates a
temporary directory \texttt{mpost\_tmp} in which it processes the
figures (\texttt{tex} files) in the \texttt{feynmf} subdirectory. The
resulting PDF files are copied back to the \texttt{feynmf}
subdirectory.

You can also use the package \Package{standalone} together with
\Package{feynmp}. The files in the \texttt{feynmf} directory contain
commented out code that shows how this can be done. I do not do this
by default for the guide, as I want
to test making the Feynman graphs with \Package{feynmf}. Note that
the name in the \Env{fmffile} environment (and the \Macro{write18}
command) should be the same and different from the name of the \LaTeX\
file. If you use this option, you should probably also adjust the
\texttt{Makefile} target for \texttt{feynmp} to work in the same way
as the target \texttt{tikz}. You have to run \texttt{pdflatex} twice
on each file.

\Cref{fig:nccc-feynmf} shows the same neutral current and
charged current graphs, but this time inputting the appropriate
\Package{feynmf} commands directly. The graphs are enclosed in
\Macro{fbox} for illustration purposes only.
The plots are made using \Package{feynmp},
where an appropriate
\Macro{write18} statement is included in the \LaTeX\ source code,
e.g.\ \verb+\write18 mpost gluon+, after the figure, where the figure
starts with \verb+\begin{fmffile}{gluon}+.%
\footnote{If you use \TeXstudio you may have to give the full pathname for \texttt{mpost},
  e.g.\ \texttt{/usr/texbin/mpost}, as \TeXstudio does not parse your \texttt{PATH} properly.}

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\fbox{\input{../feynmf/ep_nc.tex}}
  \write18{mpost ep_nc}
\qquad
\fbox{\input{../feynmf/ep_cc.tex}}
  \write18{mpost ep_cc}
\caption{NC and CC graphs for $ep$ scattering using \Package{feynmf}
  code directly.}%
\label{fig:nccc-feynmf}
\end{tcblisting}
\end{figure}

If \texttt{mpost} does not run automatically,
you must execute the command
\texttt{pdflatex --shell-escape mythesis} when you compile your thesis.
This can be achieved by
including the \texttt{EXTRACMD} definition that is commented out in
the \texttt{Makefile}.
In this guide I put the Feynman graph in its
own file and the \Macro{write18} statement in the main file so that
I can test \Package{feynmf} and \Package{feynmp} with the same
\LaTeX\ code. In your thesis, you should probably put the
\Macro{write18} statement in the file with the Feynman graph.
If you use \Command{latexmk}\index{latexmk} to compile you probably need to use 
the commented out version of the \Command{latexmk} command in the \File{Makefile}.

As mentioned above, you probably want to first draw the graphs outside
of your thesis to get them into the form that you need. If you give
the command \texttt{make feynmf}, it will run \texttt{feynmf} on all
\texttt{tex} files in the subdirectory \texttt{feynmf}. If you give
the command \texttt{make feynmf file=ep\_nc} it will run over
\texttt{./feynmf/ep\_nc.tex} etc. As indicated above, the graphs can
then be looked at in \texttt{feynmf\_all.dvi} or\\
\texttt{feynmf\_all.pdf}. You can use the same syntax for
\texttt{make feynmp} and \texttt{make tikz}.

For \TeXLive 2023 and later I have seen problems in the thesis guide
when I use \Package{feynmp} together with the \Env{tcblisting} environment:
the temporary filename is included inside the listing.
A workaround for this is to include \Package{feynmp} as the last package.\footnote{%
See \url{https://tex.stackexchange.com/questions/714662/tcolorbox-includes-temporary-filename-in-box-some-time-in-tex-live-2023-onwards}.}
While it is unlikely that this problem will actually occur in your thesis,
I have attempted to avoid it in \File{ubonn-thesis.sty} by including \Package{feynmp} rather late.
If you still see this problem, then do not activate the \Option{feynmp} option.
Instead just include the package (and the associated \Macro{DeclareGraphicsRule}) in your main file at the end of your list of packages.
This is what I have done in this guide.

%------------------------------------------------------------------------------
\section{\TikZ and PGF}%
\label{sec:fig:tikz}\index{TikZ@\TikZ}
%------------------------------------------------------------------------------

\Package{pgfplots} and \Package{\TikZ} are packages to help with
creating graphics \enquote{inline}.
For 3D figures you also need \Package{tikz-3dplot}.
PGF is the backend, while \TikZ is what the user interacts with directly.
The manual contains all the information you should need,
but was 1318 pages long at the last count,
so it may not to be too easy to find what you want!

I do not have much experience with using these packages so far,
except for Feynman graphs discussed above.
Hence, this section will certainly not cover all possibilities. There may
also be better ways of doing things than I illustrate here. The
examples I give come from Andrii Verbytskyi or are adapted from
questions and answers found on
\url{http://tex.stackexchange.com/}.
The examples included in this
guide and a few more are collected in the \texttt{tikz} directory.
If you want to get started with \TikZ you can copy this directory
into your thesis directory, e.g.\ \File{mythesis}.

\TikZ is not included by default in a new skeleton thesis.
See the commented out packages in a new thesis skeleton or
\texttt{thesis\_guide.tex} for the packages and \TikZ libraries that
you should include if you want to use it.

You often want to include a figure of your experiment's coordinate
system in your thesis. One way to do this is illustrated in
\cref{fig:tikz:coord}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\subfile{../tikz/zeus_coords.tex}
\caption{The ZEUS coordinate system.
    \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:tikz:coord}
\end{tcblisting}
\end{figure}

It is also possible to make flow charts with \TikZ.
This is illustrated in \cref{fig:tikz:flow}.

\begin{figure}[htbp]
\begin{tcblisting}{}
\centering
\subfile{../tikz/zeus_reconstruction.tex}
\caption[Event reconstruction and simulation in ZEUS]{Event reconstruction and simulation in ZEUS.
  \Macro{subfile} is used instead of \Macro{input} so this works inside \Env{tcblisting}.}%
\label{fig:tikz:flow}
\end{tcblisting}
\end{figure}

There are many more possibilities,
including plots which you would otherwise make with \texttt{root} or
some other graphics program. An example plot showing the effect of
systematic variations can be found in \cref{G-sec:app:tikz}. Making
Feynman graphs with \TikZ is covered in \cref{sec:fig:feynman:tikz}.


%------------------------------------------------------------------------------
\subsection{Accelerator lattices}%
\label{sec:fig:accelerator}

If you want to include an accelerator lattice in your thesis you can try
\Package{tikz-palattice}\footnote{%
  \CTANurl{tikz-palattice} written by Jan Schmidt,
  who gave me a number of useful tips for this guide.}.
Jan Schmidt used the package to make lattices of particle accelerators for his PhD thesis.

\end{document}
