How to use @ifnextchar to create a âtable of referencesâ macro?
Clash 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?
recursion
add a comment |Â
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?
recursion
The error of thehline
is caused because you usedchecknextarg
which isn't expandable as it uses@ifnextchar
which is not expandable. Then you want to issue anoalign
which is not the first token in that row.
â Skillmon
32 mins ago
add a comment |Â
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?
recursion
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
recursion
asked 1 hour ago
KJC
603
603
The error of thehline
is caused because you usedchecknextarg
which isn't expandable as it uses@ifnextchar
which is not expandable. Then you want to issue anoalign
which is not the first token in that row.
â Skillmon
32 mins ago
add a comment |Â
The error of thehline
is caused because you usedchecknextarg
which isn't expandable as it uses@ifnextchar
which is not expandable. Then you want to issue anoalign
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
add a comment |Â
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 noalign
s.
Example code (I removed the nameref
s 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
add a comment |Â
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
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
add a comment |Â
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 noalign
s.
Example code (I removed the nameref
s 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
add a comment |Â
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 noalign
s.
Example code (I removed the nameref
s 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
add a comment |Â
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 noalign
s.
Example code (I removed the nameref
s 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
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 noalign
s.
Example code (I removed the nameref
s 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
answered 24 mins ago
Skillmon
17.7k11535
17.7k11535
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
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
answered 17 mins ago
egreg
683k8418183064
683k8418183064
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
The error of the
hline
is caused because you usedchecknextarg
which isn't expandable as it uses@ifnextchar
which is not expandable. Then you want to issue anoalign
which is not the first token in that row.â Skillmon
32 mins ago