pic versus macro in TikZDraw 4 of the same figure in the same tikzpicturecopy and scale one figure (wheel)Rotate a node but not its content: the case of the ellipse decorationTikZ - bad positioning of images drawn by macroPass key option inside a macro to a TikZ drawing commandHow to define the default vertical distance between nodes?Numerical conditional within tikz keys?TikZ: Drawing an arc from an intersection to an intersectionDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themTikZ: clip with Pic?Nested tikz pics?

Were tables of square roots ever in use?

Is it possible to fly backward if you have really strong headwind?

The usage of kelvin in formulas

Can I utilise a baking stone to make crepes?

Sql Server delete syntax

How do i export activities related to an account with a specific recordtype?

Did Apple bundle a specific monitor with the Apple II+ for schools?

Should I refuse to be named as co-author of a low quality paper?

Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?

If I leave the US through an airport, do I have to return through the same airport?

Analogy between an unknown in an argument, and a contradiction in the principle of explosion

Can you make an identity from this product?

How to befriend someone who doesn't like to talk?

If a Variant Human is Reincarnated, would they lose the feat and skill proficiency they started with?

Is it safe to change the harddrive power feature so that it never turns off?

Who voices the small round football sized demon In Good Omens

Do you have to have figures when playing D&D?

Solving ‘Null geometry…’ error during distance matrix operation?

How to publish items after pipeline is finished?

Why does this query, missing a FROM clause, not error out?

Why did Intel abandon unified CPU cache?

Was Self-modifying-code possible just using BASIC?

Should I put programming books I wrote a few years ago on my resume?

How long is it safe to leave marker on a Chessex battle map?



pic versus macro in TikZ


Draw 4 of the same figure in the same tikzpicturecopy and scale one figure (wheel)Rotate a node but not its content: the case of the ellipse decorationTikZ - bad positioning of images drawn by macroPass key option inside a macro to a TikZ drawing commandHow to define the default vertical distance between nodes?Numerical conditional within tikz keys?TikZ: Drawing an arc from an intersection to an intersectionDrawing rectilinear curves in Tikz, aka an Etch-a-Sketch drawingLine up nested tikz enviroments or how to get rid of themTikZ: clip with Pic?Nested tikz pics?













14















Consider this code in the TikZ - PGF manual, which uses a macro



% Main code from
% The TikZ - PGF manual
% Author: Till Tantau et al
% Version 3.1.3, released May 9, 2019
% Page 40
documentclass[tikz]standalone
begindocument
begintikzpicture
defrectanglepath-- ++(1cm,0cm) -- ++(0cm,1cm) -- ++(-1cm,0cm) -- cycle
draw (0,0) rectanglepath;
draw (1.5,0) rectanglepath;
endtikzpicture
enddocument


and this one written by me, which uses pic



documentclass[tikz]standalone
begindocument
begintikzpicture
[rectanglepath/.pic=draw (0,0)--++(1cm,0cm)--++(0cm,1cm)--++(-1cm,0cm)--cycle;]
pic at (0,0) rectanglepath;
pic at (1.5,0) rectanglepath;
endtikzpicture
enddocument


Both give us the same output



enter image description here



Observation



Both give the same output. I prefer the latter one, as it is more "TikZ-ish". However, we can always change a code from pic to macro and vice versa, as above (am I wrong – is there a case in which we can't convert?), or draw the same figure using two different codes (this and this for example).



Also, I can't see any aspects in which macros are better than pic. Even arguments: we can also have pic with up to nine arguments with any pattern using /.style args.



In the PGF manual, sometimes I see pic is used, but sometimes a macro is used (it is even used in the title page!). From those examples, I can't figure out in what case I should use a macro and in what case I should use a pic.



Question



It may be quite clear by now.




If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why? Is there any cases in which I must use this one and not the other?




Thanks in advance.




Edit



As for @marmot's nice codes, I have written myself some code (against it) which uses macros



documentclassarticle
usepackagetikz
begindocument
subsection*Macros can have more complicated constructions

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) -- (0.5,-0.5);]
newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope
%path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
rectanglepath0,0
rectanglepath[dashed]2,0
endtikzpicture

subsection*Macros can have names

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;]
newcommandrectanglepath[3][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate (#3-tl)
-- (0.5,-0.5) coordinate (#3-br);endscope
%path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
rectanglepath0,0A
rectanglepath[dashed]2,0B
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on macros

begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);]
newcommandrectanglepath[2][]
scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);endscope
%path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
%(4,0) pic[thick,xscale=0.5]rectanglepath;
rectanglepath[rotate=45]0,0
rectanglepath[rotate=-30,dashed]2,0
rectanglepath[thick,xscale=0.5]4,0
endtikzpicture
enddocument


enter image description here










share|improve this question
























  • My experience is that pics are faster. For example, the threads on a screw.

    – John Kormylo
    May 25 at 13:45











  • @JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

    – The old JouleV
    May 25 at 15:16















14















Consider this code in the TikZ - PGF manual, which uses a macro



% Main code from
% The TikZ - PGF manual
% Author: Till Tantau et al
% Version 3.1.3, released May 9, 2019
% Page 40
documentclass[tikz]standalone
begindocument
begintikzpicture
defrectanglepath-- ++(1cm,0cm) -- ++(0cm,1cm) -- ++(-1cm,0cm) -- cycle
draw (0,0) rectanglepath;
draw (1.5,0) rectanglepath;
endtikzpicture
enddocument


and this one written by me, which uses pic



documentclass[tikz]standalone
begindocument
begintikzpicture
[rectanglepath/.pic=draw (0,0)--++(1cm,0cm)--++(0cm,1cm)--++(-1cm,0cm)--cycle;]
pic at (0,0) rectanglepath;
pic at (1.5,0) rectanglepath;
endtikzpicture
enddocument


Both give us the same output



enter image description here



Observation



Both give the same output. I prefer the latter one, as it is more "TikZ-ish". However, we can always change a code from pic to macro and vice versa, as above (am I wrong – is there a case in which we can't convert?), or draw the same figure using two different codes (this and this for example).



Also, I can't see any aspects in which macros are better than pic. Even arguments: we can also have pic with up to nine arguments with any pattern using /.style args.



In the PGF manual, sometimes I see pic is used, but sometimes a macro is used (it is even used in the title page!). From those examples, I can't figure out in what case I should use a macro and in what case I should use a pic.



Question



It may be quite clear by now.




If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why? Is there any cases in which I must use this one and not the other?




Thanks in advance.




Edit



As for @marmot's nice codes, I have written myself some code (against it) which uses macros



documentclassarticle
usepackagetikz
begindocument
subsection*Macros can have more complicated constructions

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) -- (0.5,-0.5);]
newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope
%path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
rectanglepath0,0
rectanglepath[dashed]2,0
endtikzpicture

subsection*Macros can have names

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;]
newcommandrectanglepath[3][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate (#3-tl)
-- (0.5,-0.5) coordinate (#3-br);endscope
%path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
rectanglepath0,0A
rectanglepath[dashed]2,0B
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on macros

begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);]
newcommandrectanglepath[2][]
scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);endscope
%path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
%(4,0) pic[thick,xscale=0.5]rectanglepath;
rectanglepath[rotate=45]0,0
rectanglepath[rotate=-30,dashed]2,0
rectanglepath[thick,xscale=0.5]4,0
endtikzpicture
enddocument


enter image description here










share|improve this question
























  • My experience is that pics are faster. For example, the threads on a screw.

    – John Kormylo
    May 25 at 13:45











  • @JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

    – The old JouleV
    May 25 at 15:16













14












14








14


2






Consider this code in the TikZ - PGF manual, which uses a macro



% Main code from
% The TikZ - PGF manual
% Author: Till Tantau et al
% Version 3.1.3, released May 9, 2019
% Page 40
documentclass[tikz]standalone
begindocument
begintikzpicture
defrectanglepath-- ++(1cm,0cm) -- ++(0cm,1cm) -- ++(-1cm,0cm) -- cycle
draw (0,0) rectanglepath;
draw (1.5,0) rectanglepath;
endtikzpicture
enddocument


and this one written by me, which uses pic



documentclass[tikz]standalone
begindocument
begintikzpicture
[rectanglepath/.pic=draw (0,0)--++(1cm,0cm)--++(0cm,1cm)--++(-1cm,0cm)--cycle;]
pic at (0,0) rectanglepath;
pic at (1.5,0) rectanglepath;
endtikzpicture
enddocument


Both give us the same output



enter image description here



Observation



Both give the same output. I prefer the latter one, as it is more "TikZ-ish". However, we can always change a code from pic to macro and vice versa, as above (am I wrong – is there a case in which we can't convert?), or draw the same figure using two different codes (this and this for example).



Also, I can't see any aspects in which macros are better than pic. Even arguments: we can also have pic with up to nine arguments with any pattern using /.style args.



In the PGF manual, sometimes I see pic is used, but sometimes a macro is used (it is even used in the title page!). From those examples, I can't figure out in what case I should use a macro and in what case I should use a pic.



Question



It may be quite clear by now.




If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why? Is there any cases in which I must use this one and not the other?




Thanks in advance.




Edit



As for @marmot's nice codes, I have written myself some code (against it) which uses macros



documentclassarticle
usepackagetikz
begindocument
subsection*Macros can have more complicated constructions

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) -- (0.5,-0.5);]
newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope
%path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
rectanglepath0,0
rectanglepath[dashed]2,0
endtikzpicture

subsection*Macros can have names

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;]
newcommandrectanglepath[3][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate (#3-tl)
-- (0.5,-0.5) coordinate (#3-br);endscope
%path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
rectanglepath0,0A
rectanglepath[dashed]2,0B
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on macros

begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);]
newcommandrectanglepath[2][]
scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);endscope
%path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
%(4,0) pic[thick,xscale=0.5]rectanglepath;
rectanglepath[rotate=45]0,0
rectanglepath[rotate=-30,dashed]2,0
rectanglepath[thick,xscale=0.5]4,0
endtikzpicture
enddocument


enter image description here










share|improve this question
















Consider this code in the TikZ - PGF manual, which uses a macro



% Main code from
% The TikZ - PGF manual
% Author: Till Tantau et al
% Version 3.1.3, released May 9, 2019
% Page 40
documentclass[tikz]standalone
begindocument
begintikzpicture
defrectanglepath-- ++(1cm,0cm) -- ++(0cm,1cm) -- ++(-1cm,0cm) -- cycle
draw (0,0) rectanglepath;
draw (1.5,0) rectanglepath;
endtikzpicture
enddocument


and this one written by me, which uses pic



documentclass[tikz]standalone
begindocument
begintikzpicture
[rectanglepath/.pic=draw (0,0)--++(1cm,0cm)--++(0cm,1cm)--++(-1cm,0cm)--cycle;]
pic at (0,0) rectanglepath;
pic at (1.5,0) rectanglepath;
endtikzpicture
enddocument


Both give us the same output



enter image description here



Observation



Both give the same output. I prefer the latter one, as it is more "TikZ-ish". However, we can always change a code from pic to macro and vice versa, as above (am I wrong – is there a case in which we can't convert?), or draw the same figure using two different codes (this and this for example).



Also, I can't see any aspects in which macros are better than pic. Even arguments: we can also have pic with up to nine arguments with any pattern using /.style args.



In the PGF manual, sometimes I see pic is used, but sometimes a macro is used (it is even used in the title page!). From those examples, I can't figure out in what case I should use a macro and in what case I should use a pic.



Question



It may be quite clear by now.




If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why? Is there any cases in which I must use this one and not the other?




Thanks in advance.




Edit



As for @marmot's nice codes, I have written myself some code (against it) which uses macros



documentclassarticle
usepackagetikz
begindocument
subsection*Macros can have more complicated constructions

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) -- (0.5,-0.5);]
newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope
%path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
rectanglepath0,0
rectanglepath[dashed]2,0
endtikzpicture

subsection*Macros can have names

begintikzpicture%[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
%draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;]
newcommandrectanglepath[3][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate (#3-tl)
-- (0.5,-0.5) coordinate (#3-br);endscope
%path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
rectanglepath0,0A
rectanglepath[dashed]2,0B
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on macros

begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);]
newcommandrectanglepath[2][]
scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1);endscope
%path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
%(4,0) pic[thick,xscale=0.5]rectanglepath;
rectanglepath[rotate=45]0,0
rectanglepath[rotate=-30,dashed]2,0
rectanglepath[thick,xscale=0.5]4,0
endtikzpicture
enddocument


enter image description here







tikz-pgf macros tikz-pic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 25 at 16:11







The old JouleV

















asked May 25 at 11:38









The old JouleVThe old JouleV

19.5k43176




19.5k43176












  • My experience is that pics are faster. For example, the threads on a screw.

    – John Kormylo
    May 25 at 13:45











  • @JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

    – The old JouleV
    May 25 at 15:16

















  • My experience is that pics are faster. For example, the threads on a screw.

    – John Kormylo
    May 25 at 13:45











  • @JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

    – The old JouleV
    May 25 at 15:16
















My experience is that pics are faster. For example, the threads on a screw.

– John Kormylo
May 25 at 13:45





My experience is that pics are faster. For example, the threads on a screw.

– John Kormylo
May 25 at 13:45













@JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

– The old JouleV
May 25 at 15:16





@JohnKormylo If yes, probably it is faster on very long documents. On reports I usually write, they are equal in time taken

– The old JouleV
May 25 at 15:16










1 Answer
1






active

oldest

votes


















11














Here are threefour examples of things that are much harder to achieve in the macro approach. The first three examples have been translated to macros in the revised question.



documentclassarticle
usepackagetikz
begindocument
subsection*Pics can have more complicated constructions
tikzsetrectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;

begintikzpicture
path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
endtikzpicture

subsection*Pics can have names

begintikzpicture
path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on pics

begintikzpicture
path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
(4,0) pic[thick,xscale=0.5]rectanglepath;
endtikzpicture

subsection*You can insert pics in paths

begintikzpicture[xboard/.style=insert path=
(0,0) grid (#1,#1)
foreach X in 1,...,#1
(X-0.5,X-0.5) picrectanglepath (X-0.5,#1-X+0.5) pic[rotate=90]rectanglepath]
draw[xboard=1,xshift=2cm,xboard=3,xshift=4cm,xboard=5];
endtikzpicture

enddocument


enter image description here



My personal take: pics win, at least in the above-described scenarios. IMHO the translated macros in the revised question substantiate this.



Notice that "behind the scenes" pics are macros at some level. So you will always be able to reproduce the outcome of a pic with a macro. However, the effort will be more substantial. And yes, if you are in the mood to do some unnecessary extra work, you can use macros instead of pics. So, yes, the choice can depend on the mood of the day.



Let me also stress that there are scenarios in which pics perform worse. An example of this type may be a life wheel.



BTW, there is also the insert path option that is sometimes preferable over pics IMO.






share|improve this answer




















  • 1





    +1: Perfect answer!

    – Dr. Manuel Kuehner
    May 25 at 13:42






  • 2





    @JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

    – marmot
    May 25 at 15:42






  • 2





    @JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

    – marmot
    May 25 at 15:55






  • 1





    but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

    – marmot
    May 25 at 15:55






  • 1





    @JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

    – marmot
    May 25 at 16:48











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f492585%2fpic-versus-macro-in-tikz%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









11














Here are threefour examples of things that are much harder to achieve in the macro approach. The first three examples have been translated to macros in the revised question.



documentclassarticle
usepackagetikz
begindocument
subsection*Pics can have more complicated constructions
tikzsetrectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;

begintikzpicture
path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
endtikzpicture

subsection*Pics can have names

begintikzpicture
path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on pics

begintikzpicture
path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
(4,0) pic[thick,xscale=0.5]rectanglepath;
endtikzpicture

subsection*You can insert pics in paths

begintikzpicture[xboard/.style=insert path=
(0,0) grid (#1,#1)
foreach X in 1,...,#1
(X-0.5,X-0.5) picrectanglepath (X-0.5,#1-X+0.5) pic[rotate=90]rectanglepath]
draw[xboard=1,xshift=2cm,xboard=3,xshift=4cm,xboard=5];
endtikzpicture

enddocument


enter image description here



My personal take: pics win, at least in the above-described scenarios. IMHO the translated macros in the revised question substantiate this.



Notice that "behind the scenes" pics are macros at some level. So you will always be able to reproduce the outcome of a pic with a macro. However, the effort will be more substantial. And yes, if you are in the mood to do some unnecessary extra work, you can use macros instead of pics. So, yes, the choice can depend on the mood of the day.



Let me also stress that there are scenarios in which pics perform worse. An example of this type may be a life wheel.



BTW, there is also the insert path option that is sometimes preferable over pics IMO.






share|improve this answer




















  • 1





    +1: Perfect answer!

    – Dr. Manuel Kuehner
    May 25 at 13:42






  • 2





    @JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

    – marmot
    May 25 at 15:42






  • 2





    @JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

    – marmot
    May 25 at 15:55






  • 1





    but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

    – marmot
    May 25 at 15:55






  • 1





    @JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

    – marmot
    May 25 at 16:48















11














Here are threefour examples of things that are much harder to achieve in the macro approach. The first three examples have been translated to macros in the revised question.



documentclassarticle
usepackagetikz
begindocument
subsection*Pics can have more complicated constructions
tikzsetrectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;

begintikzpicture
path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
endtikzpicture

subsection*Pics can have names

begintikzpicture
path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on pics

begintikzpicture
path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
(4,0) pic[thick,xscale=0.5]rectanglepath;
endtikzpicture

subsection*You can insert pics in paths

begintikzpicture[xboard/.style=insert path=
(0,0) grid (#1,#1)
foreach X in 1,...,#1
(X-0.5,X-0.5) picrectanglepath (X-0.5,#1-X+0.5) pic[rotate=90]rectanglepath]
draw[xboard=1,xshift=2cm,xboard=3,xshift=4cm,xboard=5];
endtikzpicture

enddocument


enter image description here



My personal take: pics win, at least in the above-described scenarios. IMHO the translated macros in the revised question substantiate this.



Notice that "behind the scenes" pics are macros at some level. So you will always be able to reproduce the outcome of a pic with a macro. However, the effort will be more substantial. And yes, if you are in the mood to do some unnecessary extra work, you can use macros instead of pics. So, yes, the choice can depend on the mood of the day.



Let me also stress that there are scenarios in which pics perform worse. An example of this type may be a life wheel.



BTW, there is also the insert path option that is sometimes preferable over pics IMO.






share|improve this answer




















  • 1





    +1: Perfect answer!

    – Dr. Manuel Kuehner
    May 25 at 13:42






  • 2





    @JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

    – marmot
    May 25 at 15:42






  • 2





    @JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

    – marmot
    May 25 at 15:55






  • 1





    but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

    – marmot
    May 25 at 15:55






  • 1





    @JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

    – marmot
    May 25 at 16:48













11












11








11







Here are threefour examples of things that are much harder to achieve in the macro approach. The first three examples have been translated to macros in the revised question.



documentclassarticle
usepackagetikz
begindocument
subsection*Pics can have more complicated constructions
tikzsetrectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;

begintikzpicture
path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
endtikzpicture

subsection*Pics can have names

begintikzpicture
path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on pics

begintikzpicture
path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
(4,0) pic[thick,xscale=0.5]rectanglepath;
endtikzpicture

subsection*You can insert pics in paths

begintikzpicture[xboard/.style=insert path=
(0,0) grid (#1,#1)
foreach X in 1,...,#1
(X-0.5,X-0.5) picrectanglepath (X-0.5,#1-X+0.5) pic[rotate=90]rectanglepath]
draw[xboard=1,xshift=2cm,xboard=3,xshift=4cm,xboard=5];
endtikzpicture

enddocument


enter image description here



My personal take: pics win, at least in the above-described scenarios. IMHO the translated macros in the revised question substantiate this.



Notice that "behind the scenes" pics are macros at some level. So you will always be able to reproduce the outcome of a pic with a macro. However, the effort will be more substantial. And yes, if you are in the mood to do some unnecessary extra work, you can use macros instead of pics. So, yes, the choice can depend on the mood of the day.



Let me also stress that there are scenarios in which pics perform worse. An example of this type may be a life wheel.



BTW, there is also the insert path option that is sometimes preferable over pics IMO.






share|improve this answer















Here are threefour examples of things that are much harder to achieve in the macro approach. The first three examples have been translated to macros in the revised question.



documentclassarticle
usepackagetikz
begindocument
subsection*Pics can have more complicated constructions
tikzsetrectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1);
draw[red] (-0.5,0.5) coordinate(-tl) -- (0.5,-0.5) coordinate(-br) ;

begintikzpicture
path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath;
endtikzpicture

subsection*Pics can have names

begintikzpicture
path (0,0) pic (A) rectanglepath (2,0) pic[dashed] (B) rectanglepath;
draw (A-tl) to[out=30,in=150] (B-tl) (A-br) to[out=-30,in=-150] (B-br);
endtikzpicture

subsection*Transformations are much more intuitive on pics

begintikzpicture
path (0,0) pic[rotate=45]rectanglepath (2,0) pic[dashed,rotate=-30]rectanglepath
(4,0) pic[thick,xscale=0.5]rectanglepath;
endtikzpicture

subsection*You can insert pics in paths

begintikzpicture[xboard/.style=insert path=
(0,0) grid (#1,#1)
foreach X in 1,...,#1
(X-0.5,X-0.5) picrectanglepath (X-0.5,#1-X+0.5) pic[rotate=90]rectanglepath]
draw[xboard=1,xshift=2cm,xboard=3,xshift=4cm,xboard=5];
endtikzpicture

enddocument


enter image description here



My personal take: pics win, at least in the above-described scenarios. IMHO the translated macros in the revised question substantiate this.



Notice that "behind the scenes" pics are macros at some level. So you will always be able to reproduce the outcome of a pic with a macro. However, the effort will be more substantial. And yes, if you are in the mood to do some unnecessary extra work, you can use macros instead of pics. So, yes, the choice can depend on the mood of the day.



Let me also stress that there are scenarios in which pics perform worse. An example of this type may be a life wheel.



BTW, there is also the insert path option that is sometimes preferable over pics IMO.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 28 at 20:16

























answered May 25 at 13:37









marmotmarmot

134k6174322




134k6174322







  • 1





    +1: Perfect answer!

    – Dr. Manuel Kuehner
    May 25 at 13:42






  • 2





    @JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

    – marmot
    May 25 at 15:42






  • 2





    @JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

    – marmot
    May 25 at 15:55






  • 1





    but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

    – marmot
    May 25 at 15:55






  • 1





    @JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

    – marmot
    May 25 at 16:48












  • 1





    +1: Perfect answer!

    – Dr. Manuel Kuehner
    May 25 at 13:42






  • 2





    @JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

    – marmot
    May 25 at 15:42






  • 2





    @JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

    – marmot
    May 25 at 15:55






  • 1





    but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

    – marmot
    May 25 at 15:55






  • 1





    @JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

    – marmot
    May 25 at 16:48







1




1





+1: Perfect answer!

– Dr. Manuel Kuehner
May 25 at 13:42





+1: Perfect answer!

– Dr. Manuel Kuehner
May 25 at 13:42




2




2





@JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

– marmot
May 25 at 15:42





@JouleV Well, at some level a pic is a macro. My point is simply that things are harder to achieve with macros, and your macros substantiate this. I never claimed that you cannot achieve things done with a pic also with a macro, it is just harder and also less elegant IMHO.

– marmot
May 25 at 15:42




2




2





@JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

– marmot
May 25 at 15:55





@JouleV You also misinterpreted "The first thingy has newcommandrectanglepath[2][]..., the next newcommandrectanglepath[3][]..., they are not the same. ". The point is that you have to write different macros for different situations, and if you want to have the combined functionality, things become even more complicated. BTW, foreach X in 1,2,3 begintikzpicture[rectanglepath/.pic=draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);] path (0,0) picrectanglepath (2,0) pic[dashed]rectanglepath; endtikzpicture works ...

– marmot
May 25 at 15:55




1




1





but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

– marmot
May 25 at 15:55





but foreach X in 1,2,3 begintikzpicture newcommandrectanglepath[2][]scope[shift=(#2),#1]draw (-0.5,-0.5) rectangle ++(1,1); draw[red] (-0.5,0.5) -- (0.5,-0.5);endscope rectanglepath0,0 rectanglepath[dashed]2,0 endtikzpicture doesn't. (Yes, I know how to fix it but it is, again, more complicated.)

– marmot
May 25 at 15:55




1




1





@JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

– marmot
May 25 at 16:48





@JouleV I tried to answer the question If I have to draw the same "sub-"picture many times in a TikZ picture, should I use a pic or a macro? And why?. My answer is that in most situations pics are less complicated, which is why they are arguably preferable.

– marmot
May 25 at 16:48

















draft saved

draft discarded
















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f492585%2fpic-versus-macro-in-tikz%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020