How to create two commands with the same name but different number of parameters












6















I want to define a command with the same name, but a different number of parameters.



I'm considering something like this:



documentclass{article}

usepackage{hyperref}

newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
newcommand{quelle}[2]{textit{(Quelle: url{#1} Absatz: #2)})}

begin{document}

Test: quelle{www.wikipedia.de}
Test: quelle{www.wikipedia.de, sometext}


end{document}


If I try to compile this, I get the following result:



Command quelle already defined. ...2]{textit{(Quelle: url{#1} Absatz: #2)})}


Thank you for your help!










share|improve this question

























  • Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

    – Christian Hupfer
    12 hours ago
















6















I want to define a command with the same name, but a different number of parameters.



I'm considering something like this:



documentclass{article}

usepackage{hyperref}

newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
newcommand{quelle}[2]{textit{(Quelle: url{#1} Absatz: #2)})}

begin{document}

Test: quelle{www.wikipedia.de}
Test: quelle{www.wikipedia.de, sometext}


end{document}


If I try to compile this, I get the following result:



Command quelle already defined. ...2]{textit{(Quelle: url{#1} Absatz: #2)})}


Thank you for your help!










share|improve this question

























  • Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

    – Christian Hupfer
    12 hours ago














6












6








6


1






I want to define a command with the same name, but a different number of parameters.



I'm considering something like this:



documentclass{article}

usepackage{hyperref}

newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
newcommand{quelle}[2]{textit{(Quelle: url{#1} Absatz: #2)})}

begin{document}

Test: quelle{www.wikipedia.de}
Test: quelle{www.wikipedia.de, sometext}


end{document}


If I try to compile this, I get the following result:



Command quelle already defined. ...2]{textit{(Quelle: url{#1} Absatz: #2)})}


Thank you for your help!










share|improve this question
















I want to define a command with the same name, but a different number of parameters.



I'm considering something like this:



documentclass{article}

usepackage{hyperref}

newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
newcommand{quelle}[2]{textit{(Quelle: url{#1} Absatz: #2)})}

begin{document}

Test: quelle{www.wikipedia.de}
Test: quelle{www.wikipedia.de, sometext}


end{document}


If I try to compile this, I get the following result:



Command quelle already defined. ...2]{textit{(Quelle: url{#1} Absatz: #2)})}


Thank you for your help!







macros






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 mins ago









Agi Hammerthief

1033




1033










asked 12 hours ago









mrbelamrbela

4681312




4681312













  • Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

    – Christian Hupfer
    12 hours ago



















  • Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

    – Christian Hupfer
    12 hours ago

















Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

– Christian Hupfer
12 hours ago





Traditional LaTeX does not allow macros with the same name having a different mandatory number of arguments. You can always define a macro having a certain number of arguments, but you have to check whether they are empty (i.e. not specified). With expl3 you could use cs_new:Nn foo_bar:nn` or cs_new:Nn foo_bar:nnnn for example, but those macros are not meant for user space

– Christian Hupfer
12 hours ago










4 Answers
4






active

oldest

votes


















3














The only change from the requested syntax is to use a ! as the separator between the http reference and "sometext", as I figured a comma , was much more likely to appear as part of "sometext:.



documentclass{article}
usepackage{hyperref,listofitems}
newcommand{quelle}[1]{%
setsepchar{!}%
readlistqarg{#1}%
(textit{Quelle: url{qarg[1]}}%
ifnumlistlenqarg>1relaxtextit{ Absatz: qarg[2]}fi%
)%
}
begin{document}
Test: quelle{www.wikipedia.de}
Test: quelle{www.wikipedia.de! sometext}
end{document}


enter image description here






share|improve this answer

































    2














    enter image description here



    I suggest an optional argument at the end, for example, with xparse and NewDocumentCommand.



    If the optional argument is not given, quelle works like the intended one-argument version, if it is given Absatz #2 is printed in addition.



    The check, whether it has been specified can be done with IfValueT{#2}{}.



    documentclass{article}

    usepackage{xparse}
    usepackage{hyperref}

    %newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
    NewDocumentCommand{quelle}{m+o}{textit{(Quelle: url{#1}IfValueT{#2}{Absatz: #2)}}}

    begin{document}

    Test: quelle{www.wikipedia.de}

    Test: quelle{www.wikipedia.de}[sometext]


    end{document}





    share|improve this answer































      2














      I'd prefer a syntax with a leading optional argument, that's more in line with common LaTeX conventions.



      Anyway, you can have your preferred syntax by defining a single quelle command: TeX cannot have two meanings for the same command.



      documentclass{article}
      usepackage{xparse}
      usepackage{hyperref}

      NewDocumentCommand{quelle}{ >{SplitArgument{1}{,}}m }{%
      makequelle#1%
      }
      NewDocumentCommand{makequelle}{mm}{%
      textit{%
      (Quelle: url{#1}%
      IfValueT{#2}{ Absatz: #2})%
      }%
      }

      begin{document}

      Test: quelle{www.wikipedia.de}

      Test: quelle{www.wikipedia.de, sometext}

      end{document}


      The argument is split at the first comma, if present, and passed as a pair of arguments to makequelle. If no comma is present, the second argument will make the test IfValueT false, so nothing will be printed.



      enter image description here



      The same output with a more common syntax:



      documentclass{article}
      usepackage{xparse}
      usepackage{hyperref}

      NewDocumentCommand{quelle}{om}{%
      textit{%
      (Quelle: url{#2}%
      IfValueT{#1}{ Absatz: #1})%
      }%
      }

      begin{document}

      Test: quelle{www.wikipedia.de}

      Test: quelle[sometext]{www.wikipedia.de}

      end{document}





      share|improve this answer































        1














        The following code delivers what you're after using the following setup:




        1. Use quelleattributes{<list>} to define the prefixes/attribute names in a comma-separate <list> you'll be supplying (Quelle, Absatz, ...).


        2. Using etoolbox, we process the list sequentially, setting the attribute name, followed by the attribute. A text-comparison is done with each attribute name to see whether it matches Quelle. Only those are set using url, while the others are set as-is.



        enter image description here



        documentclass{article}

        usepackage{etoolbox}
        usepackage{hyperref}

        newcounter{quellecnt}
        makeatletter
        newcommand{quelleattributes}[1]{%
        setcounter{quellecnt}{0}% Restart counter
        renewcommand*{do}[1]{% How to update each item
        stepcounter{quellecnt}% Step counter
        @namedef{quelle@thequellecnt}{##1}% Define quelle@<num> to attribute
        }%
        docsvlist{#1}% Process list
        }

        newcommand{quelle}[1]{%
        setcounter{quellecnt}{0}% Restart counter
        renewcommand*{do}[1]{%
        stepcounter{quellecnt}% Step counter
        letquelleformatrelax% Default formatting of attribute
        ifnumpdfstrcmp{@nameuse{quelle@thequellecnt}}{Quelle}=0
        defquelleformat{url}% Attribute should be a url
        fi
        @nameuse{quelle@thequellecnt}: quelleformat{##1} % Set attribute
        }
        (textit{%
        docsvlist{#1}unskip% Process list
        })%
        }

        makeatother

        begin{document}

        quelleattributes{%
        Quelle,
        Absatz%
        }

        Test: quelle{www.wikipedia.de}

        Test: quelle{www.wikipedia.de, sometext}

        end{document}





        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',
          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%2f472779%2fhow-to-create-two-commands-with-the-same-name-but-different-number-of-parameters%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          The only change from the requested syntax is to use a ! as the separator between the http reference and "sometext", as I figured a comma , was much more likely to appear as part of "sometext:.



          documentclass{article}
          usepackage{hyperref,listofitems}
          newcommand{quelle}[1]{%
          setsepchar{!}%
          readlistqarg{#1}%
          (textit{Quelle: url{qarg[1]}}%
          ifnumlistlenqarg>1relaxtextit{ Absatz: qarg[2]}fi%
          )%
          }
          begin{document}
          Test: quelle{www.wikipedia.de}
          Test: quelle{www.wikipedia.de! sometext}
          end{document}


          enter image description here






          share|improve this answer






























            3














            The only change from the requested syntax is to use a ! as the separator between the http reference and "sometext", as I figured a comma , was much more likely to appear as part of "sometext:.



            documentclass{article}
            usepackage{hyperref,listofitems}
            newcommand{quelle}[1]{%
            setsepchar{!}%
            readlistqarg{#1}%
            (textit{Quelle: url{qarg[1]}}%
            ifnumlistlenqarg>1relaxtextit{ Absatz: qarg[2]}fi%
            )%
            }
            begin{document}
            Test: quelle{www.wikipedia.de}
            Test: quelle{www.wikipedia.de! sometext}
            end{document}


            enter image description here






            share|improve this answer




























              3












              3








              3







              The only change from the requested syntax is to use a ! as the separator between the http reference and "sometext", as I figured a comma , was much more likely to appear as part of "sometext:.



              documentclass{article}
              usepackage{hyperref,listofitems}
              newcommand{quelle}[1]{%
              setsepchar{!}%
              readlistqarg{#1}%
              (textit{Quelle: url{qarg[1]}}%
              ifnumlistlenqarg>1relaxtextit{ Absatz: qarg[2]}fi%
              )%
              }
              begin{document}
              Test: quelle{www.wikipedia.de}
              Test: quelle{www.wikipedia.de! sometext}
              end{document}


              enter image description here






              share|improve this answer















              The only change from the requested syntax is to use a ! as the separator between the http reference and "sometext", as I figured a comma , was much more likely to appear as part of "sometext:.



              documentclass{article}
              usepackage{hyperref,listofitems}
              newcommand{quelle}[1]{%
              setsepchar{!}%
              readlistqarg{#1}%
              (textit{Quelle: url{qarg[1]}}%
              ifnumlistlenqarg>1relaxtextit{ Absatz: qarg[2]}fi%
              )%
              }
              begin{document}
              Test: quelle{www.wikipedia.de}
              Test: quelle{www.wikipedia.de! sometext}
              end{document}


              enter image description here







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 11 hours ago

























              answered 12 hours ago









              Steven B. SegletesSteven B. Segletes

              153k9194402




              153k9194402























                  2














                  enter image description here



                  I suggest an optional argument at the end, for example, with xparse and NewDocumentCommand.



                  If the optional argument is not given, quelle works like the intended one-argument version, if it is given Absatz #2 is printed in addition.



                  The check, whether it has been specified can be done with IfValueT{#2}{}.



                  documentclass{article}

                  usepackage{xparse}
                  usepackage{hyperref}

                  %newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
                  NewDocumentCommand{quelle}{m+o}{textit{(Quelle: url{#1}IfValueT{#2}{Absatz: #2)}}}

                  begin{document}

                  Test: quelle{www.wikipedia.de}

                  Test: quelle{www.wikipedia.de}[sometext]


                  end{document}





                  share|improve this answer




























                    2














                    enter image description here



                    I suggest an optional argument at the end, for example, with xparse and NewDocumentCommand.



                    If the optional argument is not given, quelle works like the intended one-argument version, if it is given Absatz #2 is printed in addition.



                    The check, whether it has been specified can be done with IfValueT{#2}{}.



                    documentclass{article}

                    usepackage{xparse}
                    usepackage{hyperref}

                    %newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
                    NewDocumentCommand{quelle}{m+o}{textit{(Quelle: url{#1}IfValueT{#2}{Absatz: #2)}}}

                    begin{document}

                    Test: quelle{www.wikipedia.de}

                    Test: quelle{www.wikipedia.de}[sometext]


                    end{document}





                    share|improve this answer


























                      2












                      2








                      2







                      enter image description here



                      I suggest an optional argument at the end, for example, with xparse and NewDocumentCommand.



                      If the optional argument is not given, quelle works like the intended one-argument version, if it is given Absatz #2 is printed in addition.



                      The check, whether it has been specified can be done with IfValueT{#2}{}.



                      documentclass{article}

                      usepackage{xparse}
                      usepackage{hyperref}

                      %newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
                      NewDocumentCommand{quelle}{m+o}{textit{(Quelle: url{#1}IfValueT{#2}{Absatz: #2)}}}

                      begin{document}

                      Test: quelle{www.wikipedia.de}

                      Test: quelle{www.wikipedia.de}[sometext]


                      end{document}





                      share|improve this answer













                      enter image description here



                      I suggest an optional argument at the end, for example, with xparse and NewDocumentCommand.



                      If the optional argument is not given, quelle works like the intended one-argument version, if it is given Absatz #2 is printed in addition.



                      The check, whether it has been specified can be done with IfValueT{#2}{}.



                      documentclass{article}

                      usepackage{xparse}
                      usepackage{hyperref}

                      %newcommand{quelle}[1]{textit{(Quelle: url{#1})})}
                      NewDocumentCommand{quelle}{m+o}{textit{(Quelle: url{#1}IfValueT{#2}{Absatz: #2)}}}

                      begin{document}

                      Test: quelle{www.wikipedia.de}

                      Test: quelle{www.wikipedia.de}[sometext]


                      end{document}






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 12 hours ago









                      Christian HupferChristian Hupfer

                      149k14197392




                      149k14197392























                          2














                          I'd prefer a syntax with a leading optional argument, that's more in line with common LaTeX conventions.



                          Anyway, you can have your preferred syntax by defining a single quelle command: TeX cannot have two meanings for the same command.



                          documentclass{article}
                          usepackage{xparse}
                          usepackage{hyperref}

                          NewDocumentCommand{quelle}{ >{SplitArgument{1}{,}}m }{%
                          makequelle#1%
                          }
                          NewDocumentCommand{makequelle}{mm}{%
                          textit{%
                          (Quelle: url{#1}%
                          IfValueT{#2}{ Absatz: #2})%
                          }%
                          }

                          begin{document}

                          Test: quelle{www.wikipedia.de}

                          Test: quelle{www.wikipedia.de, sometext}

                          end{document}


                          The argument is split at the first comma, if present, and passed as a pair of arguments to makequelle. If no comma is present, the second argument will make the test IfValueT false, so nothing will be printed.



                          enter image description here



                          The same output with a more common syntax:



                          documentclass{article}
                          usepackage{xparse}
                          usepackage{hyperref}

                          NewDocumentCommand{quelle}{om}{%
                          textit{%
                          (Quelle: url{#2}%
                          IfValueT{#1}{ Absatz: #1})%
                          }%
                          }

                          begin{document}

                          Test: quelle{www.wikipedia.de}

                          Test: quelle[sometext]{www.wikipedia.de}

                          end{document}





                          share|improve this answer




























                            2














                            I'd prefer a syntax with a leading optional argument, that's more in line with common LaTeX conventions.



                            Anyway, you can have your preferred syntax by defining a single quelle command: TeX cannot have two meanings for the same command.



                            documentclass{article}
                            usepackage{xparse}
                            usepackage{hyperref}

                            NewDocumentCommand{quelle}{ >{SplitArgument{1}{,}}m }{%
                            makequelle#1%
                            }
                            NewDocumentCommand{makequelle}{mm}{%
                            textit{%
                            (Quelle: url{#1}%
                            IfValueT{#2}{ Absatz: #2})%
                            }%
                            }

                            begin{document}

                            Test: quelle{www.wikipedia.de}

                            Test: quelle{www.wikipedia.de, sometext}

                            end{document}


                            The argument is split at the first comma, if present, and passed as a pair of arguments to makequelle. If no comma is present, the second argument will make the test IfValueT false, so nothing will be printed.



                            enter image description here



                            The same output with a more common syntax:



                            documentclass{article}
                            usepackage{xparse}
                            usepackage{hyperref}

                            NewDocumentCommand{quelle}{om}{%
                            textit{%
                            (Quelle: url{#2}%
                            IfValueT{#1}{ Absatz: #1})%
                            }%
                            }

                            begin{document}

                            Test: quelle{www.wikipedia.de}

                            Test: quelle[sometext]{www.wikipedia.de}

                            end{document}





                            share|improve this answer


























                              2












                              2








                              2







                              I'd prefer a syntax with a leading optional argument, that's more in line with common LaTeX conventions.



                              Anyway, you can have your preferred syntax by defining a single quelle command: TeX cannot have two meanings for the same command.



                              documentclass{article}
                              usepackage{xparse}
                              usepackage{hyperref}

                              NewDocumentCommand{quelle}{ >{SplitArgument{1}{,}}m }{%
                              makequelle#1%
                              }
                              NewDocumentCommand{makequelle}{mm}{%
                              textit{%
                              (Quelle: url{#1}%
                              IfValueT{#2}{ Absatz: #2})%
                              }%
                              }

                              begin{document}

                              Test: quelle{www.wikipedia.de}

                              Test: quelle{www.wikipedia.de, sometext}

                              end{document}


                              The argument is split at the first comma, if present, and passed as a pair of arguments to makequelle. If no comma is present, the second argument will make the test IfValueT false, so nothing will be printed.



                              enter image description here



                              The same output with a more common syntax:



                              documentclass{article}
                              usepackage{xparse}
                              usepackage{hyperref}

                              NewDocumentCommand{quelle}{om}{%
                              textit{%
                              (Quelle: url{#2}%
                              IfValueT{#1}{ Absatz: #1})%
                              }%
                              }

                              begin{document}

                              Test: quelle{www.wikipedia.de}

                              Test: quelle[sometext]{www.wikipedia.de}

                              end{document}





                              share|improve this answer













                              I'd prefer a syntax with a leading optional argument, that's more in line with common LaTeX conventions.



                              Anyway, you can have your preferred syntax by defining a single quelle command: TeX cannot have two meanings for the same command.



                              documentclass{article}
                              usepackage{xparse}
                              usepackage{hyperref}

                              NewDocumentCommand{quelle}{ >{SplitArgument{1}{,}}m }{%
                              makequelle#1%
                              }
                              NewDocumentCommand{makequelle}{mm}{%
                              textit{%
                              (Quelle: url{#1}%
                              IfValueT{#2}{ Absatz: #2})%
                              }%
                              }

                              begin{document}

                              Test: quelle{www.wikipedia.de}

                              Test: quelle{www.wikipedia.de, sometext}

                              end{document}


                              The argument is split at the first comma, if present, and passed as a pair of arguments to makequelle. If no comma is present, the second argument will make the test IfValueT false, so nothing will be printed.



                              enter image description here



                              The same output with a more common syntax:



                              documentclass{article}
                              usepackage{xparse}
                              usepackage{hyperref}

                              NewDocumentCommand{quelle}{om}{%
                              textit{%
                              (Quelle: url{#2}%
                              IfValueT{#1}{ Absatz: #1})%
                              }%
                              }

                              begin{document}

                              Test: quelle{www.wikipedia.de}

                              Test: quelle[sometext]{www.wikipedia.de}

                              end{document}






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 11 hours ago









                              egregegreg

                              716k8619023191




                              716k8619023191























                                  1














                                  The following code delivers what you're after using the following setup:




                                  1. Use quelleattributes{<list>} to define the prefixes/attribute names in a comma-separate <list> you'll be supplying (Quelle, Absatz, ...).


                                  2. Using etoolbox, we process the list sequentially, setting the attribute name, followed by the attribute. A text-comparison is done with each attribute name to see whether it matches Quelle. Only those are set using url, while the others are set as-is.



                                  enter image description here



                                  documentclass{article}

                                  usepackage{etoolbox}
                                  usepackage{hyperref}

                                  newcounter{quellecnt}
                                  makeatletter
                                  newcommand{quelleattributes}[1]{%
                                  setcounter{quellecnt}{0}% Restart counter
                                  renewcommand*{do}[1]{% How to update each item
                                  stepcounter{quellecnt}% Step counter
                                  @namedef{quelle@thequellecnt}{##1}% Define quelle@<num> to attribute
                                  }%
                                  docsvlist{#1}% Process list
                                  }

                                  newcommand{quelle}[1]{%
                                  setcounter{quellecnt}{0}% Restart counter
                                  renewcommand*{do}[1]{%
                                  stepcounter{quellecnt}% Step counter
                                  letquelleformatrelax% Default formatting of attribute
                                  ifnumpdfstrcmp{@nameuse{quelle@thequellecnt}}{Quelle}=0
                                  defquelleformat{url}% Attribute should be a url
                                  fi
                                  @nameuse{quelle@thequellecnt}: quelleformat{##1} % Set attribute
                                  }
                                  (textit{%
                                  docsvlist{#1}unskip% Process list
                                  })%
                                  }

                                  makeatother

                                  begin{document}

                                  quelleattributes{%
                                  Quelle,
                                  Absatz%
                                  }

                                  Test: quelle{www.wikipedia.de}

                                  Test: quelle{www.wikipedia.de, sometext}

                                  end{document}





                                  share|improve this answer




























                                    1














                                    The following code delivers what you're after using the following setup:




                                    1. Use quelleattributes{<list>} to define the prefixes/attribute names in a comma-separate <list> you'll be supplying (Quelle, Absatz, ...).


                                    2. Using etoolbox, we process the list sequentially, setting the attribute name, followed by the attribute. A text-comparison is done with each attribute name to see whether it matches Quelle. Only those are set using url, while the others are set as-is.



                                    enter image description here



                                    documentclass{article}

                                    usepackage{etoolbox}
                                    usepackage{hyperref}

                                    newcounter{quellecnt}
                                    makeatletter
                                    newcommand{quelleattributes}[1]{%
                                    setcounter{quellecnt}{0}% Restart counter
                                    renewcommand*{do}[1]{% How to update each item
                                    stepcounter{quellecnt}% Step counter
                                    @namedef{quelle@thequellecnt}{##1}% Define quelle@<num> to attribute
                                    }%
                                    docsvlist{#1}% Process list
                                    }

                                    newcommand{quelle}[1]{%
                                    setcounter{quellecnt}{0}% Restart counter
                                    renewcommand*{do}[1]{%
                                    stepcounter{quellecnt}% Step counter
                                    letquelleformatrelax% Default formatting of attribute
                                    ifnumpdfstrcmp{@nameuse{quelle@thequellecnt}}{Quelle}=0
                                    defquelleformat{url}% Attribute should be a url
                                    fi
                                    @nameuse{quelle@thequellecnt}: quelleformat{##1} % Set attribute
                                    }
                                    (textit{%
                                    docsvlist{#1}unskip% Process list
                                    })%
                                    }

                                    makeatother

                                    begin{document}

                                    quelleattributes{%
                                    Quelle,
                                    Absatz%
                                    }

                                    Test: quelle{www.wikipedia.de}

                                    Test: quelle{www.wikipedia.de, sometext}

                                    end{document}





                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      The following code delivers what you're after using the following setup:




                                      1. Use quelleattributes{<list>} to define the prefixes/attribute names in a comma-separate <list> you'll be supplying (Quelle, Absatz, ...).


                                      2. Using etoolbox, we process the list sequentially, setting the attribute name, followed by the attribute. A text-comparison is done with each attribute name to see whether it matches Quelle. Only those are set using url, while the others are set as-is.



                                      enter image description here



                                      documentclass{article}

                                      usepackage{etoolbox}
                                      usepackage{hyperref}

                                      newcounter{quellecnt}
                                      makeatletter
                                      newcommand{quelleattributes}[1]{%
                                      setcounter{quellecnt}{0}% Restart counter
                                      renewcommand*{do}[1]{% How to update each item
                                      stepcounter{quellecnt}% Step counter
                                      @namedef{quelle@thequellecnt}{##1}% Define quelle@<num> to attribute
                                      }%
                                      docsvlist{#1}% Process list
                                      }

                                      newcommand{quelle}[1]{%
                                      setcounter{quellecnt}{0}% Restart counter
                                      renewcommand*{do}[1]{%
                                      stepcounter{quellecnt}% Step counter
                                      letquelleformatrelax% Default formatting of attribute
                                      ifnumpdfstrcmp{@nameuse{quelle@thequellecnt}}{Quelle}=0
                                      defquelleformat{url}% Attribute should be a url
                                      fi
                                      @nameuse{quelle@thequellecnt}: quelleformat{##1} % Set attribute
                                      }
                                      (textit{%
                                      docsvlist{#1}unskip% Process list
                                      })%
                                      }

                                      makeatother

                                      begin{document}

                                      quelleattributes{%
                                      Quelle,
                                      Absatz%
                                      }

                                      Test: quelle{www.wikipedia.de}

                                      Test: quelle{www.wikipedia.de, sometext}

                                      end{document}





                                      share|improve this answer













                                      The following code delivers what you're after using the following setup:




                                      1. Use quelleattributes{<list>} to define the prefixes/attribute names in a comma-separate <list> you'll be supplying (Quelle, Absatz, ...).


                                      2. Using etoolbox, we process the list sequentially, setting the attribute name, followed by the attribute. A text-comparison is done with each attribute name to see whether it matches Quelle. Only those are set using url, while the others are set as-is.



                                      enter image description here



                                      documentclass{article}

                                      usepackage{etoolbox}
                                      usepackage{hyperref}

                                      newcounter{quellecnt}
                                      makeatletter
                                      newcommand{quelleattributes}[1]{%
                                      setcounter{quellecnt}{0}% Restart counter
                                      renewcommand*{do}[1]{% How to update each item
                                      stepcounter{quellecnt}% Step counter
                                      @namedef{quelle@thequellecnt}{##1}% Define quelle@<num> to attribute
                                      }%
                                      docsvlist{#1}% Process list
                                      }

                                      newcommand{quelle}[1]{%
                                      setcounter{quellecnt}{0}% Restart counter
                                      renewcommand*{do}[1]{%
                                      stepcounter{quellecnt}% Step counter
                                      letquelleformatrelax% Default formatting of attribute
                                      ifnumpdfstrcmp{@nameuse{quelle@thequellecnt}}{Quelle}=0
                                      defquelleformat{url}% Attribute should be a url
                                      fi
                                      @nameuse{quelle@thequellecnt}: quelleformat{##1} % Set attribute
                                      }
                                      (textit{%
                                      docsvlist{#1}unskip% Process list
                                      })%
                                      }

                                      makeatother

                                      begin{document}

                                      quelleattributes{%
                                      Quelle,
                                      Absatz%
                                      }

                                      Test: quelle{www.wikipedia.de}

                                      Test: quelle{www.wikipedia.de, sometext}

                                      end{document}






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 12 hours ago









                                      WernerWerner

                                      442k679741670




                                      442k679741670






























                                          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%2f472779%2fhow-to-create-two-commands-with-the-same-name-but-different-number-of-parameters%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

                                          Contact image not getting when fetch all contact list from iPhone by CNContact

                                          count number of partitions of a set with n elements into k subsets

                                          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks