편집하다

편집하다

내가 만드는 (tikz 기반) 그림은 모듈식인 경우가 많습니다. 그러므로 그림의 다양한 변형에 대해 동일한 소스를 사용하는 것이 이상적입니다.

이상적으로는 내가 이미 사용하고 있는 를 기반으로 standalone하고 조건부 블록을 정의하는 새로운 환경을 제공합니다(아래에서 환경 이름을 지정했습니다 conditionally). 이러한 조건부 코드 블록은 includestandalone옵션을 통해 활성화할 수 있습니다.

main.tex:

\documentclass{article}

\usepackage{standalone}
\usepackage{tikz}

\begin{document}
\includestandalone[enableall]{figure}

\includestandalone[enable=detour]{figure}

\includestandalone[enable={detour,longer-detour}]{figure}

\end{document}

figure.tex:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\pgfmathsetmacro{\myRadius}{2}

\coordinate (loop-start) at (-170:\myRadius);

\draw[
  ->,
  line width=7pt,
]
(loop-start)
arc (-170:170:\myRadius)
coordinate[pos=0.75] (detour-start)
coordinate[pos=0.25] (detour-end)
coordinate[pos=0.27] (detour-end-2)
;

\begin{conditionally}{detour}
  \draw[
    ->,
    line width=3pt,
    red,
  ] (detour-start) to[out=160, in=220, distance=6cm] (detour-end);
\end{conditionally}

\begin{conditionally}{longer-detour}
  \draw[
    ->,
    line width=3pt,
    red,
  ] (detour-start) to[out=45, in=-30, distance=10cm] (detour-end-2);
\end{conditionally}

\end{tikzpicture}
\end{document}

이런 일이 가능합니까?

답변1

standalone이 솔루션은 가 포함된 파일 에 대한 대상 구문을 활성화 tikzpicture하지만 기본 파일에서는 사용자 지정 명령을 사용합니다.

더 구체적으로 말하면 conditionally단일 필수 인수를 취하는 환경입니다.

  • 인수는 내용을 식별하는 데 사용되는 간단한 태그/레이블로 구성되어야 합니다.
  • 예제에서 이는 a의 일부로 사용되지만 tikzpicture솔루션은 이에 의존하지 않습니다. 동일한 메커니즘을 동일하게 사용하여 인용문이나 임의의 코드 조각을 포함할 수 있습니다.

\flowconditional[<key-value list>]{<filename>}는 기본 문서에서 태그/라벨별로 조각을 선택하는 데 사용됩니다 <filename>.

  • 현재 하나의 키만 정의되어 있습니다 enable.
  • enable쉼표로 구분된 값 목록을 사용합니다.
  • <filename>각 값은 또는 의 태그/레이블이어야 하며 *, 이는 *사용 가능한 모든 코드가 포함되어야 함을 나타냅니다.
  • 그러나 이 요구 사항은 적용되지 않습니다. 에 전달된 값이 enable에 정의되지 않은 경우 filename해당 값은 자동으로 무시됩니다.

OP의 그림 파일 이름이 \jobname-fig.tex이면 다음과 같이 작성할 수 있습니다.

\flowconditionalpic[enable=*]{\jobname-fig}

\flowconditionalpic[enable=detour]{\jobname-fig}

\flowconditionalpic[enable={detour,longer-detour}]{\jobname-fig}

목표 행동을 만들어낸다.

목표 출력

동일한 프레임워크를 사용하여 tabular환경을 포함하거나 포함하지 않을 수 있습니다(행 집합을 포함하려면 약간 더 많은 작업이 필요함). 예를 들어,

\begin{table}
  \caption{Tables rather than pictures}
  \flowconditional[enable=tab1]{\jobname-tab}
  \flowconditional[enable=tab2]{\jobname-tab}
\end{table}

\begin{table}
  \caption{Order is irrelevant}
  \flowconditional[enable=*]{\jobname-tab}
  \flowconditional[enable={tab2,tab1}]{\jobname-tab}
\end{table}

어디에 \jobname-tab.tex다음이 포함되어 있습니까 ?

\documentclass{standalone}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\sffamily
\begin{conditionally}{tab1}
  \begin{tabular} {ll}
    \toprule
    \bfseries Column 1 & \bfseries Column 2 \\
    \midrule
    Row 1 & Cell A \\
    \bottomrule
  \end{tabular}
\end{conditionally}
\begin{conditionally}{tab2}
  \begin{tabular} {ll}
    \toprule
    \bfseries Column 1 & \bfseries Column 2 \\
    \midrule
    Row 1 & Cell A \\
    Row 2 & Cell B \\
    \bottomrule
  \end{tabular}
\end{conditionally}
\end{document}

tikzpicture의 일부가 아닌 표 형식과 동일한 아이디어

전체 코드:

\begin{filecontents}[overwrite]{\jobname-fig.tex}
\documentclass{standalone}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}  
  \pgfmathsetmacro{\myRadius}{2} 
  \coordinate (loop-start) at (-170:\myRadius);  
  \draw[->,line width=7pt,]
  (loop-start)
  arc (-170:170:\myRadius)
  coordinate[pos=0.75] (detour-start)
  coordinate[pos=0.25] (detour-end)
  coordinate[pos=0.27] (detour-end-2)
  ;  
  \begin{conditionally}{detour}
    \draw[
    ->,
    line width=3pt,
    red,
    ] (detour-start) to[out=160, in=220, distance=6cm] (detour-end);
  \end{conditionally}  
  \begin{conditionally}{longer-detour}
    \draw[
    ->,
    line width=3pt,
    red,
    ] (detour-start) to[out=45, in=-30, distance=10cm] (detour-end-2);
  \end{conditionally}
\end{tikzpicture}
\end{document}
\end{filecontents}
\begin{filecontents}[overwrite]{\jobname-tab.tex}
\documentclass{standalone}
\usepackage{array}
\usepackage{booktabs}
\begin{document}
\sffamily
\begin{conditionally}{tab1}
  \begin{tabular} {ll}
    \toprule
    \bfseries Column 1 & \bfseries Column 2 \\
    \midrule
    Row 1 & Cell A \\
    \bottomrule
  \end{tabular}
\end{conditionally}
\begin{conditionally}{tab2}
  \begin{tabular} {ll}
    \toprule
    \bfseries Column 1 & \bfseries Column 2 \\
    \midrule
    Row 1 & Cell A \\
    Row 2 & Cell B \\
    \bottomrule
  \end{tabular}
\end{conditionally}
\end{document}
\end{filecontents}

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/705487/ addaswyd o gwestiwn Flow: https://tex.stackexchange.com/q/705458/
\usepackage[subpreambles]{standalone}
\usepackage{tikz}
\ExplSyntaxOn
\bool_new:N \l_flow_condition_bool
\bool_set_false:N \l_flow_condition_bool
\keys_define:nn { flow }
{
  enable .clist_set:N = \l_flow_conditions_clist,
  enable .initial:n = ,
  enable .default:n = ,
}
\NewDocumentEnvironment { conditionally } { m +b }
{
  \clist_if_in:NnT \l_flow_conditions_clist { #1 }
  { \bool_set_true:N \l_flow_condition_bool } 
  \clist_if_in:NnT \l_flow_conditions_clist { * }
  { \bool_set_true:N \l_flow_condition_bool } 
  \bool_if:NT \l_flow_condition_bool { #2 }
}{  }
\NewDocumentCommand \flowconditional { O {} m }
{
  \group_begin:
    \keys_set:nn { flow } { #1 }
    \includestandalone { #2 }
  \group_end:
}
\ExplSyntaxOff

\begin{document}
\flowconditional[enable=*]{\jobname-fig}

\flowconditional[enable=detour]{\jobname-fig}

\flowconditional[enable={detour,longer-detour}]{\jobname-fig}


\begin{table}
  \caption{Tables rather than pictures}
  \flowconditional[enable=tab1]{\jobname-tab}
  \flowconditional[enable=tab2]{\jobname-tab}
\end{table}

\begin{table}
  \caption{Order is irrelevant}
  \flowconditional[enable=*]{\jobname-tab}
  \flowconditional[enable={tab2,tab1}]{\jobname-tab}
\end{table}

\end{document}

편집하다

다음은 추가 키를 추가합니다 standalone options. 처음에는 로 설정되어 있습니다 mode = tex. 값 없이 키를 사용하면 옵션이 비워집니다. 값과 함께 키를 사용하면 옵션이 해당 값으로 설정됩니다. 아래 예시에서는 대부분의 경우 초기값을 적용하고 angle=90옵션 변경에 따른 효과를 보여주기 위해 사용됩니다.

\documentclass{article}
% ateb: https://tex.stackexchange.com/a/705487/ addaswyd o gwestiwn Flow: https://tex.stackexchange.com/q/705458/
\usepackage[subpreambles]{standalone}
\usepackage{tikz}
\ExplSyntaxOn
\bool_new:N \l_flow_condition_bool
\bool_set_false:N \l_flow_condition_bool
\keys_define:nn { flow }
{
  enable .clist_set:N = \l_flow_conditions_clist,
  enable .initial:n = ,
  enable .default:n = ,
  standalone ~ options .tl_set:N = \l_flow_standalone_tl,
  standalone ~ options .default:n = ,
  standalone ~ options .initial:n = {mode = tex},
}
\NewDocumentEnvironment { conditionally } { m +b }
{
  \clist_if_in:NnT \l_flow_conditions_clist { #1 }
  { \bool_set_true:N \l_flow_condition_bool } 
  \clist_if_in:NnT \l_flow_conditions_clist { * }
  { \bool_set_true:N \l_flow_condition_bool } 
  \bool_if:NT \l_flow_condition_bool { #2 }
}{  }
\NewDocumentCommand \flowconditional { O {} m }
{
  \group_begin:
    \keys_set:nn { flow } { #1 }
    \flow_includestandalone:Vn \l_flow_standalone_tl { #2 }
  \group_end:
}
\cs_new_protected:Nn \flow_includestandalone:nn
{
  \includestandalone [ #1 ] { #2 }
}
\cs_generate_variant:Nn \flow_includestandalone:nn { Vn }
\ExplSyntaxOff

\begin{document}
\flowconditional[enable=*]{\jobname-fig}

\flowconditional[enable=detour,standalone options={angle=90}]{\jobname-fig}

\flowconditional[enable={detour,longer-detour}]{\jobname-fig}


\begin{table}
  \caption{Tables rather than pictures}
  \flowconditional[enable=tab1]{\jobname-tab}
  \flowconditional[enable=tab2]{\jobname-tab}
\end{table}

\begin{table}
  \caption{Order is irrelevant}
  \flowconditional[enable=*]{\jobname-tab}
  \flowconditional[enable={tab2,tab1}]{\jobname-tab}
\end{table}

\end{document}

`standalone options={angle=90} 설정 효과

답변2

다음을 사용할 수 있습니다 \pic.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\tikzset{
    pics/conditional loop/.style={
        code={
            \tikzset{conditional loop/.cd, #1}
            \coordinate
                (-loop-start)
                at (-170:{\pgfkeysvalueof{/tikz/conditional loop/radius}})
            ;
            \draw[
              ->,
              line width=7pt,
            ]
                (-loop-start)
                arc[
                    start angle=-170, 
                    end angle=170, 
                    radius={\pgfkeysvalueof{/tikz/conditional loop/radius}}
                ]
                coordinate[pos=0.75] (-detour-start)
                coordinate[pos=0.25] (-detour-end-short)
                coordinate[pos=0.27] (-detour-end-long)
            ;
            \foreach \o/\i/\d/\e in \conditionallooploopsettings {
                \draw[
                    ->,
                    line width=3pt,
                    red,
                ] 
                    (-detour-start) 
                    to[out=\o, in=\i, distance=\d] 
                    (-\e)
                ;
            }
        }
    },
    conditional loop/radius/.initial={2},
    conditional loop/loop settings/.store in=\conditionallooploopsettings,
    conditional loop/loop settings={},
    conditional loop/all/.style={
        loop settings={160/220/6cm/detour-end-short,45/-30/10cm/detour-end-long}
    },
    conditional loop/detour/.style={
        loop settings={160/220/6cm/detour-end-short}
    },
    conditional loop/longer detour/.style={
        loop settings={45/-30/10cm/detour-end-long}
    }
}

\begin{tikzpicture}

\pic at (0,0) {conditional loop};

\pic at (0,-10) {conditional loop={all}};

\pic at (0,-20) {conditional loop={detour}};

\pic at (0,-30) {conditional loop={longer detour}};

\pic at (0,-40) {conditional loop={radius=1cm, all}};

\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

또한 다음을 허용하는 변형입니다 conditional loop={detour, longer detour}.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\tikzset{
    pics/conditional loop/.style={
        code={
            \tikzset{conditional loop/.cd, #1}
            \coordinate
                (-loop-start)
                at (-170:{\pgfkeysvalueof{/tikz/conditional loop/radius}})
            ;
            \draw[
              ->,
              line width=7pt,
            ]
                (-loop-start)
                arc[
                    start angle=-170, 
                    end angle=170, 
                    radius={\pgfkeysvalueof{/tikz/conditional loop/radius}}
                ]
                coordinate[pos=0.75] (-detour-start)
                coordinate[pos=0.25] (-detour-end-short)
                coordinate[pos=0.27] (-detour-end-long)
            ;
            \pgfkeys{/tikz/conditional loop/draw loops}
        }
    },
    conditional loop/detour arrow/.style={
        ->,
        line width=3pt,
        red,
    },
    conditional loop/radius/.initial={2},
    conditional loop/loop settings/.store in=\conditionallooploopsettings,
    conditional loop/draw loops/.initial={},
    conditional loop/detour/.style={
        draw loops/.append code={
            \draw[conditional loop/detour arrow]
                (-detour-start) 
                to[out=160, in=220, distance=6cm] 
                (-detour-end-short);
        }
    },
    conditional loop/longer detour/.style={
        draw loops/.append code={
            \draw[conditional loop/detour arrow]
                (-detour-start) 
                to[out=34, in=-30, distance=10cm] 
                (-detour-end-long);
        }
    },
    conditional loop/all/.style={
        detour,
        longer detour
    }
}

\begin{tikzpicture}

\pic at (0,0) {conditional loop};

\pic at (0,-10) {conditional loop={all}};

\pic at (0,-20) {conditional loop={detour}};

\pic at (0,-30) {conditional loop={longer detour}};

\pic at (0,-40) {conditional loop={detour, longer detour}};

\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보