이 코드(다른 기능을 사용하는 유사한 새 명령 정의)를 복사하여 붙여넣는 것을 방지하려면 어떻게 해야 합니까?

이 코드(다른 기능을 사용하는 유사한 새 명령 정의)를 복사하여 붙여넣는 것을 방지하려면 어떻게 해야 합니까?

저는 여러분 덕분에 코드를 개선해 왔지만 보기 흉한 복사/붙여넣기처럼 보이기 때문에 여전히 개선 가능해 보입니다.

\newcommand*{\LegendFlecheInf}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FInfAUn(#1,#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}
\newcommand*{\LegendFlecheEga}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FEgaAUn(#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}
\newcommand*{\LegendFlecheSup}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FSupAUn(#1,#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}

여기에 정의된 3개 명령 간의 유일한 차이점은 화살표 끝의 y 좌표를 계산하기 위해 호출되는 함수입니다.

MWE를 위해 많은 것을 제거했지만 여전히 큽니다.

\documentclass[border=2pt]{standalone}
\usepackage[utf8]{inputenc}

\usepackage{graphics}
\usepackage{tikz,pgfplots}
\usetikzlibrary{math} % Pour evaluate
\usetikzlibrary{calc} % Pour postionnement relatif

\def\FInfAUn(#1,#2){( 1 - ( (exp(-W*#1*#2)/sqrt(1-#1*#1)) *cos((W*#2*sqrt(1-#1*#1) 
                    - (atan(#1/sqrt(1-#1*#1))*pi/180) ) *180/pi) )  ) *\Kg }

\def\FTUn(#1){( 1/( W*(#1-sqrt((#1*#1) -1))) )}
\def\FTDeux(#1){( 1/(W *(#1+sqrt((#1*#1) -1))) )}
\def\FInterSupAUn(#1,#2,#3){(  \Kg * (1 - ( 1/( #1 - #2 ) )*( #1 *exp(-#3/ #1 ) - #2 *exp(-#3/ #2 ) ))   )}
\def\FSupAUn(#1,#2){ \FInterSupAUn({\FTUn(#1)},{\FTDeux(#1)},#2)   }
\def\FEgaAUn(#1){ \Kg * (1 - ( 1+ #1/(1/W) )*exp(-#1/(1/W)) )  }

    \newcommand*{\LegendFlecheInf}[5]{ 
        \coordinate (C2) at (axis cs:#2, { \FInfAUn(#1,#2) }) ;
        \draw node[anchor=#3] (#4) at #5 {$z =#1$};
        \draw[fleche] (C2) -- (#4.west) ;
    }
    \newcommand*{\LegendFlecheEga}[5]{ 
        \coordinate (C2) at (axis cs:#2, { \FEgaAUn(#2) }) ;
        \draw node[anchor=#3] (#4) at #5 {$z =#1$};
        \draw[fleche] (C2) -- (#4.west) ;
    }
    \newcommand*{\LegendFlecheSup}[5]{ 
        \coordinate (C2) at (axis cs:#2, { \FSupAUn(#1,#2) }) ;
        \draw node[anchor=#3] (#4) at #5 {$z =#1$};
        \draw[fleche] (C2) -- (#4.west) ;
    }

\tikzset{ fleche/.style={<-,>=latex,line width=0.2mm,shorten <=-0.02cm} }

\begin{document}
\begin{tikzpicture}[
  declare function={
    W=pi*2;
  }]
\def\Kg{2}
\def\Ezero{1} 
\def\Ttrace{3}

\begin{axis}[ymax=1.55*\Kg]
    \addplot[blue,loosely dashed,thick=3pt,ultra thick,domain=0:3] {  \FEgaAUn(x)  };  \label{d}

    %\LegendFleche{z}{t}{Anchor of new node}{New node name}{previous node anchor coinsiding with this anchor}
    \LegendFlecheInf{0.2}{0.6}{west}{C3}{($(C2)+(axis cs:0.5,0.05)$)}
    \LegendFlecheSup{4}{0.6}{west}{C3}{($(C2)+(axis cs:1,-0.5)$)}
    \LegendFlecheSup{2}{0.6}{south}{C4}{(C3.north)}
    \LegendFlecheEga{1}{0.6}{south}{C5}{(C4.north)}

\end{axis}
\end{tikzpicture}
\end{document}

답변1

당신은 대체할 수 있습니다

\newcommand*{\LegendFlecheInf}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FInfAUn(#1,#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}
\newcommand*{\LegendFlecheEga}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FEgaAUn(#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}
\newcommand*{\LegendFlecheSup}[5]{ 
    \coordinate (C2) at (axis cs:#2, { \FSupAUn(#1,#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}

~에 의해

\newcommand*{\Legendx}[6]{ 
    \coordinate (C2) at (axis cs:#2, { #6(#1,#2) }) ;
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}

예를 들어 교체하십시오.

\LegendFlecheEga{1}{0.6}{south}{C5}{(C4.north)}

~에 의해

\Legendx{1}{0.6}{south}{C5}{(C4.north)}\FEgaAUn

답변2

패키지 를 사용하면 ifthen세 가지 명령을 새 명령으로 바꿀 수 있습니다.

\newcommand{\LegendComplex}[6]{  
     \ifthenelse{\equal{#6}{inf}}{\coordinate (C2) at (axis cs:#2, {\FInfAUn(#1,#2)});}{}
     \ifthenelse{\equal{#6}{sup}}{\coordinate (C2) at (axis cs:#2, {\FSupAUn(#1,#2)});}{}
     \ifthenelse{\equal{#6}{ega}}{\coordinate (C2) at (axis cs:#2, {\FEgaAUn(#2)});}{}      
    \draw node[anchor=#3] (#4) at #5 {$z =#1$};
    \draw[fleche] (C2) -- (#4.west) ;
}

호출하려는 함수를 지정하는 새 매개변수(sup, inf 또는 ega)를 제공해야 합니다.

관련 정보