Problem with condition in a table by using counters
I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:
% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}
newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}
This code works fine, but if i change defanyy{a}
to defanyy{a,b}
, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.
tables counters condition
New contributor
add a comment |
I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:
% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}
newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}
This code works fine, but if i change defanyy{a}
to defanyy{a,b}
, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.
tables counters condition
New contributor
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago
add a comment |
I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:
% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}
newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}
This code works fine, but if i change defanyy{a}
to defanyy{a,b}
, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.
tables counters condition
New contributor
I'm trying to make a conditional dynamic table that uses counter for comparison but i got a irrational error, Please see the following code:
% !TEX TS-program = xelatex
documentclass[hidelinks]{article}
usepackage{pgffor}
usepackage{longtable}
newcounter{generalCounter}
begin{document}
defanyy{a}
begin{longtable}{cccc}
setcounter{generalCounter}{0}foreachelement inanyy{stepcounter{generalCounter}}
ifnumthegeneralCounter=1
1 & 2 & 3 & 4 \hline
fi
ifnumthegeneralCounter=2
1 & 2 & 3 & 4 \hline
fi
end{longtable}
end{document}
This code works fine, but if i change defanyy{a}
to defanyy{a,b}
, can not build and showen error is ! Incomplete ifnum; all text was ignored after line 11.
tables counters condition
tables counters condition
New contributor
New contributor
New contributor
asked 41 mins ago
David Tex
61
61
New contributor
New contributor
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago
add a comment |
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago
add a comment |
1 Answer
1
active
oldest
votes
The looping with foreach
isn't the issue, but anyy
isn't getting expanded correctly. In addition, the test ifnum
begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.
A simpler way is to use prg_replicate:nn
here, a, expl3
macro, that performs expandable loops and survives the grouping involved with tabular cells.
The helper macro generatelines
stores the argument in a clist
and counts its elements with clist_count:N
, which is the number of repetitions to be made.
The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry
.
documentclass{article}
usepackage{longtable}
usepackage{xparse}
newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn
NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
end{document}
add a comment |
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
});
}
});
David Tex is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467709%2fproblem-with-condition-in-a-table-by-using-counters%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
The looping with foreach
isn't the issue, but anyy
isn't getting expanded correctly. In addition, the test ifnum
begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.
A simpler way is to use prg_replicate:nn
here, a, expl3
macro, that performs expandable loops and survives the grouping involved with tabular cells.
The helper macro generatelines
stores the argument in a clist
and counts its elements with clist_count:N
, which is the number of repetitions to be made.
The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry
.
documentclass{article}
usepackage{longtable}
usepackage{xparse}
newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn
NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
end{document}
add a comment |
The looping with foreach
isn't the issue, but anyy
isn't getting expanded correctly. In addition, the test ifnum
begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.
A simpler way is to use prg_replicate:nn
here, a, expl3
macro, that performs expandable loops and survives the grouping involved with tabular cells.
The helper macro generatelines
stores the argument in a clist
and counts its elements with clist_count:N
, which is the number of repetitions to be made.
The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry
.
documentclass{article}
usepackage{longtable}
usepackage{xparse}
newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn
NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
end{document}
add a comment |
The looping with foreach
isn't the issue, but anyy
isn't getting expanded correctly. In addition, the test ifnum
begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.
A simpler way is to use prg_replicate:nn
here, a, expl3
macro, that performs expandable loops and survives the grouping involved with tabular cells.
The helper macro generatelines
stores the argument in a clist
and counts its elements with clist_count:N
, which is the number of repetitions to be made.
The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry
.
documentclass{article}
usepackage{longtable}
usepackage{xparse}
newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn
NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
end{document}
The looping with foreach
isn't the issue, but anyy
isn't getting expanded correctly. In addition, the test ifnum
begins in one tabular cell and ends in other ones -- this is weird and can be catched only with tricks.
A simpler way is to use prg_replicate:nn
here, a, expl3
macro, that performs expandable loops and survives the grouping involved with tabular cells.
The helper macro generatelines
stores the argument in a clist
and counts its elements with clist_count:N
, which is the number of repetitions to be made.
The actual tabular line entry is another, 'freely' configurable helper macro, e.g. modeltableentry
.
documentclass{article}
usepackage{longtable}
usepackage{xparse}
newcommand{modeltableentry}{%
1 & 2 & 3 & 4 tabularnewline hline
}
ExplSyntaxOn
NewDocumentCommand{generatelines}{+m}{%
clist_set:Nx l_tmpa_clist {#1}
prg_replicate:nn {clist_count:N l_tmpa_clist } {modeltableentry}
}
ExplSyntaxOff
begin{document}
newcommand{anyy}{a,b}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
renewcommand{anyy}{a,b,c,d,e,f,g,h,i,j,k}
begin{longtable}{cccc}
generatelines{anyy}
end{longtable}
end{document}
edited 21 mins ago
answered 26 mins ago
Christian Hupfer
147k14192384
147k14192384
add a comment |
add a comment |
David Tex is a new contributor. Be nice, and check out our Code of Conduct.
David Tex is a new contributor. Be nice, and check out our Code of Conduct.
David Tex is a new contributor. Be nice, and check out our Code of Conduct.
David Tex is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467709%2fproblem-with-condition-in-a-table-by-using-counters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
Welcome to TeX.SE!
– Christian Hupfer
21 mins ago