About the definition of textcolor












12















I was curious and found the following definition for the macro textcolor defined in the package xcolor:



deftextcolor#1#{@textcolor{#1}}
def@textcolor#1#2#3{protectleavevmode{color#1{#2}#3}}


However, I use the macro with only two arguments and not three arguments:



textcolor{blue}{foo}


What I don't understand for this definition is:




  1. What is the meaning of the syntax textcolor#1#?

  2. What will be the third argument the macro @textcolor will get in the example above?










share|improve this question



























    12















    I was curious and found the following definition for the macro textcolor defined in the package xcolor:



    deftextcolor#1#{@textcolor{#1}}
    def@textcolor#1#2#3{protectleavevmode{color#1{#2}#3}}


    However, I use the macro with only two arguments and not three arguments:



    textcolor{blue}{foo}


    What I don't understand for this definition is:




    1. What is the meaning of the syntax textcolor#1#?

    2. What will be the third argument the macro @textcolor will get in the example above?










    share|improve this question

























      12












      12








      12








      I was curious and found the following definition for the macro textcolor defined in the package xcolor:



      deftextcolor#1#{@textcolor{#1}}
      def@textcolor#1#2#3{protectleavevmode{color#1{#2}#3}}


      However, I use the macro with only two arguments and not three arguments:



      textcolor{blue}{foo}


      What I don't understand for this definition is:




      1. What is the meaning of the syntax textcolor#1#?

      2. What will be the third argument the macro @textcolor will get in the example above?










      share|improve this question














      I was curious and found the following definition for the macro textcolor defined in the package xcolor:



      deftextcolor#1#{@textcolor{#1}}
      def@textcolor#1#2#3{protectleavevmode{color#1{#2}#3}}


      However, I use the macro with only two arguments and not three arguments:



      textcolor{blue}{foo}


      What I don't understand for this definition is:




      1. What is the meaning of the syntax textcolor#1#?

      2. What will be the third argument the macro @textcolor will get in the example above?







      color arguments texdef






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 14 at 15:26









      SaroupilleSaroupille

      297210




      297210






















          1 Answer
          1






          active

          oldest

          votes


















          14














          This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes by shortcutting the definition was worth it.



          If you go



          deffoo#1#{zzz #1 zzz}


          then #1 is everything from foo to the first brace, so



          foo one two three {zzz}


          then #1 would be one two three



          Using this allows textcolor to grab any optional arguments without actually parsing for them and then re-insert them so color sees them.



          so compare



          textcolor{blue}{foo}


          and



          textcolor[rgb]{0,0,1}{foo}


          in the first case #1 is empty so the expansion is



            @textcolor{}{blue}{foo}


          which is



            protectleavevmode{color{blue}foo}


          but in the second case #1 is [rgb] (including the brackets) so the first expansion is



          @textcolor{[rgb]}{0,0,1}{foo}


          which is



           protectleavevmode{color[rgb]{0,0,1}foo}


          so the [rgb] isn't really ever seen by textcolor as an optional argument, it is just grabbed and passed to color.






          share|improve this answer


























          • Thank you for your clear answer. Is the second sharp after #1 really necessary then?

            – Saroupille
            Feb 14 at 17:42








          • 1





            @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

            – TeXnician
            Feb 14 at 19:22













          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%2f474884%2fabout-the-definition-of-textcolor%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









          14














          This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes by shortcutting the definition was worth it.



          If you go



          deffoo#1#{zzz #1 zzz}


          then #1 is everything from foo to the first brace, so



          foo one two three {zzz}


          then #1 would be one two three



          Using this allows textcolor to grab any optional arguments without actually parsing for them and then re-insert them so color sees them.



          so compare



          textcolor{blue}{foo}


          and



          textcolor[rgb]{0,0,1}{foo}


          in the first case #1 is empty so the expansion is



            @textcolor{}{blue}{foo}


          which is



            protectleavevmode{color{blue}foo}


          but in the second case #1 is [rgb] (including the brackets) so the first expansion is



          @textcolor{[rgb]}{0,0,1}{foo}


          which is



           protectleavevmode{color[rgb]{0,0,1}foo}


          so the [rgb] isn't really ever seen by textcolor as an optional argument, it is just grabbed and passed to color.






          share|improve this answer


























          • Thank you for your clear answer. Is the second sharp after #1 really necessary then?

            – Saroupille
            Feb 14 at 17:42








          • 1





            @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

            – TeXnician
            Feb 14 at 19:22


















          14














          This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes by shortcutting the definition was worth it.



          If you go



          deffoo#1#{zzz #1 zzz}


          then #1 is everything from foo to the first brace, so



          foo one two three {zzz}


          then #1 would be one two three



          Using this allows textcolor to grab any optional arguments without actually parsing for them and then re-insert them so color sees them.



          so compare



          textcolor{blue}{foo}


          and



          textcolor[rgb]{0,0,1}{foo}


          in the first case #1 is empty so the expansion is



            @textcolor{}{blue}{foo}


          which is



            protectleavevmode{color{blue}foo}


          but in the second case #1 is [rgb] (including the brackets) so the first expansion is



          @textcolor{[rgb]}{0,0,1}{foo}


          which is



           protectleavevmode{color[rgb]{0,0,1}foo}


          so the [rgb] isn't really ever seen by textcolor as an optional argument, it is just grabbed and passed to color.






          share|improve this answer


























          • Thank you for your clear answer. Is the second sharp after #1 really necessary then?

            – Saroupille
            Feb 14 at 17:42








          • 1





            @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

            – TeXnician
            Feb 14 at 19:22
















          14












          14








          14







          This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes by shortcutting the definition was worth it.



          If you go



          deffoo#1#{zzz #1 zzz}


          then #1 is everything from foo to the first brace, so



          foo one two three {zzz}


          then #1 would be one two three



          Using this allows textcolor to grab any optional arguments without actually parsing for them and then re-insert them so color sees them.



          so compare



          textcolor{blue}{foo}


          and



          textcolor[rgb]{0,0,1}{foo}


          in the first case #1 is empty so the expansion is



            @textcolor{}{blue}{foo}


          which is



            protectleavevmode{color{blue}foo}


          but in the second case #1 is [rgb] (including the brackets) so the first expansion is



          @textcolor{[rgb]}{0,0,1}{foo}


          which is



           protectleavevmode{color[rgb]{0,0,1}foo}


          so the [rgb] isn't really ever seen by textcolor as an optional argument, it is just grabbed and passed to color.






          share|improve this answer















          This is primitive tex syntax that really shouldn't be used in a latex package. It's used here as in 1993 fitting this all into a 640K machine we were really short of space and saving a few dozen bytes by shortcutting the definition was worth it.



          If you go



          deffoo#1#{zzz #1 zzz}


          then #1 is everything from foo to the first brace, so



          foo one two three {zzz}


          then #1 would be one two three



          Using this allows textcolor to grab any optional arguments without actually parsing for them and then re-insert them so color sees them.



          so compare



          textcolor{blue}{foo}


          and



          textcolor[rgb]{0,0,1}{foo}


          in the first case #1 is empty so the expansion is



            @textcolor{}{blue}{foo}


          which is



            protectleavevmode{color{blue}foo}


          but in the second case #1 is [rgb] (including the brackets) so the first expansion is



          @textcolor{[rgb]}{0,0,1}{foo}


          which is



           protectleavevmode{color[rgb]{0,0,1}foo}


          so the [rgb] isn't really ever seen by textcolor as an optional argument, it is just grabbed and passed to color.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 14 at 17:10

























          answered Feb 14 at 16:55









          David CarlisleDavid Carlisle

          494k4111381885




          494k4111381885













          • Thank you for your clear answer. Is the second sharp after #1 really necessary then?

            – Saroupille
            Feb 14 at 17:42








          • 1





            @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

            – TeXnician
            Feb 14 at 19:22





















          • Thank you for your clear answer. Is the second sharp after #1 really necessary then?

            – Saroupille
            Feb 14 at 17:42








          • 1





            @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

            – TeXnician
            Feb 14 at 19:22



















          Thank you for your clear answer. Is the second sharp after #1 really necessary then?

          – Saroupille
          Feb 14 at 17:42







          Thank you for your clear answer. Is the second sharp after #1 really necessary then?

          – Saroupille
          Feb 14 at 17:42






          1




          1





          @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

          – TeXnician
          Feb 14 at 19:22







          @Saroupille Yes, otherwise it would only read the first token after textcolor which would be [ in the case of an optional argument.

          – TeXnician
          Feb 14 at 19:22




















          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%2f474884%2fabout-the-definition-of-textcolor%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

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix