4

ORIGINAL QUESTION: I have major problems compiling Feynman diagrams produced with the tikz-feynman package with lualatex. To make it less likely that I am just sloppy, I copied the example from this nice answer.

\documentclass[tikz, border=10pt]{standalone}

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

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \diagram [vertical'=a to b, edges={red}] {
      i1 -- [fermion] a -- [fermion] f1,
      a -- [photon] b,
      i2 -- [fermion] b -- [fermion] f2,
    };

    \vertex [above right=of f1] (k1);
    \vertex [below right=of f1] (p1);
    \vertex [below right=of f2] (k2);
    \vertex [above right=of f2] (p2);

    \diagram* {
      (f1) -- [fermion] (k1),
      (f1) -- [photon] (p1),
      (f2) -- [fermion] (k2),
      (f2) -- [photon] (p2),
    };
  \end{feynman}
\end{tikzpicture}
\end{document}

Given that this the accepted answer, it is probably safe to assume that there was a time when this could be compiled. However, when I compile it on my updated TeXLive2018 distribution with lualatex, I get the error message

! Package pgf Error: Graph drawing library 'circular' not found.

EXTRA INFORMATION: This question was marked as a duplicate (by myself) of this question. Indeed, if one uses the accepted answer to fix it, one may arrive at

\documentclass[tikz, border=10pt]{standalone}
\usepackage{luacode}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}

\begin{luacode*}
function pgf_lookup_and_require(name)
    local sep = package.config:sub(1,1)
    local function lookup(name)
        local sub = name:gsub('%.',sep)  
        if kpse.find_file(sub, 'lua') then
            require(name)
        elseif kpse.find_file(sub, 'clua') then
            collectgarbage('stop') 
            require(name)
            collectgarbage('restart')
        else
            return false
        end
        return true
    end
    return
        lookup('pgf.gd.' .. name .. '.library') or
        lookup('pgf.gd.' .. name) or
        lookup(name .. '.library') or
        lookup(name) 
end
\end{luacode*}

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

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \diagram [vertical'=a to b, edges={red}] {
      i1 -- [fermion] a -- [fermion] f1,
      a -- [photon] b,
      i2 -- [fermion] b -- [fermion] f2,
    };

    \vertex [above right=of f1] (k1);
    \vertex [below right=of f1] (p1);
    \vertex [below right=of f2] (k2);
    \vertex [above right=of f2] (p2);

    \diagram* {
      (f1) -- [fermion] (k1),
      (f1) -- [photon] (p1),
      (f2) -- [fermion] (k2),
      (f2) -- [photon] (p2),
    };
  \end{feynman}
\end{tikzpicture}
\end{document}

enter image description here

The good news is that the error is gone. However, the output looks really different from the output of the original answer

enter image description here

in that the photon vertex on the top right has move to the left. When I marked my answer as a duplicate, I did not carefully check that the output is OK. Now I did, and realized that the output produced using Henri's fix produces unexpected results. Therefore, I'd like to reopen the question.

  • Workaround only. Copy texmf-dist/tex/generic/pgf/graphdrawing/tex/pgflibrarygraphdrawing.code.tex into the current direcroty and try the following: change line 1093 if resolvers then to if false then – Akira Kakuto Oct 13 '18 at 05:57
  • 2
    There is already a question and also a pgf bug report about this.https://sourceforge.net/p/pgf/bugs/493/ – Ulrike Fischer Oct 13 '18 at 06:56
  • 2
    The obvious solution is to use picture mode instead of tikz-pgf – David Carlisle Oct 13 '18 at 08:31
  • @UlrikeFischer Yes, but as far as I can see this resolves the problem of the error. Yet there is a problem with that: after employing the fix, the output is quite different. (Of course, I am not 100% sure if these things are related, there could be a coincidental change of some library and this has nothing to do with the original problem. If that's not the case, I'd kindly ask you to help me reopening the question. As we both know: "It looks complicated because it is complicated." ;-) –  Oct 14 '18 at 00:07
  • @marmot The output is okay on my machine. Could you sent me a log-file? – Ulrike Fischer Oct 14 '18 at 08:37
  • @marmot In general people are quite able to find me ... – Ulrike Fischer Oct 14 '18 at 08:42
  • @UlrikeFischer People, yes, but marmots? (You got mail... ;-) –  Oct 14 '18 at 08:49
  • With version 1.09.0, Dev id: 6924 (lua 5.3 and pplib) different order is required to obtain correct output: \diagram [vertical'=a to b, edges={red}] { a -- [photon] b, i2 -- [fermion] b -- [fermion] f2, i1 -- [fermion] a -- [fermion] f1, }; With version 1.07.0, Dev id: 6686 (lua 5.2 and poppler) outputs are correct for original and changed order. – Akira Kakuto Oct 15 '18 at 12:40
  • I have tested by changing from lua 5.3 to lua 5.2 in 1.09.0: With version 1.09.0, Dev id: 6924 (lua 5.2 and pplib). Then outputs are correct for original and changed orders. – Akira Kakuto Oct 15 '18 at 12:51
  • I have tested by changing from lua 5.2 to lua 5.3 in 1.07.0: With version 1.07.0, Dev id: 6686 (lua 5.3 and poppler). Then output is correct for changed order, and it is incorrect for the original order. – Akira Kakuto Oct 15 '18 at 12:59
  • @AkiraKakuto These are all interesting observations but I think it is fair to say that they do not solve the fundamental problem. Or are you suggesting that for each diagram one should change the order for each version in a different way. Note also that different people seem to get different results. –  Oct 15 '18 at 13:22
  • 1
    @marmot: I'm only suggesting that the problem is caused by differences of versions of used lua. I don't know a solution. – Akira Kakuto Oct 15 '18 at 21:12
  • I don't have time to check this right now, but it is possible that the underlying differences arise from different random seeds used in the graph drawing algorithms. If that is indeed the case, I can release an update to TikZ-Feynman that sets a specific seed for all diagrams. (Though such an update will be backward incompatible.) – JP-Ellis Oct 16 '18 at 08:44
  • @JP-Ellis: I replaced x by math.floor(x) in math.random in SpringHu2006.lua to avoid argument error in lua 5.3. Was it bad? – Akira Kakuto Oct 16 '18 at 22:55
  • @AkiraKakuto Well, it's not bad to have the seed changed (especially if it fixes another issue elsewhere), but it does mean the layout will (likely) change. – JP-Ellis Oct 17 '18 at 02:10
  • 1
    @JP-Ellis It is not the seed that changed but the whole RNG. Lua 5.2 used the C standard library rand() function, whereas Lua 5.3 uses the POSIX random() function. Therefore you get entirely different random numbers even with the same seed. – Henri Menke Jan 02 '19 at 04:10

1 Answers1

3

With the latest master branch of my TikZ/PGF development repository it compiles fine, but thanks to new features in Lua 5.3 some graphs might appear mirrored. There are workarounds for this but no backwards compatibility will be provided by TikZ.

\documentclass[tikz, border=10pt]{standalone}
\usepackage{luacode}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}

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

\begin{document}
\begin{tikzpicture}
  \begin{feynman}
    \diagram [vertical'=a to b, edges={red}] {
      i1 -- [fermion] a -- [fermion] f1,
      a -- [photon] b,
      i2 -- [fermion] b -- [fermion] f2,
    };

    \vertex [above right=of f1] (k1);
    \vertex [below right=of f1] (p1);
    \vertex [below right=of f2] (k2);
    \vertex [above right=of f2] (p2);

    \diagram* {
      (f1) -- [fermion] (k1),
      (f1) -- [photon] (p1),
      (f2) -- [fermion] (k2),
      (f2) -- [photon] (p2),
    };
  \end{feynman}
\end{tikzpicture}
\end{document}

enter image description here

Henri Menke
  • 109,596