CTeX-org / forum

A temporarily alternate forum of `bbs.ctex.org`
https://t.me/chinesetex
Apache License 2.0
211 stars 16 forks source link

TikZ-Feynman package didn't complied properly #4

Open 70akaline opened 5 years ago

70akaline commented 5 years ago

Dear All, I met a problem when compiling codes with TikZ-Feynman package, my codes is shown below

\documentclass{article}
\usepackage{tikz-feynman}
\begin{document}
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. 
The quick brown fox jumps over the lazy dog.

\begin{figure}[hbt]
  \centering
  \begin{tikzpicture}
    \begin{feynman}
      \diagram [vertical'=a to b] {
        i1 [particle=\(e^{-}\)]
           -- [fermion] a
           -- [draw=none] f1 [particle=\(e^{+}\)],
        a -- [photon, edge label'=\(p\)] b,
        i2 [particle=\(e^{+}\)]
           -- [anti fermion] b
           -- [draw=none] f2 [particle=\(e^{-}\)],
      };
      \diagram* {
        (a) -- [fermion] (f2),
        (b) -- [anti fermion] (f1),
      };
    \end{feynman}
  \end{tikzpicture}
\end{figure}

\end{document}

When I compile this with LuaTeX in TeXPad, the diagram shown is not the same as the example from document:

Mine: 1_mine

Document example 2_example

How can I compile this file properly?

muzimuzhi commented 5 years ago

Labeling vertex as their respective internal names gives us more info. In the package document, vertices i1 and i2 are both at the left side of a -- b; but this is not true in your output, nor in my local output.

image

According to the document of tikz-feynman, the only constraint in this example is that, groups of vertices i1 f1 a and i2 f2 b are positioned closer together (by using [draw=none]). However, the default behavior of whether vertices i1 and i2 are both at the same side of a -- b or not, is determined by the undergoing positioning algorithm. Therefore your output and the output in doc may both be ok.

I am not capable of finding the real cause of this difference, but currently "reversing the drawing routine of group consisting i2, f2 and b" could be a workaround.

% workaround
\begin{tikzpicture}
  \begin{feynman}
    \diagram[vertical=a to b] {% change from flipped `vertical'` to normal `vertical`
      i1 [particle=\(e^{-}\)]
         -- [fermion] a
         -- [draw=none] f1 [particle=\(e^{+}\)],
      a -- [photon, edge label'=\(p\)] b,
      % draw reversely
      f2 [particle=\(e^{-}\)]
         --  [draw=none] b
         -- [anti fermion] i2 [particle=\(e^{+}\)],
    };
    \diagram* {
      (a) -- [fermion] (f2),
      (b) -- [anti fermion] (f1),
    };
  \end{feynman}
\end{tikzpicture}

image

70akaline commented 5 years ago

image

Thanks for your checking, but since you change the codes, the feynman diagram is not the same as the document. For a Feynman diagram, the arrow direction is very important, in your case, the left side incoming piston should have a reversed arrow. I think my problem may discussed from this link: https://github.com/u-fischer/luaotfload/issues/6

As you discussed with me before, maybe this luacode helps, but I don't know will this luacode works my case?

muzimuzhi commented 5 years ago

maybe this luacode helps, but I don't know will this luacode works my case?

I am afraid not. That luacode resolver "is just for fonts", but not positioning. In my local latex installation with some lua-related packages updated, inserting that resolver is a necessary to using \usegdlibrary{circular}, which is loaded internally by tikz-feynman. And, after that resolver, I produced the same vertex-partly reversed output as you.

In TeXPad, maybe the package version is freezing, so that you can use tikz-feynman normally without introducing the resolver.

I will try reading the document of tikz-feynman carefully, to see if I can find something helpful. Maybe an issue should be opened under JP-Ellis/tikz-feynman.

muzimuzhi commented 5 years ago

Update messages:

The reported pgf bug #493, resulted from u-fischer/luaotfload#6, is fixed in commit [afd7e8] 5 days ago. See diff here.

I have manually used the new version, and your problem persists.

muzimuzhi commented 5 years ago

This question on TeX.SX denotes the same question, under which the author of tikz-feynman has participated in discussions. I have not found this until posted a new question on TeX.SX.

stone-zeng commented 5 years ago

I have met this problem as well, see another question on TeX.SX. Solution is to change the lua code as they do.

However, it seems using luacode from TeX code didn't work for me, so I directly hacked the original lua code.

@Liam0205 Please consider to add a tag like Lua or LuaTeX.

Liam0205 commented 5 years ago

@Stone-Zeng Sounds a good idea, I'll handle it.

muzimuzhi commented 5 years ago

@Stone-Zeng I have met this problem as well, see another question on TeX.SX. Solution is to change the lua code as they do.

However, it seems using luacode from TeX code didn't work for me, so I directly hacked the original lua code.

Denote

The accepted answer of question 1 does not solve the problem described by question 2, as the EXTRA INFORMATION part of question 2 has mentioned. Since this issue and the question 2 seem similar, your suggestion does not solve this issue either. And I have experimented to verify this.

muzimuzhi commented 5 years ago

The comments, posted in Oct 2018, of the un-solved question 2 provides a dangerous but effective solution: update luatex from v1.07.0 (with lua v5.2) to v1.09.0 (with lua v5.3).

Here are the steps:

  1. Download luatex v1.09.0. In case you prefer to build from source, see here.
  2. Replace local binary files luatex and luajittex. Execute luatex --version to test.
  3. Regenerate formats by fmtutil-sys --byengine luatex.
  4. Change two instances of math.random(1, spring_length) in line 217 of file TEXMFDIST/tex/generic/pgf/graphdrawing/lua/pgf/gd/force/SpringHu2006.lua to math.random(1, math.floor(spring_length)). (since the incompatibility introduced by lua v5.3)

Delete the auxiliary files of .tex file and then recompile. Now you get the expected vertex positioning, the same as the package doc shows.

I have little experience in using luatex, let alone the source code level of luatex and/or lua. This comment is just a record of what I just tried.

muzimuzhi commented 5 years ago

Some update from TeX.SX

Denote, as before,

As the accepted answer of question 2 stated, updating to the latest luatex (v1.09.0) and pgf (no older than commit [de79f5]) solves the original problem. Hence the question posted later by myself is flagged duplicate. However, users may still take care using graph drawing function of pgf with Lua 5.3, as the accepted answer complains.

How to update luatex is introduced in my previous comment, and I personally recommend installing dev version of pgf into TEXMFHOME TDS tree. One can use kpsewhich -var-value TEXMFHOME to get the actual directory of TEXMFHOME.

Note: Before the release of TeX Live 2019 (accompanying with luatex v1.10.0), there won't be updates of luatex in TeX Live 2018.

hmenke commented 5 years ago

This was a bug in PGF which is fixed by these two commits: https://github.com/pgf-tikz/pgf/commit/afd7e8de65cf70dab4a2152b9c9a8910b8ba2e86 https://github.com/pgf-tikz/pgf/commit/73ca6bed1874f33eefc58005cd80fbcfd647b575 The next PGF release contains these fixes and will be distributed in the coming days via CTAN.

Here is a screenshot from LuaTeX 1.07.0 with PGF 3.1

muzimuzhi commented 5 years ago

@hmenke Using PGF 3.1 downloaded from pgf-tikz/pgf/zip/3.1 with LuaTeX 1.07.0, I still get wrong output, the same as the original poster got. My .tex file is the one posted by OP.

Version info - macOS 12.14.2 - LuaTeX, Version 1.07.0 (TeX Live 2018) - LaTeX2e <2018-12-01> Output of `\listfiles` ``` *File List* article.cls 2018/09/03 v1.4i Standard LaTeX document class size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option) tikz-feynman.sty 2016/02/05v1.1.0Feynman diagrams with TikZ tikz.sty 2014/07/01 v0.0 (0) pgf.sty 2014/07/01 v0.0 (0) pgfrcs.sty 2014/07/01 v0.0 (0) everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS) pgfrcs.code.tex pgfcore.sty 2014/07/01 v0.0 (0) graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 2014/10/28 v1.15 key=value parser (DPC) graphics.sty 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR) trig.sty 2016/01/03 v1.10 sin cos tan (DPC) graphics.cfg 2016/06/04 v1.11 sample graphics configuration luatex.def 2018/01/08 v1.0l Graphics/color driver for luatex pgfsys.sty 2014/07/01 v0.0 (0) pgfsys.code.tex pgfsyssoftpath.code.tex 2014/07/01 v0.0 (0) pgfsysprotocol.code.tex 2014/07/01 v0.0 (0) xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK) color.cfg 2016/01/02 v1.6 sample color configuration pgfcore.code.tex pgfcomp-version-0-65.sty 2014/07/01 v0.0 (0) pgfcomp-version-1-18.sty 2014/07/01 v0.0 (0) pgffor.sty 2014/07/01 v0.0 (0) pgfkeys.sty pgfkeys.code.tex pgfmath.sty pgfmath.code.tex pgffor.code.tex tikz.code.tex ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO) pgfopts.sty 2014/07/10 v2.1a LaTeX package options with pgfkeys supp-pdf.mkii epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO) grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO) kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO) ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO) kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO) etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO) pdftexcmds.sty 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO) ifpdf.sty 2018/09/07 v3.3 Provides the ifpdf switch epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live *********** ```

Maybe the listed info is not capable of "discovering the truth", and I can provide more info on request.

muzimuzhi commented 5 years ago

Updating PGF to 3.1 from tlmgr, the wrong output remains using LuaTeX 1.07.0.

Updated version info, with PGF related files having version 3.1 ``` *File List* article.cls 2018/09/03 v1.4i Standard LaTeX document class size10.clo 2018/09/03 v1.4i Standard LaTeX file (size option) tikz-feynman.sty 2016/02/05v1.1.0Feynman diagrams with TikZ tikz.sty 2019/01/05 v3.1 (3.1) pgf.sty 2019/01/05 v3.1 (3.1) pgfrcs.sty 2019/01/05 v3.1 (3.1) everyshi.sty 2001/05/15 v3.00 EveryShipout Package (MS) pgfrcs.code.tex pgfcore.sty 2019/01/05 v3.1 (3.1) graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 2014/10/28 v1.15 key=value parser (DPC) graphics.sty 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR) trig.sty 2016/01/03 v1.10 sin cos tan (DPC) graphics.cfg 2016/06/04 v1.11 sample graphics configuration luatex.def 2018/01/08 v1.0l Graphics/color driver for luatex pgfsys.sty 2019/01/05 v3.1 (3.1) pgfsys.code.tex pgfsyssoftpath.code.tex 2019/01/05 v3.1 (3.1) pgfsysprotocol.code.tex 2019/01/05 v3.1 (3.1) xcolor.sty 2016/05/11 v2.12 LaTeX color extensions (UK) color.cfg 2016/01/02 v1.6 sample color configuration pgfcore.code.tex pgfcomp-version-0-65.sty 2019/01/05 v3.1 (3.1) pgfcomp-version-1-18.sty 2019/01/05 v3.1 (3.1) pgffor.sty 2019/01/05 v3.1 (3.1) pgfkeys.sty pgfkeys.code.tex pgfmath.sty pgfmath.code.tex pgffor.code.tex tikz.code.tex ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO) pgfopts.sty 2014/07/10 v2.1a LaTeX package options with pgfkeys supp-pdf.mkii epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO) grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO) kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO) ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO) kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO) kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO) etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO) pdftexcmds.sty 2018/09/10 v0.29 Utility functions of pdfTeX for LuaTeX (HO) ifpdf.sty 2018/09/07 v3.3 Provides the ifpdf switch epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live *********** ```
hmenke commented 5 years ago

I can't reproduce on Linux with neither LuaTeX 1.07.0 nor LuaTeX 1.09.0 and PGF 3.1. I don't have access to a computer with Mac OS X, so I can't debug it.

muzimuzhi commented 2 years ago

Unfortunately, the problem is reproducible with overleaf's texlive 2019 to 2021. See a simpler example in JP-Ellis/tikz-feynman#73.