2

Consider the following MWE where I define a macro to generate triangle Feynman diagrams with three inputs:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{physics,tikz-feynman}
\usepackage{float}
\usepackage{graphicx}
\usepackage{xstring}
\tikzset{every picture/.append style={remember picture}}
\newcommand{\Ctype}[3]{
\begin{figure}[H]
    \centering
    \tikzfeynmanset{
        every plain={blue},
        every scalar={red},
    }
    \feynmandiagram[scale=.5,transform shape] [large, horizontal=a to t1] {
        a  -- [plain] t1 
        -- \IfEqCase{#1}{{P}{[scalar]}{M}{[scalar]}{R}{[plain]}{L}{[plain]}} t2 
        --\IfEqCase{#2}{{P}{[scalar]}{M}{[scalar]}{R}{[plain]}{L}{[plain]}} t3 
        -- \IfEqCase{#3}{{P}{[scalar]}{M}{[scalar]}{R}{[plain]}{L}{[plain]}} t1,
        t2 -- [plain] p1 ,
        t3 -- [plain] p2,
    };
    \IfEqCase{#1}{
    {P}{\tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
        \draw[thick,red] (m1) --(t1);}}
    {M}{\tikz[overlay]{\path (t1) --(t2) coordinate[midway] (m1);
            \draw[thick,red] (m1) --(t2);}}
    }
    \IfEqCase{#2}{
        {P}{\tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
                \draw[thick,red] (m2) --(t2);}}
        {M}{\tikz[overlay]{\path (t2) --(t3) coordinate[midway] (m2);
                \draw[thick,red] (m2) --(t3);}}
    }
    \IfEqCase{#3}{
        {P}{\tikz[overlay]{\path (t3) --(t1) coordinate[midway] (m3);
                \draw[thick,red] (m3) --(t3);}}
        {M}{\tikz[overlay]{\path (t3) --(t1) coordinate[midway] (m3);
                \draw[thick,red] (m3) --(t1);}}
    }
    \captionsetup{labelformat=empty}
    \caption{$C_{#1#2#3}$}
\end{figure}}
\begin{document}
\Ctype{P}{P}{M}
\end{document}

I get the error:

Argument of \XC@definec@lor has an extra }. \Ctype{P}{P}{M}

How to fix this?

1
  • A rather different approach: I recommend checking the tikz-feynman package. Commented Jul 10, 2018 at 4:24

1 Answer 1

2

I think I understand what you want to do, and here is how I would suggest doing it.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{physics,tikz-feynman}
\usetikzlibrary{decorations.markings}
\usepackage{float,caption}
\usepackage{graphicx}
\usepackage{xstring}
\tikzset{every picture/.append style={remember picture}}
\tikzset{semidashed straight line/.style={dashed,postaction={decorate,decoration={markings,
     mark=at position 0 with {\coordinate (X0); },
     mark=at position 0.5 with {\draw[thick,solid,#1] (X0) -- (0,0); }}}},
     semidashed straight line reversed/.style={dashed,postaction={decorate,decoration={markings,
     mark=at position 0.5 with {\coordinate (X0); },
     mark=at position 1 with {\draw[thick,solid,#1] (X0) -- (0,0); }}}},
     P/.style={red,semidashed straight line=red},
     M/.style={red,semidashed straight line reversed=red},
     L/.style={solid,blue},
     R/.style={solid,blue},
     }
\newcommand{\Ctype}[3]{
\begin{figure}[H]
    \centering
    \tikzfeynmanset{
        every plain={blue},
        every scalar={red},
    }
    \feynmandiagram[scale=.5,transform shape] [large, horizontal=a to t1] {
        a  -- [plain] t1
        -- [#1] t2 -- [#2] t3 -- [#3] t1,
        t2 -- [plain] p1 ,
        t3 -- [plain] p2,
    };
    \captionsetup{labelformat=empty}
    \caption{$C_{#1#2#3}$}
\end{figure}
}
\begin{document}
\Ctype{P}{P}{M}
\Ctype{P}{R}{R}
\end{document}

enter image description here

3
  • Exactly, what I wanted. But what is wrong with my code?
    – Subho
    Commented Jul 10, 2018 at 4:30
  • For \Ctype{P}{R}{R}, the above code produces an error: Package pgfkeys Error: I do not know the key '/tikz/plain' and I am going to ignore it. Perhaps you misspelled it. \Ctype{P}{R}{R} The plain style is not working. How to fix this?
    – Subho
    Commented Jul 10, 2018 at 4:59
  • @Subho95 I do not precisely understand what's going wrong with your attempt but in general you cannot just insert arbitrary LaTeX commands in a TikZ path. Normally you need to do \pgfextra but in this case that wouldn't help.
    – user121799
    Commented Jul 10, 2018 at 5:08

You must log in to answer this question.

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