macros inside tikzpicture












7















I wanted to make a bit more readable the tex code I'm using and, in this respect, I wanted to somehow use a macro for the following code:



draw (10 mm,10 mm) -- (20 mm,10 mm);


I've created the following newcommands:



newcommand*horizontalLineCoor[3]{  draw (#1 mm,#2 mm) -- (#3 mm,#2 mm);   }
newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}


I'm receiving this sort of errors:



! Package PGF Math Error: Unknown function `mm' (in '( mm').

See the PGF Math package documentation for explanation.
Type H <return> for immediate help.
...

l.31 horizontalLineLength(10
, 20, 10);
?


Can you give me hand with this macros:) Thank you!
R



The test file (this should draw 2 horizontal lines):



documentclass[a4paper,10pt,fleqn]{article}
usepackage{tikz}
usetikzlibrary{positioning}
newcommand*horizontalLineCoor[3]{ draw (#1 mm,#2 mm) -- (#3 mm,#2 mm); }
newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}

begin{document}
begin{figure}
begin{tikzpicture}[
xscale=2,
yscale=2,
virtual/.style={thin,dashed}
]
horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
end{tikzpicture}
caption{Interesting caption}
end{figure}
end{document}









share|improve this question









New contributor




radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    7















    I wanted to make a bit more readable the tex code I'm using and, in this respect, I wanted to somehow use a macro for the following code:



    draw (10 mm,10 mm) -- (20 mm,10 mm);


    I've created the following newcommands:



    newcommand*horizontalLineCoor[3]{  draw (#1 mm,#2 mm) -- (#3 mm,#2 mm);   }
    newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}


    I'm receiving this sort of errors:



    ! Package PGF Math Error: Unknown function `mm' (in '( mm').

    See the PGF Math package documentation for explanation.
    Type H <return> for immediate help.
    ...

    l.31 horizontalLineLength(10
    , 20, 10);
    ?


    Can you give me hand with this macros:) Thank you!
    R



    The test file (this should draw 2 horizontal lines):



    documentclass[a4paper,10pt,fleqn]{article}
    usepackage{tikz}
    usetikzlibrary{positioning}
    newcommand*horizontalLineCoor[3]{ draw (#1 mm,#2 mm) -- (#3 mm,#2 mm); }
    newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}

    begin{document}
    begin{figure}
    begin{tikzpicture}[
    xscale=2,
    yscale=2,
    virtual/.style={thin,dashed}
    ]
    horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
    horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
    end{tikzpicture}
    caption{Interesting caption}
    end{figure}
    end{document}









    share|improve this question









    New contributor




    radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      7












      7








      7


      1






      I wanted to make a bit more readable the tex code I'm using and, in this respect, I wanted to somehow use a macro for the following code:



      draw (10 mm,10 mm) -- (20 mm,10 mm);


      I've created the following newcommands:



      newcommand*horizontalLineCoor[3]{  draw (#1 mm,#2 mm) -- (#3 mm,#2 mm);   }
      newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}


      I'm receiving this sort of errors:



      ! Package PGF Math Error: Unknown function `mm' (in '( mm').

      See the PGF Math package documentation for explanation.
      Type H <return> for immediate help.
      ...

      l.31 horizontalLineLength(10
      , 20, 10);
      ?


      Can you give me hand with this macros:) Thank you!
      R



      The test file (this should draw 2 horizontal lines):



      documentclass[a4paper,10pt,fleqn]{article}
      usepackage{tikz}
      usetikzlibrary{positioning}
      newcommand*horizontalLineCoor[3]{ draw (#1 mm,#2 mm) -- (#3 mm,#2 mm); }
      newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}

      begin{document}
      begin{figure}
      begin{tikzpicture}[
      xscale=2,
      yscale=2,
      virtual/.style={thin,dashed}
      ]
      horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
      horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
      end{tikzpicture}
      caption{Interesting caption}
      end{figure}
      end{document}









      share|improve this question









      New contributor




      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I wanted to make a bit more readable the tex code I'm using and, in this respect, I wanted to somehow use a macro for the following code:



      draw (10 mm,10 mm) -- (20 mm,10 mm);


      I've created the following newcommands:



      newcommand*horizontalLineCoor[3]{  draw (#1 mm,#2 mm) -- (#3 mm,#2 mm);   }
      newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}


      I'm receiving this sort of errors:



      ! Package PGF Math Error: Unknown function `mm' (in '( mm').

      See the PGF Math package documentation for explanation.
      Type H <return> for immediate help.
      ...

      l.31 horizontalLineLength(10
      , 20, 10);
      ?


      Can you give me hand with this macros:) Thank you!
      R



      The test file (this should draw 2 horizontal lines):



      documentclass[a4paper,10pt,fleqn]{article}
      usepackage{tikz}
      usetikzlibrary{positioning}
      newcommand*horizontalLineCoor[3]{ draw (#1 mm,#2 mm) -- (#3 mm,#2 mm); }
      newcommand*horizontalLineLength[3]{draw (#1 mm,#2 mm) -- (#1+#3 mm,#2 mm);}

      begin{document}
      begin{figure}
      begin{tikzpicture}[
      xscale=2,
      yscale=2,
      virtual/.style={thin,dashed}
      ]
      horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
      horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
      end{tikzpicture}
      caption{Interesting caption}
      end{figure}
      end{document}






      tikz-pgf macros






      share|improve this question









      New contributor




      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday







      radu













      New contributor




      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked yesterday









      raduradu

      362




      362




      New contributor




      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      radu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes


















          10














          You provided no test file but the error shows you used the syntax



          horizontalLineLength(10, 20, 10);


          But you have defined the command with three TeX arguments, that supplied the ; so



          horizontalLineLength{10}{20}{10}





          share|improve this answer

































            4














            You can use the syntax horizontalLineCoor(10, 10, 20) if you prefer. However, this is a bit awkward, because TeX does not treat multiple arguments like C or other programming languages; if you define



            newcommand{foo}[3]{...}


            the call should be like



            foo{x}{y}{z}


            each argument enclosed in braces.



            However, the syntax with parentheses can be set up using xparse, that provides fairly general methods for inputting arguments.



            documentclass[a4paper,10pt,fleqn]{article}
            usepackage{xparse}
            usepackage{tikz}
            usetikzlibrary{positioning}

            NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
            horizontalLineCoorDo#1%
            }
            NewDocumentCommand{horizontalLineLength}{>{SplitArgument{2}{,}}r()}{%
            horizontalLineLengthDo#1%
            }
            NewDocumentCommand{horizontalLineCoorDo}{mmm}{%
            horizontalLineDo{#1}{#2}{#3}%
            }
            NewDocumentCommand{horizontalLineLengthDo}{mmm}{%
            horizontalLineDo{#1}{#2}{#1+#3}%
            }
            NewDocumentCommand{horizontalLineDo}{mmm}{%
            draw (#1 mm,#2 mm) -- (#3 mm,#2 mm)%
            }


            begin{document}

            begin{figure}[htp]
            centering

            begin{tikzpicture}[
            xscale=2,
            yscale=2,
            virtual/.style={thin,dashed}
            ]
            horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
            horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
            end{tikzpicture}
            caption{Interesting caption}

            end{figure}

            end{document}


            The definition



            NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
            horizontalLineCoorDo#1%
            }


            says that horizontalLineCoor accepts one argument enclosed between parentheses; but we can tell LaTeX to split this argument at commas (there should be two of them), so at the end a call such as



            horizontalLineCoor(10, 10, 20)


            results in



            horizontalLineCoorDo{10}{10}{20}


            so the arguments are “TeX-normalized”. Now it's a matter of defining horizontalLineCoorDo, which I do in an indirect fashion so as to avoid code duplication for the main code, since horizontalLineCoor and horizontalLineLength do very similar tasks.



            enter image description here






            share|improve this answer































              3














              This is just to remark that TikZ comes with its own means to define such abbreviations. Your commands can be represented by two styles, horizontal to and horizontal add, which do the same as what your commands should do (if I understand correctly).



              documentclass[a4paper,10pt,fleqn]{article}
              usepackage{tikz}

              begin{document}
              begin{figure}
              begin{tikzpicture}[
              xscale=2,
              yscale=2,
              horizontal to/.style={insert path={coordinate(aux) -- (#1mm,0 |-aux)}},
              horizontal add/.style={insert path={-- ++ (#1mm,0)}},
              ]
              draw (10mm,10mm) [horizontal to=20];
              draw (10mm,20mm) [horizontal add=10];
              end{tikzpicture}
              caption{Interesting caption.}
              end{figure}
              end{document}


              enter image description here






              share|improve this answer



















              • 1





                Eventually, the appropriate TikZ answer! (+1)

                – CarLaTeX
                21 hours ago











              • @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                – David Carlisle
                17 hours ago











              • @DavidCarlisle lol

                – CarLaTeX
                17 hours ago











              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
              });


              }
              });






              radu is a new contributor. Be nice, and check out our Code of Conduct.










              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f473074%2fmacros-inside-tikzpicture%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              10














              You provided no test file but the error shows you used the syntax



              horizontalLineLength(10, 20, 10);


              But you have defined the command with three TeX arguments, that supplied the ; so



              horizontalLineLength{10}{20}{10}





              share|improve this answer






























                10














                You provided no test file but the error shows you used the syntax



                horizontalLineLength(10, 20, 10);


                But you have defined the command with three TeX arguments, that supplied the ; so



                horizontalLineLength{10}{20}{10}





                share|improve this answer




























                  10












                  10








                  10







                  You provided no test file but the error shows you used the syntax



                  horizontalLineLength(10, 20, 10);


                  But you have defined the command with three TeX arguments, that supplied the ; so



                  horizontalLineLength{10}{20}{10}





                  share|improve this answer















                  You provided no test file but the error shows you used the syntax



                  horizontalLineLength(10, 20, 10);


                  But you have defined the command with three TeX arguments, that supplied the ; so



                  horizontalLineLength{10}{20}{10}






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited yesterday

























                  answered yesterday









                  David CarlisleDavid Carlisle

                  488k4111271875




                  488k4111271875























                      4














                      You can use the syntax horizontalLineCoor(10, 10, 20) if you prefer. However, this is a bit awkward, because TeX does not treat multiple arguments like C or other programming languages; if you define



                      newcommand{foo}[3]{...}


                      the call should be like



                      foo{x}{y}{z}


                      each argument enclosed in braces.



                      However, the syntax with parentheses can be set up using xparse, that provides fairly general methods for inputting arguments.



                      documentclass[a4paper,10pt,fleqn]{article}
                      usepackage{xparse}
                      usepackage{tikz}
                      usetikzlibrary{positioning}

                      NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                      horizontalLineCoorDo#1%
                      }
                      NewDocumentCommand{horizontalLineLength}{>{SplitArgument{2}{,}}r()}{%
                      horizontalLineLengthDo#1%
                      }
                      NewDocumentCommand{horizontalLineCoorDo}{mmm}{%
                      horizontalLineDo{#1}{#2}{#3}%
                      }
                      NewDocumentCommand{horizontalLineLengthDo}{mmm}{%
                      horizontalLineDo{#1}{#2}{#1+#3}%
                      }
                      NewDocumentCommand{horizontalLineDo}{mmm}{%
                      draw (#1 mm,#2 mm) -- (#3 mm,#2 mm)%
                      }


                      begin{document}

                      begin{figure}[htp]
                      centering

                      begin{tikzpicture}[
                      xscale=2,
                      yscale=2,
                      virtual/.style={thin,dashed}
                      ]
                      horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
                      horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
                      end{tikzpicture}
                      caption{Interesting caption}

                      end{figure}

                      end{document}


                      The definition



                      NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                      horizontalLineCoorDo#1%
                      }


                      says that horizontalLineCoor accepts one argument enclosed between parentheses; but we can tell LaTeX to split this argument at commas (there should be two of them), so at the end a call such as



                      horizontalLineCoor(10, 10, 20)


                      results in



                      horizontalLineCoorDo{10}{10}{20}


                      so the arguments are “TeX-normalized”. Now it's a matter of defining horizontalLineCoorDo, which I do in an indirect fashion so as to avoid code duplication for the main code, since horizontalLineCoor and horizontalLineLength do very similar tasks.



                      enter image description here






                      share|improve this answer




























                        4














                        You can use the syntax horizontalLineCoor(10, 10, 20) if you prefer. However, this is a bit awkward, because TeX does not treat multiple arguments like C or other programming languages; if you define



                        newcommand{foo}[3]{...}


                        the call should be like



                        foo{x}{y}{z}


                        each argument enclosed in braces.



                        However, the syntax with parentheses can be set up using xparse, that provides fairly general methods for inputting arguments.



                        documentclass[a4paper,10pt,fleqn]{article}
                        usepackage{xparse}
                        usepackage{tikz}
                        usetikzlibrary{positioning}

                        NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                        horizontalLineCoorDo#1%
                        }
                        NewDocumentCommand{horizontalLineLength}{>{SplitArgument{2}{,}}r()}{%
                        horizontalLineLengthDo#1%
                        }
                        NewDocumentCommand{horizontalLineCoorDo}{mmm}{%
                        horizontalLineDo{#1}{#2}{#3}%
                        }
                        NewDocumentCommand{horizontalLineLengthDo}{mmm}{%
                        horizontalLineDo{#1}{#2}{#1+#3}%
                        }
                        NewDocumentCommand{horizontalLineDo}{mmm}{%
                        draw (#1 mm,#2 mm) -- (#3 mm,#2 mm)%
                        }


                        begin{document}

                        begin{figure}[htp]
                        centering

                        begin{tikzpicture}[
                        xscale=2,
                        yscale=2,
                        virtual/.style={thin,dashed}
                        ]
                        horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
                        horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
                        end{tikzpicture}
                        caption{Interesting caption}

                        end{figure}

                        end{document}


                        The definition



                        NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                        horizontalLineCoorDo#1%
                        }


                        says that horizontalLineCoor accepts one argument enclosed between parentheses; but we can tell LaTeX to split this argument at commas (there should be two of them), so at the end a call such as



                        horizontalLineCoor(10, 10, 20)


                        results in



                        horizontalLineCoorDo{10}{10}{20}


                        so the arguments are “TeX-normalized”. Now it's a matter of defining horizontalLineCoorDo, which I do in an indirect fashion so as to avoid code duplication for the main code, since horizontalLineCoor and horizontalLineLength do very similar tasks.



                        enter image description here






                        share|improve this answer


























                          4












                          4








                          4







                          You can use the syntax horizontalLineCoor(10, 10, 20) if you prefer. However, this is a bit awkward, because TeX does not treat multiple arguments like C or other programming languages; if you define



                          newcommand{foo}[3]{...}


                          the call should be like



                          foo{x}{y}{z}


                          each argument enclosed in braces.



                          However, the syntax with parentheses can be set up using xparse, that provides fairly general methods for inputting arguments.



                          documentclass[a4paper,10pt,fleqn]{article}
                          usepackage{xparse}
                          usepackage{tikz}
                          usetikzlibrary{positioning}

                          NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineCoorDo#1%
                          }
                          NewDocumentCommand{horizontalLineLength}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineLengthDo#1%
                          }
                          NewDocumentCommand{horizontalLineCoorDo}{mmm}{%
                          horizontalLineDo{#1}{#2}{#3}%
                          }
                          NewDocumentCommand{horizontalLineLengthDo}{mmm}{%
                          horizontalLineDo{#1}{#2}{#1+#3}%
                          }
                          NewDocumentCommand{horizontalLineDo}{mmm}{%
                          draw (#1 mm,#2 mm) -- (#3 mm,#2 mm)%
                          }


                          begin{document}

                          begin{figure}[htp]
                          centering

                          begin{tikzpicture}[
                          xscale=2,
                          yscale=2,
                          virtual/.style={thin,dashed}
                          ]
                          horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
                          horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
                          end{tikzpicture}
                          caption{Interesting caption}

                          end{figure}

                          end{document}


                          The definition



                          NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineCoorDo#1%
                          }


                          says that horizontalLineCoor accepts one argument enclosed between parentheses; but we can tell LaTeX to split this argument at commas (there should be two of them), so at the end a call such as



                          horizontalLineCoor(10, 10, 20)


                          results in



                          horizontalLineCoorDo{10}{10}{20}


                          so the arguments are “TeX-normalized”. Now it's a matter of defining horizontalLineCoorDo, which I do in an indirect fashion so as to avoid code duplication for the main code, since horizontalLineCoor and horizontalLineLength do very similar tasks.



                          enter image description here






                          share|improve this answer













                          You can use the syntax horizontalLineCoor(10, 10, 20) if you prefer. However, this is a bit awkward, because TeX does not treat multiple arguments like C or other programming languages; if you define



                          newcommand{foo}[3]{...}


                          the call should be like



                          foo{x}{y}{z}


                          each argument enclosed in braces.



                          However, the syntax with parentheses can be set up using xparse, that provides fairly general methods for inputting arguments.



                          documentclass[a4paper,10pt,fleqn]{article}
                          usepackage{xparse}
                          usepackage{tikz}
                          usetikzlibrary{positioning}

                          NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineCoorDo#1%
                          }
                          NewDocumentCommand{horizontalLineLength}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineLengthDo#1%
                          }
                          NewDocumentCommand{horizontalLineCoorDo}{mmm}{%
                          horizontalLineDo{#1}{#2}{#3}%
                          }
                          NewDocumentCommand{horizontalLineLengthDo}{mmm}{%
                          horizontalLineDo{#1}{#2}{#1+#3}%
                          }
                          NewDocumentCommand{horizontalLineDo}{mmm}{%
                          draw (#1 mm,#2 mm) -- (#3 mm,#2 mm)%
                          }


                          begin{document}

                          begin{figure}[htp]
                          centering

                          begin{tikzpicture}[
                          xscale=2,
                          yscale=2,
                          virtual/.style={thin,dashed}
                          ]
                          horizontalLineCoor(10, 10, 20); %%%draw (10 mm,10 mm) -- (20 mm,10 mm);
                          horizontalLineLength(10, 20, 10); %%%draw (10 mm,20 mm) -- (20 mm,20 mm);
                          end{tikzpicture}
                          caption{Interesting caption}

                          end{figure}

                          end{document}


                          The definition



                          NewDocumentCommand{horizontalLineCoor}{>{SplitArgument{2}{,}}r()}{%
                          horizontalLineCoorDo#1%
                          }


                          says that horizontalLineCoor accepts one argument enclosed between parentheses; but we can tell LaTeX to split this argument at commas (there should be two of them), so at the end a call such as



                          horizontalLineCoor(10, 10, 20)


                          results in



                          horizontalLineCoorDo{10}{10}{20}


                          so the arguments are “TeX-normalized”. Now it's a matter of defining horizontalLineCoorDo, which I do in an indirect fashion so as to avoid code duplication for the main code, since horizontalLineCoor and horizontalLineLength do very similar tasks.



                          enter image description here







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          egregegreg

                          717k8719023194




                          717k8719023194























                              3














                              This is just to remark that TikZ comes with its own means to define such abbreviations. Your commands can be represented by two styles, horizontal to and horizontal add, which do the same as what your commands should do (if I understand correctly).



                              documentclass[a4paper,10pt,fleqn]{article}
                              usepackage{tikz}

                              begin{document}
                              begin{figure}
                              begin{tikzpicture}[
                              xscale=2,
                              yscale=2,
                              horizontal to/.style={insert path={coordinate(aux) -- (#1mm,0 |-aux)}},
                              horizontal add/.style={insert path={-- ++ (#1mm,0)}},
                              ]
                              draw (10mm,10mm) [horizontal to=20];
                              draw (10mm,20mm) [horizontal add=10];
                              end{tikzpicture}
                              caption{Interesting caption.}
                              end{figure}
                              end{document}


                              enter image description here






                              share|improve this answer



















                              • 1





                                Eventually, the appropriate TikZ answer! (+1)

                                – CarLaTeX
                                21 hours ago











                              • @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                                – David Carlisle
                                17 hours ago











                              • @DavidCarlisle lol

                                – CarLaTeX
                                17 hours ago
















                              3














                              This is just to remark that TikZ comes with its own means to define such abbreviations. Your commands can be represented by two styles, horizontal to and horizontal add, which do the same as what your commands should do (if I understand correctly).



                              documentclass[a4paper,10pt,fleqn]{article}
                              usepackage{tikz}

                              begin{document}
                              begin{figure}
                              begin{tikzpicture}[
                              xscale=2,
                              yscale=2,
                              horizontal to/.style={insert path={coordinate(aux) -- (#1mm,0 |-aux)}},
                              horizontal add/.style={insert path={-- ++ (#1mm,0)}},
                              ]
                              draw (10mm,10mm) [horizontal to=20];
                              draw (10mm,20mm) [horizontal add=10];
                              end{tikzpicture}
                              caption{Interesting caption.}
                              end{figure}
                              end{document}


                              enter image description here






                              share|improve this answer



















                              • 1





                                Eventually, the appropriate TikZ answer! (+1)

                                – CarLaTeX
                                21 hours ago











                              • @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                                – David Carlisle
                                17 hours ago











                              • @DavidCarlisle lol

                                – CarLaTeX
                                17 hours ago














                              3












                              3








                              3







                              This is just to remark that TikZ comes with its own means to define such abbreviations. Your commands can be represented by two styles, horizontal to and horizontal add, which do the same as what your commands should do (if I understand correctly).



                              documentclass[a4paper,10pt,fleqn]{article}
                              usepackage{tikz}

                              begin{document}
                              begin{figure}
                              begin{tikzpicture}[
                              xscale=2,
                              yscale=2,
                              horizontal to/.style={insert path={coordinate(aux) -- (#1mm,0 |-aux)}},
                              horizontal add/.style={insert path={-- ++ (#1mm,0)}},
                              ]
                              draw (10mm,10mm) [horizontal to=20];
                              draw (10mm,20mm) [horizontal add=10];
                              end{tikzpicture}
                              caption{Interesting caption.}
                              end{figure}
                              end{document}


                              enter image description here






                              share|improve this answer













                              This is just to remark that TikZ comes with its own means to define such abbreviations. Your commands can be represented by two styles, horizontal to and horizontal add, which do the same as what your commands should do (if I understand correctly).



                              documentclass[a4paper,10pt,fleqn]{article}
                              usepackage{tikz}

                              begin{document}
                              begin{figure}
                              begin{tikzpicture}[
                              xscale=2,
                              yscale=2,
                              horizontal to/.style={insert path={coordinate(aux) -- (#1mm,0 |-aux)}},
                              horizontal add/.style={insert path={-- ++ (#1mm,0)}},
                              ]
                              draw (10mm,10mm) [horizontal to=20];
                              draw (10mm,20mm) [horizontal add=10];
                              end{tikzpicture}
                              caption{Interesting caption.}
                              end{figure}
                              end{document}


                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered yesterday









                              marmotmarmot

                              97k4112213




                              97k4112213








                              • 1





                                Eventually, the appropriate TikZ answer! (+1)

                                – CarLaTeX
                                21 hours ago











                              • @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                                – David Carlisle
                                17 hours ago











                              • @DavidCarlisle lol

                                – CarLaTeX
                                17 hours ago














                              • 1





                                Eventually, the appropriate TikZ answer! (+1)

                                – CarLaTeX
                                21 hours ago











                              • @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                                – David Carlisle
                                17 hours ago











                              • @DavidCarlisle lol

                                – CarLaTeX
                                17 hours ago








                              1




                              1





                              Eventually, the appropriate TikZ answer! (+1)

                              – CarLaTeX
                              21 hours ago





                              Eventually, the appropriate TikZ answer! (+1)

                              – CarLaTeX
                              21 hours ago













                              @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                              – David Carlisle
                              17 hours ago





                              @CarLaTeX I can't guess what you mean, I got a badge for my answer!

                              – David Carlisle
                              17 hours ago













                              @DavidCarlisle lol

                              – CarLaTeX
                              17 hours ago





                              @DavidCarlisle lol

                              – CarLaTeX
                              17 hours ago










                              radu is a new contributor. Be nice, and check out our Code of Conduct.










                              draft saved

                              draft discarded


















                              radu is a new contributor. Be nice, and check out our Code of Conduct.













                              radu is a new contributor. Be nice, and check out our Code of Conduct.












                              radu is a new contributor. Be nice, and check out our Code of Conduct.
















                              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%2f473074%2fmacros-inside-tikzpicture%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

                              If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                              Alcedinidae

                              Can an atomic nucleus contain both particles and antiparticles? [duplicate]