A simple macro with tikzcd - fork diagrams

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I am trying to create a macro to easily draw forks as this one:



enter image description here



I tried this:



 newcommandfork[6]
begincenter
begintikzcd
#1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
arrow[r,shift right, "#5"'] & #6
endtikzcd
endcenter



But I get an error "Single ampersand used with wrong catcode."










share|improve this question

























    up vote
    2
    down vote

    favorite












    I am trying to create a macro to easily draw forks as this one:



    enter image description here



    I tried this:



     newcommandfork[6]
    begincenter
    begintikzcd
    #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
    arrow[r,shift right, "#5"'] & #6
    endtikzcd
    endcenter



    But I get an error "Single ampersand used with wrong catcode."










    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I am trying to create a macro to easily draw forks as this one:



      enter image description here



      I tried this:



       newcommandfork[6]
      begincenter
      begintikzcd
      #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
      arrow[r,shift right, "#5"'] & #6
      endtikzcd
      endcenter



      But I get an error "Single ampersand used with wrong catcode."










      share|improve this question













      I am trying to create a macro to easily draw forks as this one:



      enter image description here



      I tried this:



       newcommandfork[6]
      begincenter
      begintikzcd
      #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
      arrow[r,shift right, "#5"'] & #6
      endtikzcd
      endcenter



      But I get an error "Single ampersand used with wrong catcode."







      tikz-pgf macros






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 at 14:59









      Soap

      1554




      1554




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          You don't really want to use the center environment, but the main problem is the &:



          newcommandfork[6]%
          begintikzcd[ampersand replacement=&]
          #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
          arrow[r,shift right, "#5"'] & #6
          endtikzcd%



          The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.



          Use it in a display environment, say



          [
          forkKkAf0B
          ]


          Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



          documentclassarticle
          usepackageamsmath
          usepackagetikz-cd
          usepackagexparse

          ExplSyntaxOn

          keys_define:nn soap/forks

          s .tl_set:N = l__soap_fork_source_tl,
          t .tl_set:N = l__soap_fork_target_tl,
          e .tl_set:N = l__soap_fork_end_tl,
          u .tl_set:N = l__soap_fork_up_tl,
          d .tl_set:N = l__soap_fork_down_tl,
          c .tl_set:N = l__soap_fork_center_tl,
          * .bool_set:N = l__soap_fork_co_bool,
          * .default:n = true,


          NewDocumentCommandforkm

          keys_set:nn soap/forks #1
          begintikzcd[ampersand~replacement=&]
          bool_if:NF l__soap_fork_co_bool
          % false, equalizer
          l__soap_fork_end_tl
          arrow[r,"l__soap_fork_center_tl"] &

          l__soap_fork_source_tl
          arrow[r,shift~left,"l__soap_fork_up_tl"]
          arrow[r,shift~right,"l__soap_fork_down_tl",swap] &
          l__soap_fork_target_tl
          bool_if:NT l__soap_fork_co_bool
          % true, coequalizer
          arrow[r,"l__soap_fork_center_tl"] &
          l__soap_fork_end_tl

          endtikzcd


          ExplSyntaxOff

          begindocument

          begingather
          forks=A,t=B,e=K,u=f,d=0,c=k
          \
          fork*,s=A,t=B,e=K,u=f,d=0,c=k
          endgather

          enddocument


          enter image description here






          share|improve this answer






















            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',
            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%2f461427%2fa-simple-macro-with-tikzcd-fork-diagrams%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








            up vote
            4
            down vote



            accepted










            You don't really want to use the center environment, but the main problem is the &:



            newcommandfork[6]%
            begintikzcd[ampersand replacement=&]
            #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
            arrow[r,shift right, "#5"'] & #6
            endtikzcd%



            The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.



            Use it in a display environment, say



            [
            forkKkAf0B
            ]


            Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



            documentclassarticle
            usepackageamsmath
            usepackagetikz-cd
            usepackagexparse

            ExplSyntaxOn

            keys_define:nn soap/forks

            s .tl_set:N = l__soap_fork_source_tl,
            t .tl_set:N = l__soap_fork_target_tl,
            e .tl_set:N = l__soap_fork_end_tl,
            u .tl_set:N = l__soap_fork_up_tl,
            d .tl_set:N = l__soap_fork_down_tl,
            c .tl_set:N = l__soap_fork_center_tl,
            * .bool_set:N = l__soap_fork_co_bool,
            * .default:n = true,


            NewDocumentCommandforkm

            keys_set:nn soap/forks #1
            begintikzcd[ampersand~replacement=&]
            bool_if:NF l__soap_fork_co_bool
            % false, equalizer
            l__soap_fork_end_tl
            arrow[r,"l__soap_fork_center_tl"] &

            l__soap_fork_source_tl
            arrow[r,shift~left,"l__soap_fork_up_tl"]
            arrow[r,shift~right,"l__soap_fork_down_tl",swap] &
            l__soap_fork_target_tl
            bool_if:NT l__soap_fork_co_bool
            % true, coequalizer
            arrow[r,"l__soap_fork_center_tl"] &
            l__soap_fork_end_tl

            endtikzcd


            ExplSyntaxOff

            begindocument

            begingather
            forks=A,t=B,e=K,u=f,d=0,c=k
            \
            fork*,s=A,t=B,e=K,u=f,d=0,c=k
            endgather

            enddocument


            enter image description here






            share|improve this answer


























              up vote
              4
              down vote



              accepted










              You don't really want to use the center environment, but the main problem is the &:



              newcommandfork[6]%
              begintikzcd[ampersand replacement=&]
              #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
              arrow[r,shift right, "#5"'] & #6
              endtikzcd%



              The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.



              Use it in a display environment, say



              [
              forkKkAf0B
              ]


              Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



              documentclassarticle
              usepackageamsmath
              usepackagetikz-cd
              usepackagexparse

              ExplSyntaxOn

              keys_define:nn soap/forks

              s .tl_set:N = l__soap_fork_source_tl,
              t .tl_set:N = l__soap_fork_target_tl,
              e .tl_set:N = l__soap_fork_end_tl,
              u .tl_set:N = l__soap_fork_up_tl,
              d .tl_set:N = l__soap_fork_down_tl,
              c .tl_set:N = l__soap_fork_center_tl,
              * .bool_set:N = l__soap_fork_co_bool,
              * .default:n = true,


              NewDocumentCommandforkm

              keys_set:nn soap/forks #1
              begintikzcd[ampersand~replacement=&]
              bool_if:NF l__soap_fork_co_bool
              % false, equalizer
              l__soap_fork_end_tl
              arrow[r,"l__soap_fork_center_tl"] &

              l__soap_fork_source_tl
              arrow[r,shift~left,"l__soap_fork_up_tl"]
              arrow[r,shift~right,"l__soap_fork_down_tl",swap] &
              l__soap_fork_target_tl
              bool_if:NT l__soap_fork_co_bool
              % true, coequalizer
              arrow[r,"l__soap_fork_center_tl"] &
              l__soap_fork_end_tl

              endtikzcd


              ExplSyntaxOff

              begindocument

              begingather
              forks=A,t=B,e=K,u=f,d=0,c=k
              \
              fork*,s=A,t=B,e=K,u=f,d=0,c=k
              endgather

              enddocument


              enter image description here






              share|improve this answer
























                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                You don't really want to use the center environment, but the main problem is the &:



                newcommandfork[6]%
                begintikzcd[ampersand replacement=&]
                #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
                arrow[r,shift right, "#5"'] & #6
                endtikzcd%



                The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.



                Use it in a display environment, say



                [
                forkKkAf0B
                ]


                Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



                documentclassarticle
                usepackageamsmath
                usepackagetikz-cd
                usepackagexparse

                ExplSyntaxOn

                keys_define:nn soap/forks

                s .tl_set:N = l__soap_fork_source_tl,
                t .tl_set:N = l__soap_fork_target_tl,
                e .tl_set:N = l__soap_fork_end_tl,
                u .tl_set:N = l__soap_fork_up_tl,
                d .tl_set:N = l__soap_fork_down_tl,
                c .tl_set:N = l__soap_fork_center_tl,
                * .bool_set:N = l__soap_fork_co_bool,
                * .default:n = true,


                NewDocumentCommandforkm

                keys_set:nn soap/forks #1
                begintikzcd[ampersand~replacement=&]
                bool_if:NF l__soap_fork_co_bool
                % false, equalizer
                l__soap_fork_end_tl
                arrow[r,"l__soap_fork_center_tl"] &

                l__soap_fork_source_tl
                arrow[r,shift~left,"l__soap_fork_up_tl"]
                arrow[r,shift~right,"l__soap_fork_down_tl",swap] &
                l__soap_fork_target_tl
                bool_if:NT l__soap_fork_co_bool
                % true, coequalizer
                arrow[r,"l__soap_fork_center_tl"] &
                l__soap_fork_end_tl

                endtikzcd


                ExplSyntaxOff

                begindocument

                begingather
                forks=A,t=B,e=K,u=f,d=0,c=k
                \
                fork*,s=A,t=B,e=K,u=f,d=0,c=k
                endgather

                enddocument


                enter image description here






                share|improve this answer














                You don't really want to use the center environment, but the main problem is the &:



                newcommandfork[6]%
                begintikzcd[ampersand replacement=&]
                #1 arrow[r, "#2"] & #3 arrow[r,shift left, "#4"]
                arrow[r,shift right, "#5"'] & #6
                endtikzcd%



                The key ampersand replacement is necessary each time a TikZ matrix (such as a tikzcd diagram) is used in the argument to another command.



                Use it in a display environment, say



                [
                forkKkAf0B
                ]


                Here's another suggestion for coping with both equalizer and coequalizer diagrams. Each item in the diagram is defined with a key-value approach (use different keys, if you like); a * tells to draw a coequalizer diagram. Like in most key-value approaches, the order of the keys is irrelevant.



                documentclassarticle
                usepackageamsmath
                usepackagetikz-cd
                usepackagexparse

                ExplSyntaxOn

                keys_define:nn soap/forks

                s .tl_set:N = l__soap_fork_source_tl,
                t .tl_set:N = l__soap_fork_target_tl,
                e .tl_set:N = l__soap_fork_end_tl,
                u .tl_set:N = l__soap_fork_up_tl,
                d .tl_set:N = l__soap_fork_down_tl,
                c .tl_set:N = l__soap_fork_center_tl,
                * .bool_set:N = l__soap_fork_co_bool,
                * .default:n = true,


                NewDocumentCommandforkm

                keys_set:nn soap/forks #1
                begintikzcd[ampersand~replacement=&]
                bool_if:NF l__soap_fork_co_bool
                % false, equalizer
                l__soap_fork_end_tl
                arrow[r,"l__soap_fork_center_tl"] &

                l__soap_fork_source_tl
                arrow[r,shift~left,"l__soap_fork_up_tl"]
                arrow[r,shift~right,"l__soap_fork_down_tl",swap] &
                l__soap_fork_target_tl
                bool_if:NT l__soap_fork_co_bool
                % true, coequalizer
                arrow[r,"l__soap_fork_center_tl"] &
                l__soap_fork_end_tl

                endtikzcd


                ExplSyntaxOff

                begindocument

                begingather
                forks=A,t=B,e=K,u=f,d=0,c=k
                \
                fork*,s=A,t=B,e=K,u=f,d=0,c=k
                endgather

                enddocument


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 23 at 21:49

























                answered Nov 23 at 15:21









                egreg

                701k8618673141




                701k8618673141



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f461427%2fa-simple-macro-with-tikzcd-fork-diagrams%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

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?