定义费曼图的宏

定义费曼图的宏

考虑以下 MWE,其中我定义一个宏来生成具有三个输入的三角费曼图:

\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}

我收到错误:

\XC@definec@lor 的参数有一个额外的}。\Ctype{P}{P}{M}

如何解决这个问题?

答案1

我想我知道你想做什么,以下是我建议的做法。

\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}

在此处输入图片描述

相关内容