This solution enables the target syntax for the standalone file containing the tikzpicture, but uses a custom command in the main file.
More specifically, conditionally is an environment which takes a single, mandatory argument.
- The argument should consist of a simple tag/label used to identify the contents.
- In the example, this is used as part of a
tikzpicture, but the solution doesn't depend on this. The same mechanism could equally be used to include a selection of quotations, say, or arbitrary code snippets.
\flowconditional[<key-value list>]{<filename>} is used in the main document to select snippets by tag/label from <filename>.
- Only one key is currently defined,
enable.
enable takes a comma-separated list of values.
- Each value should be either a tag/label in
<filename> or *, where * indicates that all available code should be included.
- However, this requirement is not enforced: if a value passed to
enable is not defined in filename, the value will be silently ignored.
Given the OP's figure file is named \jobname-fig.tex, we can then write
\flowconditionalpic[enable=*]{\jobname-fig}
\flowconditionalpic[enable=detour]{\jobname-fig}
\flowconditionalpic[enable={detour,longer-detour}]{\jobname-fig}
to produce the target behaviour.

The same framework can be used to include or not include tabular environments (though including sets of rows would require a bit more work). For example,
\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}
where \jobname-tab.tex contains
\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}

Complete code:
\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}
Edit
The following adds an additional key standalone options. Initially, this is set to mode = tex. Using the key without a value will empty the options. Using the key with a value will set the options to that value. In the example below, the initial value is applied to most cases, with angle=90 being used to demonstrate the effect of changing the option.
\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}

\pic... – Jasper Habicht Dec 21 '23 at 11:23circuitikzat all. Not the most elegant implementation, I suppose, but could give some hint. It was added here – Rmano Dec 21 '23 at 11:25