Detecting if inside a tikzpicture
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I would like to define the DrawLine
macro below so that it can be invoked from within a tikzpicture
environment or from outside:
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
This works fine when invoked from within a tikzpicture
, but not when it is invoked from outside (line is commented in the MWE). Invoking it from outside yields the error:
Missing endgroup inserted.
The MWE below uses the first reference below. The other two references also fail on the commented out test case.
References:
Detecting if inside a tikzpicture node. Even though this solution is for detecting within a node, it appears to work to detect if you are within a
tikzpicture
(as the commented out code in the MWE shows).Is there a (simple) way to find out if a command is executed in a tikzpicture environment?.
How can I check if the current code is inside a certain environment?.
Code:
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic[2]% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined#2else#1fi%
makeatother
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
%textbfIfInTikzPicpar
%IfInTikzPicinsideoutside
%
%begintikzpicture
% IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
%endtikzpicture
%
%medskip% --------------------------
textbfDrawLine: Actual Outputpar
%DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
tikz-pgf grouping
add a comment |Â
up vote
5
down vote
favorite
I would like to define the DrawLine
macro below so that it can be invoked from within a tikzpicture
environment or from outside:
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
This works fine when invoked from within a tikzpicture
, but not when it is invoked from outside (line is commented in the MWE). Invoking it from outside yields the error:
Missing endgroup inserted.
The MWE below uses the first reference below. The other two references also fail on the commented out test case.
References:
Detecting if inside a tikzpicture node. Even though this solution is for detecting within a node, it appears to work to detect if you are within a
tikzpicture
(as the commented out code in the MWE shows).Is there a (simple) way to find out if a command is executed in a tikzpicture environment?.
How can I check if the current code is inside a certain environment?.
Code:
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic[2]% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined#2else#1fi%
makeatother
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
%textbfIfInTikzPicpar
%IfInTikzPicinsideoutside
%
%begintikzpicture
% IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
%endtikzpicture
%
%medskip% --------------------------
textbfDrawLine: Actual Outputpar
%DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
tikz-pgf grouping
1
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:Undefined control sequence
).
â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I would like to define the DrawLine
macro below so that it can be invoked from within a tikzpicture
environment or from outside:
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
This works fine when invoked from within a tikzpicture
, but not when it is invoked from outside (line is commented in the MWE). Invoking it from outside yields the error:
Missing endgroup inserted.
The MWE below uses the first reference below. The other two references also fail on the commented out test case.
References:
Detecting if inside a tikzpicture node. Even though this solution is for detecting within a node, it appears to work to detect if you are within a
tikzpicture
(as the commented out code in the MWE shows).Is there a (simple) way to find out if a command is executed in a tikzpicture environment?.
How can I check if the current code is inside a certain environment?.
Code:
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic[2]% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined#2else#1fi%
makeatother
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
%textbfIfInTikzPicpar
%IfInTikzPicinsideoutside
%
%begintikzpicture
% IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
%endtikzpicture
%
%medskip% --------------------------
textbfDrawLine: Actual Outputpar
%DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
tikz-pgf grouping
I would like to define the DrawLine
macro below so that it can be invoked from within a tikzpicture
environment or from outside:
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
This works fine when invoked from within a tikzpicture
, but not when it is invoked from outside (line is commented in the MWE). Invoking it from outside yields the error:
Missing endgroup inserted.
The MWE below uses the first reference below. The other two references also fail on the commented out test case.
References:
Detecting if inside a tikzpicture node. Even though this solution is for detecting within a node, it appears to work to detect if you are within a
tikzpicture
(as the commented out code in the MWE shows).Is there a (simple) way to find out if a command is executed in a tikzpicture environment?.
How can I check if the current code is inside a certain environment?.
Code:
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic[2]% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined#2else#1fi%
makeatother
newcommand*DrawLine[1]%
IfInTikzPictikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
IfInTikzPicendtikzpicture%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
%textbfIfInTikzPicpar
%IfInTikzPicinsideoutside
%
%begintikzpicture
% IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
%endtikzpicture
%
%medskip% --------------------------
textbfDrawLine: Actual Outputpar
%DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
tikz-pgf grouping
tikz-pgf grouping
edited 1 hour ago
asked 2 hours ago
Peter Grill
162k24432737
162k24432737
1
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:Undefined control sequence
).
â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago
add a comment |Â
1
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:Undefined control sequence
).
â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago
1
1
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:
Undefined control sequence
).â Peter Grill
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:
Undefined control sequence
).â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
The following example defines IfInTikzPic
to check the curr
ent envir
onment against tikzpicture
and define a tikzstart
...tikzend
pair accordingly:
documentclassarticle
usepackagetikz
makeatletter
def@tikzenvironmenttikzpicture
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandtikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
newcommand*DrawLine[1]%
IfInTikzPic
tikzstart
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
tikzend%
makeatother
begindocument
textbfDrawLine: Actual Outputpar
DrawLineblue
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
You could also group the tikzpicture
if needed:
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandbegintikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
add a comment |Â
up vote
3
down vote
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommand*DrawLine[1]%
IfInTikzPic
begintikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
endtikzpicture%
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
textbfIfInTikzPicpar
IfInTikzPicinsideoutside
begintikzpicture
IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
endtikzpicture
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
Or this version which directly forces tikz rather than having an if-then-else construct
documentclassarticle
usepackagetikz
makeatletter
newcommandensuretikz% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandaftertikzify
else
expandafter@firstofone
fi
makeatother
deftikzify#1begintikzpicture#1endtikzpicture
newcommand*DrawLine[1]%
ensuretikz
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
@PeterGrill I think the main error wasIfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.
â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
The following example defines IfInTikzPic
to check the curr
ent envir
onment against tikzpicture
and define a tikzstart
...tikzend
pair accordingly:
documentclassarticle
usepackagetikz
makeatletter
def@tikzenvironmenttikzpicture
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandtikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
newcommand*DrawLine[1]%
IfInTikzPic
tikzstart
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
tikzend%
makeatother
begindocument
textbfDrawLine: Actual Outputpar
DrawLineblue
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
You could also group the tikzpicture
if needed:
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandbegintikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
add a comment |Â
up vote
4
down vote
The following example defines IfInTikzPic
to check the curr
ent envir
onment against tikzpicture
and define a tikzstart
...tikzend
pair accordingly:
documentclassarticle
usepackagetikz
makeatletter
def@tikzenvironmenttikzpicture
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandtikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
newcommand*DrawLine[1]%
IfInTikzPic
tikzstart
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
tikzend%
makeatother
begindocument
textbfDrawLine: Actual Outputpar
DrawLineblue
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
You could also group the tikzpicture
if needed:
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandbegintikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The following example defines IfInTikzPic
to check the curr
ent envir
onment against tikzpicture
and define a tikzstart
...tikzend
pair accordingly:
documentclassarticle
usepackagetikz
makeatletter
def@tikzenvironmenttikzpicture
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandtikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
newcommand*DrawLine[1]%
IfInTikzPic
tikzstart
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
tikzend%
makeatother
begindocument
textbfDrawLine: Actual Outputpar
DrawLineblue
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
You could also group the tikzpicture
if needed:
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandbegintikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
The following example defines IfInTikzPic
to check the curr
ent envir
onment against tikzpicture
and define a tikzstart
...tikzend
pair accordingly:
documentclassarticle
usepackagetikz
makeatletter
def@tikzenvironmenttikzpicture
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandtikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
newcommand*DrawLine[1]%
IfInTikzPic
tikzstart
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
tikzend%
makeatother
begindocument
textbfDrawLine: Actual Outputpar
DrawLineblue
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
You could also group the tikzpicture
if needed:
newcommandIfInTikzPic%
edeftikzstart%
ifx@currenvir@tikzenvironmentelse
noexpandbegintikzpicture[remember picture]%
fi
%
edeftikzend%
ifx@currenvir@tikzenvironmentelse
noexpandendtikzpicture%
fi
%
edited 1 hour ago
answered 1 hour ago
Werner
428k589391616
428k589391616
add a comment |Â
add a comment |Â
up vote
3
down vote
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommand*DrawLine[1]%
IfInTikzPic
begintikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
endtikzpicture%
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
textbfIfInTikzPicpar
IfInTikzPicinsideoutside
begintikzpicture
IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
endtikzpicture
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
Or this version which directly forces tikz rather than having an if-then-else construct
documentclassarticle
usepackagetikz
makeatletter
newcommandensuretikz% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandaftertikzify
else
expandafter@firstofone
fi
makeatother
deftikzify#1begintikzpicture#1endtikzpicture
newcommand*DrawLine[1]%
ensuretikz
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
@PeterGrill I think the main error wasIfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.
â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
add a comment |Â
up vote
3
down vote
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommand*DrawLine[1]%
IfInTikzPic
begintikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
endtikzpicture%
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
textbfIfInTikzPicpar
IfInTikzPicinsideoutside
begintikzpicture
IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
endtikzpicture
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
Or this version which directly forces tikz rather than having an if-then-else construct
documentclassarticle
usepackagetikz
makeatletter
newcommandensuretikz% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandaftertikzify
else
expandafter@firstofone
fi
makeatother
deftikzify#1begintikzpicture#1endtikzpicture
newcommand*DrawLine[1]%
ensuretikz
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
@PeterGrill I think the main error wasIfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.
â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommand*DrawLine[1]%
IfInTikzPic
begintikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
endtikzpicture%
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
textbfIfInTikzPicpar
IfInTikzPicinsideoutside
begintikzpicture
IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
endtikzpicture
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
Or this version which directly forces tikz rather than having an if-then-else construct
documentclassarticle
usepackagetikz
makeatletter
newcommandensuretikz% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandaftertikzify
else
expandafter@firstofone
fi
makeatother
deftikzify#1begintikzpicture#1endtikzpicture
newcommand*DrawLine[1]%
ensuretikz
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
documentclassarticle
usepackagetikz
makeatletter
newcommandIfInTikzPic% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommand*DrawLine[1]%
IfInTikzPic
begintikzpicture[remember picture]
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;
endtikzpicture%
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
textbfIfInTikzPicpar
IfInTikzPicinsideoutside
begintikzpicture
IfInTikzPicdraw [red, ultra thick]draw [blue, ultra thick] (0,0) -- (1,0);
endtikzpicture
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
Or this version which directly forces tikz rather than having an if-then-else construct
documentclassarticle
usepackagetikz
makeatletter
newcommandensuretikz% https://tex.stackexchange.com/a/121309/4301
ifxpgfpictureid@undefined
expandaftertikzify
else
expandafter@firstofone
fi
makeatother
deftikzify#1begintikzpicture#1endtikzpicture
newcommand*DrawLine[1]%
ensuretikz
draw[ultra thick, ->, #1] (0,) -- (1,1) node [right] output of DrawLine;%
begindocument
%%% The commented out code here is to show that IfInTikzPic works as desired
%%% (in a tikzpicture, outside of a node).
%%%
medskip% --------------------------
textbfDrawLine: Actual Outputpar
DrawLineblue% <---- How do I get this case to work?
begintikzpicture
DrawLineorange
endtikzpicture
medskip% --------------------------
textbfDrawLine: Desired Outputpar
begintikzpicture
DrawLineblue
endtikzpicture
begintikzpicture
DrawLineorange
endtikzpicture
enddocument
edited 25 mins ago
answered 1 hour ago
David Carlisle
475k3811041838
475k3811041838
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
@PeterGrill I think the main error wasIfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.
â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
add a comment |Â
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
@PeterGrill I think the main error wasIfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.
â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
I thought it might have something to dot with the dreaded expansion issues!
â Peter Grill
1 hour ago
2
2
@PeterGrill I think the main error was
IfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.â David Carlisle
1 hour ago
@PeterGrill I think the main error was
IfInTikzPicendtikzpicture%
as by that point you are always in a tikz picture, you need to know if you started it or if you were already in one.â David Carlisle
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
Opsss..., thats a bit embarrassing. I'd prefer to not duplicate the drawing code though.
â Peter Grill
1 hour ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill duplicating it isn't needed, I could post a variant without, i just started by simplifying it
â David Carlisle
31 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
@PeterGrill plan b posted
â David Carlisle
25 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f458849%2fdetecting-if-inside-a-tikzpicture%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
tex.stackexchange.com/questions/18652/⦠perhaps
â Torbjørn T.
1 hour ago
Or tex.stackexchange.com/questions/412456/â¦
â marmot
1 hour ago
@TorbjørnT.: That works for all but the commented out case below (yields a different error message though:
Undefined control sequence
).â Peter Grill
1 hour ago
@marmot: Yep, that also works for all but the commented out case below and produces the same error message.
â Peter Grill
1 hour ago