How to use @ifnextchar to create a “table of references” macro?

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











up vote
2
down vote

favorite












At the bottom of every section in a big policy manual I need to include a table of references to a procedures manual like this:



begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
%fyi PM = Procedures Manual
PM refPM-tyinglaces & namerefPM-tyinglaces \
PM ref{PM-polishshoes & namerefPM-polishshoes \
PM refPM-ironshirt & namerefPM-ironshirt \
hline
endtabular
endtable


Of course since every table is formatted the same I'd really like a macro with syntax similar to:



%procedurelistfirstlabelnextlabel...nthlabel
%
procedurelistPM-tyinglacesPM-polishshoesPM-ironshirt


A single comma deliminated parameter would be okay too. My attempt is found below. I just can't get it to close the table, somehow it breaks when I include the closing hline.



makeatletter
newcommandprocedurelist[1]%
begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
PM ref#1 & nameref#1 \%
checknextarg

newcommandchecknextarg%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


newcommandconsumenextarg[1]%
PM ref#1 & nameref#1 \%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


makeatother


How do I achieve my goal?



What am I doing wrong in my macro?










share|improve this question





















  • The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
    – Skillmon
    32 mins ago














up vote
2
down vote

favorite












At the bottom of every section in a big policy manual I need to include a table of references to a procedures manual like this:



begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
%fyi PM = Procedures Manual
PM refPM-tyinglaces & namerefPM-tyinglaces \
PM ref{PM-polishshoes & namerefPM-polishshoes \
PM refPM-ironshirt & namerefPM-ironshirt \
hline
endtabular
endtable


Of course since every table is formatted the same I'd really like a macro with syntax similar to:



%procedurelistfirstlabelnextlabel...nthlabel
%
procedurelistPM-tyinglacesPM-polishshoesPM-ironshirt


A single comma deliminated parameter would be okay too. My attempt is found below. I just can't get it to close the table, somehow it breaks when I include the closing hline.



makeatletter
newcommandprocedurelist[1]%
begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
PM ref#1 & nameref#1 \%
checknextarg

newcommandchecknextarg%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


newcommandconsumenextarg[1]%
PM ref#1 & nameref#1 \%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


makeatother


How do I achieve my goal?



What am I doing wrong in my macro?










share|improve this question





















  • The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
    – Skillmon
    32 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











At the bottom of every section in a big policy manual I need to include a table of references to a procedures manual like this:



begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
%fyi PM = Procedures Manual
PM refPM-tyinglaces & namerefPM-tyinglaces \
PM ref{PM-polishshoes & namerefPM-polishshoes \
PM refPM-ironshirt & namerefPM-ironshirt \
hline
endtabular
endtable


Of course since every table is formatted the same I'd really like a macro with syntax similar to:



%procedurelistfirstlabelnextlabel...nthlabel
%
procedurelistPM-tyinglacesPM-polishshoesPM-ironshirt


A single comma deliminated parameter would be okay too. My attempt is found below. I just can't get it to close the table, somehow it breaks when I include the closing hline.



makeatletter
newcommandprocedurelist[1]%
begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
PM ref#1 & nameref#1 \%
checknextarg

newcommandchecknextarg%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


newcommandconsumenextarg[1]%
PM ref#1 & nameref#1 \%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


makeatother


How do I achieve my goal?



What am I doing wrong in my macro?










share|improve this question













At the bottom of every section in a big policy manual I need to include a table of references to a procedures manual like this:



begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
%fyi PM = Procedures Manual
PM refPM-tyinglaces & namerefPM-tyinglaces \
PM ref{PM-polishshoes & namerefPM-polishshoes \
PM refPM-ironshirt & namerefPM-ironshirt \
hline
endtabular
endtable


Of course since every table is formatted the same I'd really like a macro with syntax similar to:



%procedurelistfirstlabelnextlabel...nthlabel
%
procedurelistPM-tyinglacesPM-polishshoesPM-ironshirt


A single comma deliminated parameter would be okay too. My attempt is found below. I just can't get it to close the table, somehow it breaks when I include the closing hline.



makeatletter
newcommandprocedurelist[1]%
begintable[H]
begintabular
hline
multicolumn2Procedures \
hline
PM ref#1 & nameref#1 \%
checknextarg

newcommandchecknextarg%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


newcommandconsumenextarg[1]%
PM ref#1 & nameref#1 \%
@ifnextcharbgroup%
consumenextarg
%
hline %causes error?
endtabular
endtable


makeatother


How do I achieve my goal?



What am I doing wrong in my macro?







recursion






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 1 hour ago









KJC

603




603











  • The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
    – Skillmon
    32 mins ago
















  • The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
    – Skillmon
    32 mins ago















The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
– Skillmon
32 mins ago




The error of the hline is caused because you used checknextarg which isn't expandable as it uses @ifnextchar which is not expandable. Then you want to issue a noalign which is not the first token in that row.
– Skillmon
32 mins ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













The trick is to first grab all those arguments and store them somewhere (here in procedurelist@content). After you grabbed all arguments you can then output the formatted table. This way you don't have any unexpandable tests inside of the table blocking any noaligns.



Example code (I removed the namerefs and the surrounding table as that doesn't make sense if the only allowed placement is H and you don't use a caption):



documentclassarticle

makeatletter
newcommand*procedurelist@content
newcommand*procedurelist@checknext
%
@ifnextcharbgroup
procedurelist@eatnext
procedurelist@shipout%

newcommandprocedurelist[1]
%
begingroup
defprocedurelist@contentPM ref#1 & #1 \%
procedurelist@checknext

newcommandprocedurelist@eatnext[1]
%
edefprocedurelist@content
unexpandedexpandafterprocedurelist@content PM ref#1 & #1 \%
procedurelist@checknext

newcommand*procedurelist@shipout
%
begintabular
hline
multicolumn2Procedures \
hline
procedurelist@content
hline
endtabular%
endgroup

makeatother

begindocument
procedurelistarg1arg2arg3arg4
enddocument


enter image description here






share|improve this answer



























    up vote
    1
    down vote













    This is possible with expl3, which already has features for processing comma separated lists and cycling over them.



    documentclassarticle
    usepackagexparse
    usepackagehyperref

    ExplSyntaxOn

    NewDocumentCommandprocedurelistm

    seq_clear:N l__kjc_procedurelist_seq
    clist_map_inline:nn #1

    seq_put_right:Nn l__kjc_procedurelist_seq

    PM~ref##1 & nameref##1


    begintabular
    hline
    seq_use:Nn l__kjc_procedurelist_seq \ \
    hline
    endtabular


    seq_new:N l__kjc_procedurelist_seq

    ExplSyntaxOff

    begindocument

    sectionTie laceslabelPM-tyinglaces
    sectionPolish shoeslabelPM-polishshoes
    sectionIron shirtlabelPM-ironshirt

    sectionEnd

    procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

    enddocument


    enter image description here



    A better table:



    documentclassarticle
    usepackagexparse,booktabs
    usepackagehyperref

    ExplSyntaxOn

    NewDocumentCommandprocedurelistm

    seq_clear:N l__kjc_procedurelist_seq
    clist_map_inline:nn #1

    seq_put_right:Nn l__kjc_procedurelist_seq

    ref##1 & nameref##1


    begintabularcl
    toprule
    multicolumn1ctextbfPM & textbfName \
    midrule
    seq_use:Nn l__kjc_procedurelist_seq \ \
    bottomrule
    endtabular


    seq_new:N l__kjc_procedurelist_seq

    ExplSyntaxOff

    begindocument

    sectionTie laceslabelPM-tyinglaces
    sectionPolish shoeslabelPM-polishshoes
    sectionIron shirtlabelPM-ironshirt

    sectionEnd

    procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

    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: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      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%2f451423%2fhow-to-use-ifnextchar-to-create-a-table-of-references-macro%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      2
      down vote













      The trick is to first grab all those arguments and store them somewhere (here in procedurelist@content). After you grabbed all arguments you can then output the formatted table. This way you don't have any unexpandable tests inside of the table blocking any noaligns.



      Example code (I removed the namerefs and the surrounding table as that doesn't make sense if the only allowed placement is H and you don't use a caption):



      documentclassarticle

      makeatletter
      newcommand*procedurelist@content
      newcommand*procedurelist@checknext
      %
      @ifnextcharbgroup
      procedurelist@eatnext
      procedurelist@shipout%

      newcommandprocedurelist[1]
      %
      begingroup
      defprocedurelist@contentPM ref#1 & #1 \%
      procedurelist@checknext

      newcommandprocedurelist@eatnext[1]
      %
      edefprocedurelist@content
      unexpandedexpandafterprocedurelist@content PM ref#1 & #1 \%
      procedurelist@checknext

      newcommand*procedurelist@shipout
      %
      begintabular
      hline
      multicolumn2Procedures \
      hline
      procedurelist@content
      hline
      endtabular%
      endgroup

      makeatother

      begindocument
      procedurelistarg1arg2arg3arg4
      enddocument


      enter image description here






      share|improve this answer
























        up vote
        2
        down vote













        The trick is to first grab all those arguments and store them somewhere (here in procedurelist@content). After you grabbed all arguments you can then output the formatted table. This way you don't have any unexpandable tests inside of the table blocking any noaligns.



        Example code (I removed the namerefs and the surrounding table as that doesn't make sense if the only allowed placement is H and you don't use a caption):



        documentclassarticle

        makeatletter
        newcommand*procedurelist@content
        newcommand*procedurelist@checknext
        %
        @ifnextcharbgroup
        procedurelist@eatnext
        procedurelist@shipout%

        newcommandprocedurelist[1]
        %
        begingroup
        defprocedurelist@contentPM ref#1 & #1 \%
        procedurelist@checknext

        newcommandprocedurelist@eatnext[1]
        %
        edefprocedurelist@content
        unexpandedexpandafterprocedurelist@content PM ref#1 & #1 \%
        procedurelist@checknext

        newcommand*procedurelist@shipout
        %
        begintabular
        hline
        multicolumn2Procedures \
        hline
        procedurelist@content
        hline
        endtabular%
        endgroup

        makeatother

        begindocument
        procedurelistarg1arg2arg3arg4
        enddocument


        enter image description here






        share|improve this answer






















          up vote
          2
          down vote










          up vote
          2
          down vote









          The trick is to first grab all those arguments and store them somewhere (here in procedurelist@content). After you grabbed all arguments you can then output the formatted table. This way you don't have any unexpandable tests inside of the table blocking any noaligns.



          Example code (I removed the namerefs and the surrounding table as that doesn't make sense if the only allowed placement is H and you don't use a caption):



          documentclassarticle

          makeatletter
          newcommand*procedurelist@content
          newcommand*procedurelist@checknext
          %
          @ifnextcharbgroup
          procedurelist@eatnext
          procedurelist@shipout%

          newcommandprocedurelist[1]
          %
          begingroup
          defprocedurelist@contentPM ref#1 & #1 \%
          procedurelist@checknext

          newcommandprocedurelist@eatnext[1]
          %
          edefprocedurelist@content
          unexpandedexpandafterprocedurelist@content PM ref#1 & #1 \%
          procedurelist@checknext

          newcommand*procedurelist@shipout
          %
          begintabular
          hline
          multicolumn2Procedures \
          hline
          procedurelist@content
          hline
          endtabular%
          endgroup

          makeatother

          begindocument
          procedurelistarg1arg2arg3arg4
          enddocument


          enter image description here






          share|improve this answer












          The trick is to first grab all those arguments and store them somewhere (here in procedurelist@content). After you grabbed all arguments you can then output the formatted table. This way you don't have any unexpandable tests inside of the table blocking any noaligns.



          Example code (I removed the namerefs and the surrounding table as that doesn't make sense if the only allowed placement is H and you don't use a caption):



          documentclassarticle

          makeatletter
          newcommand*procedurelist@content
          newcommand*procedurelist@checknext
          %
          @ifnextcharbgroup
          procedurelist@eatnext
          procedurelist@shipout%

          newcommandprocedurelist[1]
          %
          begingroup
          defprocedurelist@contentPM ref#1 & #1 \%
          procedurelist@checknext

          newcommandprocedurelist@eatnext[1]
          %
          edefprocedurelist@content
          unexpandedexpandafterprocedurelist@content PM ref#1 & #1 \%
          procedurelist@checknext

          newcommand*procedurelist@shipout
          %
          begintabular
          hline
          multicolumn2Procedures \
          hline
          procedurelist@content
          hline
          endtabular%
          endgroup

          makeatother

          begindocument
          procedurelistarg1arg2arg3arg4
          enddocument


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 24 mins ago









          Skillmon

          17.7k11535




          17.7k11535




















              up vote
              1
              down vote













              This is possible with expl3, which already has features for processing comma separated lists and cycling over them.



              documentclassarticle
              usepackagexparse
              usepackagehyperref

              ExplSyntaxOn

              NewDocumentCommandprocedurelistm

              seq_clear:N l__kjc_procedurelist_seq
              clist_map_inline:nn #1

              seq_put_right:Nn l__kjc_procedurelist_seq

              PM~ref##1 & nameref##1


              begintabular
              hline
              seq_use:Nn l__kjc_procedurelist_seq \ \
              hline
              endtabular


              seq_new:N l__kjc_procedurelist_seq

              ExplSyntaxOff

              begindocument

              sectionTie laceslabelPM-tyinglaces
              sectionPolish shoeslabelPM-polishshoes
              sectionIron shirtlabelPM-ironshirt

              sectionEnd

              procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

              enddocument


              enter image description here



              A better table:



              documentclassarticle
              usepackagexparse,booktabs
              usepackagehyperref

              ExplSyntaxOn

              NewDocumentCommandprocedurelistm

              seq_clear:N l__kjc_procedurelist_seq
              clist_map_inline:nn #1

              seq_put_right:Nn l__kjc_procedurelist_seq

              ref##1 & nameref##1


              begintabularcl
              toprule
              multicolumn1ctextbfPM & textbfName \
              midrule
              seq_use:Nn l__kjc_procedurelist_seq \ \
              bottomrule
              endtabular


              seq_new:N l__kjc_procedurelist_seq

              ExplSyntaxOff

              begindocument

              sectionTie laceslabelPM-tyinglaces
              sectionPolish shoeslabelPM-polishshoes
              sectionIron shirtlabelPM-ironshirt

              sectionEnd

              procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

              enddocument


              enter image description here






              share|improve this answer
























                up vote
                1
                down vote













                This is possible with expl3, which already has features for processing comma separated lists and cycling over them.



                documentclassarticle
                usepackagexparse
                usepackagehyperref

                ExplSyntaxOn

                NewDocumentCommandprocedurelistm

                seq_clear:N l__kjc_procedurelist_seq
                clist_map_inline:nn #1

                seq_put_right:Nn l__kjc_procedurelist_seq

                PM~ref##1 & nameref##1


                begintabular
                hline
                seq_use:Nn l__kjc_procedurelist_seq \ \
                hline
                endtabular


                seq_new:N l__kjc_procedurelist_seq

                ExplSyntaxOff

                begindocument

                sectionTie laceslabelPM-tyinglaces
                sectionPolish shoeslabelPM-polishshoes
                sectionIron shirtlabelPM-ironshirt

                sectionEnd

                procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                enddocument


                enter image description here



                A better table:



                documentclassarticle
                usepackagexparse,booktabs
                usepackagehyperref

                ExplSyntaxOn

                NewDocumentCommandprocedurelistm

                seq_clear:N l__kjc_procedurelist_seq
                clist_map_inline:nn #1

                seq_put_right:Nn l__kjc_procedurelist_seq

                ref##1 & nameref##1


                begintabularcl
                toprule
                multicolumn1ctextbfPM & textbfName \
                midrule
                seq_use:Nn l__kjc_procedurelist_seq \ \
                bottomrule
                endtabular


                seq_new:N l__kjc_procedurelist_seq

                ExplSyntaxOff

                begindocument

                sectionTie laceslabelPM-tyinglaces
                sectionPolish shoeslabelPM-polishshoes
                sectionIron shirtlabelPM-ironshirt

                sectionEnd

                procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                enddocument


                enter image description here






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  This is possible with expl3, which already has features for processing comma separated lists and cycling over them.



                  documentclassarticle
                  usepackagexparse
                  usepackagehyperref

                  ExplSyntaxOn

                  NewDocumentCommandprocedurelistm

                  seq_clear:N l__kjc_procedurelist_seq
                  clist_map_inline:nn #1

                  seq_put_right:Nn l__kjc_procedurelist_seq

                  PM~ref##1 & nameref##1


                  begintabular
                  hline
                  seq_use:Nn l__kjc_procedurelist_seq \ \
                  hline
                  endtabular


                  seq_new:N l__kjc_procedurelist_seq

                  ExplSyntaxOff

                  begindocument

                  sectionTie laceslabelPM-tyinglaces
                  sectionPolish shoeslabelPM-polishshoes
                  sectionIron shirtlabelPM-ironshirt

                  sectionEnd

                  procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                  enddocument


                  enter image description here



                  A better table:



                  documentclassarticle
                  usepackagexparse,booktabs
                  usepackagehyperref

                  ExplSyntaxOn

                  NewDocumentCommandprocedurelistm

                  seq_clear:N l__kjc_procedurelist_seq
                  clist_map_inline:nn #1

                  seq_put_right:Nn l__kjc_procedurelist_seq

                  ref##1 & nameref##1


                  begintabularcl
                  toprule
                  multicolumn1ctextbfPM & textbfName \
                  midrule
                  seq_use:Nn l__kjc_procedurelist_seq \ \
                  bottomrule
                  endtabular


                  seq_new:N l__kjc_procedurelist_seq

                  ExplSyntaxOff

                  begindocument

                  sectionTie laceslabelPM-tyinglaces
                  sectionPolish shoeslabelPM-polishshoes
                  sectionIron shirtlabelPM-ironshirt

                  sectionEnd

                  procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                  enddocument


                  enter image description here






                  share|improve this answer












                  This is possible with expl3, which already has features for processing comma separated lists and cycling over them.



                  documentclassarticle
                  usepackagexparse
                  usepackagehyperref

                  ExplSyntaxOn

                  NewDocumentCommandprocedurelistm

                  seq_clear:N l__kjc_procedurelist_seq
                  clist_map_inline:nn #1

                  seq_put_right:Nn l__kjc_procedurelist_seq

                  PM~ref##1 & nameref##1


                  begintabular
                  hline
                  seq_use:Nn l__kjc_procedurelist_seq \ \
                  hline
                  endtabular


                  seq_new:N l__kjc_procedurelist_seq

                  ExplSyntaxOff

                  begindocument

                  sectionTie laceslabelPM-tyinglaces
                  sectionPolish shoeslabelPM-polishshoes
                  sectionIron shirtlabelPM-ironshirt

                  sectionEnd

                  procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                  enddocument


                  enter image description here



                  A better table:



                  documentclassarticle
                  usepackagexparse,booktabs
                  usepackagehyperref

                  ExplSyntaxOn

                  NewDocumentCommandprocedurelistm

                  seq_clear:N l__kjc_procedurelist_seq
                  clist_map_inline:nn #1

                  seq_put_right:Nn l__kjc_procedurelist_seq

                  ref##1 & nameref##1


                  begintabularcl
                  toprule
                  multicolumn1ctextbfPM & textbfName \
                  midrule
                  seq_use:Nn l__kjc_procedurelist_seq \ \
                  bottomrule
                  endtabular


                  seq_new:N l__kjc_procedurelist_seq

                  ExplSyntaxOff

                  begindocument

                  sectionTie laceslabelPM-tyinglaces
                  sectionPolish shoeslabelPM-polishshoes
                  sectionIron shirtlabelPM-ironshirt

                  sectionEnd

                  procedurelistPM-tyinglaces,PM-polishshoes,PM-ironshirt

                  enddocument


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 17 mins ago









                  egreg

                  683k8418183064




                  683k8418183064



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f451423%2fhow-to-use-ifnextchar-to-create-a-table-of-references-macro%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      Long meetings (6-7 hours a day): Being “babysat” by supervisor

                      Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                      Confectionery