Problem with foreach in node with rectangle split












1














I am attempting to automate the use rectangle split parts with a foreach loop. In the following MWE, the manual use of nodepart works as expected. The foreach loop fails with



./makebox-mwe.tex:71: Extra }, or forgotten endgroup.
pgfutil@reserved@c ->egroup
relax
l.71 end{outerenv}


The code:



documentclass{article}

usepackage{tikz}
usepackage{xparse}
usepackage{etoolbox}
usetikzlibrary{shapes.multipart}

%% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
cslet{glrbox}lrbox
expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
cslet{endglrbox}endlrbox

newsavebox{myboxi}
newsavebox{myboxii}
newsavebox{myboxiii}
newsavebox{myboxiv}
newsavebox{myboxv}

newcounter{myboxes}

defnumname#1{%
ifcase#1or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
}

NewDocumentEnvironment{outerenv}{}{%
setcounter{myboxes}{0}%
}{%
tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
{%
%% This does NOT work:
foreach nn in {1,...,themyboxes}{%
edeftmpname{csname myboxromannumeralnnendcsname}typeout{tmpname}%
deftmpnum{numname{nn}}typeout{tmpnum}%
nodepart{tmpnum}usebox{tmpname}%
}%
%%%
%% This works:
% nodepart{one}{usebox{myboxi}}
% nodepart{two}{usebox{myboxii}}
% nodepart{three}{usebox{myboxiii}}
% nodepart{four}{usebox{myboxiv}}
% nodepart{five}{usebox{myboxv}}%
};%
}

NewDocumentEnvironment{innerenv}{}{%
stepcounter{myboxes}%
edeftmpname{csname myboxromannumeralthemyboxesendcsname}%typeout{tmpname}%
begin{glrbox}{tmpname}
begin{minipage}[t]{2in}
}{%
end{minipage}%
end{glrbox}%
}

begin{document}

begin{outerenv}

begin{innerenv}
First
end{innerenv}

begin{innerenv}
Second
end{innerenv}

begin{innerenv}
Third
end{innerenv}

end{outerenv}

end{document}


NOTE: I know that there are probably a million (gajillion?) other ways of doing this. But my curiosity is piqued as to why this apparently straightforward attempt fails.










share|improve this question


















  • 1




    With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
    – jfbu
    Dec 14 '18 at 19:49












  • @jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
    – sgmoye
    Dec 14 '18 at 20:19










  • @jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
    – sgmoye
    Dec 14 '18 at 20:44










  • the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
    – jfbu
    Dec 14 '18 at 21:23












  • Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
    – sgmoye
    Dec 14 '18 at 21:31
















1














I am attempting to automate the use rectangle split parts with a foreach loop. In the following MWE, the manual use of nodepart works as expected. The foreach loop fails with



./makebox-mwe.tex:71: Extra }, or forgotten endgroup.
pgfutil@reserved@c ->egroup
relax
l.71 end{outerenv}


The code:



documentclass{article}

usepackage{tikz}
usepackage{xparse}
usepackage{etoolbox}
usetikzlibrary{shapes.multipart}

%% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
cslet{glrbox}lrbox
expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
cslet{endglrbox}endlrbox

newsavebox{myboxi}
newsavebox{myboxii}
newsavebox{myboxiii}
newsavebox{myboxiv}
newsavebox{myboxv}

newcounter{myboxes}

defnumname#1{%
ifcase#1or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
}

NewDocumentEnvironment{outerenv}{}{%
setcounter{myboxes}{0}%
}{%
tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
{%
%% This does NOT work:
foreach nn in {1,...,themyboxes}{%
edeftmpname{csname myboxromannumeralnnendcsname}typeout{tmpname}%
deftmpnum{numname{nn}}typeout{tmpnum}%
nodepart{tmpnum}usebox{tmpname}%
}%
%%%
%% This works:
% nodepart{one}{usebox{myboxi}}
% nodepart{two}{usebox{myboxii}}
% nodepart{three}{usebox{myboxiii}}
% nodepart{four}{usebox{myboxiv}}
% nodepart{five}{usebox{myboxv}}%
};%
}

NewDocumentEnvironment{innerenv}{}{%
stepcounter{myboxes}%
edeftmpname{csname myboxromannumeralthemyboxesendcsname}%typeout{tmpname}%
begin{glrbox}{tmpname}
begin{minipage}[t]{2in}
}{%
end{minipage}%
end{glrbox}%
}

begin{document}

begin{outerenv}

begin{innerenv}
First
end{innerenv}

begin{innerenv}
Second
end{innerenv}

begin{innerenv}
Third
end{innerenv}

end{outerenv}

end{document}


NOTE: I know that there are probably a million (gajillion?) other ways of doing this. But my curiosity is piqued as to why this apparently straightforward attempt fails.










share|improve this question


















  • 1




    With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
    – jfbu
    Dec 14 '18 at 19:49












  • @jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
    – sgmoye
    Dec 14 '18 at 20:19










  • @jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
    – sgmoye
    Dec 14 '18 at 20:44










  • the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
    – jfbu
    Dec 14 '18 at 21:23












  • Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
    – sgmoye
    Dec 14 '18 at 21:31














1












1








1







I am attempting to automate the use rectangle split parts with a foreach loop. In the following MWE, the manual use of nodepart works as expected. The foreach loop fails with



./makebox-mwe.tex:71: Extra }, or forgotten endgroup.
pgfutil@reserved@c ->egroup
relax
l.71 end{outerenv}


The code:



documentclass{article}

usepackage{tikz}
usepackage{xparse}
usepackage{etoolbox}
usetikzlibrary{shapes.multipart}

%% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
cslet{glrbox}lrbox
expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
cslet{endglrbox}endlrbox

newsavebox{myboxi}
newsavebox{myboxii}
newsavebox{myboxiii}
newsavebox{myboxiv}
newsavebox{myboxv}

newcounter{myboxes}

defnumname#1{%
ifcase#1or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
}

NewDocumentEnvironment{outerenv}{}{%
setcounter{myboxes}{0}%
}{%
tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
{%
%% This does NOT work:
foreach nn in {1,...,themyboxes}{%
edeftmpname{csname myboxromannumeralnnendcsname}typeout{tmpname}%
deftmpnum{numname{nn}}typeout{tmpnum}%
nodepart{tmpnum}usebox{tmpname}%
}%
%%%
%% This works:
% nodepart{one}{usebox{myboxi}}
% nodepart{two}{usebox{myboxii}}
% nodepart{three}{usebox{myboxiii}}
% nodepart{four}{usebox{myboxiv}}
% nodepart{five}{usebox{myboxv}}%
};%
}

NewDocumentEnvironment{innerenv}{}{%
stepcounter{myboxes}%
edeftmpname{csname myboxromannumeralthemyboxesendcsname}%typeout{tmpname}%
begin{glrbox}{tmpname}
begin{minipage}[t]{2in}
}{%
end{minipage}%
end{glrbox}%
}

begin{document}

begin{outerenv}

begin{innerenv}
First
end{innerenv}

begin{innerenv}
Second
end{innerenv}

begin{innerenv}
Third
end{innerenv}

end{outerenv}

end{document}


NOTE: I know that there are probably a million (gajillion?) other ways of doing this. But my curiosity is piqued as to why this apparently straightforward attempt fails.










share|improve this question













I am attempting to automate the use rectangle split parts with a foreach loop. In the following MWE, the manual use of nodepart works as expected. The foreach loop fails with



./makebox-mwe.tex:71: Extra }, or forgotten endgroup.
pgfutil@reserved@c ->egroup
relax
l.71 end{outerenv}


The code:



documentclass{article}

usepackage{tikz}
usepackage{xparse}
usepackage{etoolbox}
usetikzlibrary{shapes.multipart}

%% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
cslet{glrbox}lrbox
expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
cslet{endglrbox}endlrbox

newsavebox{myboxi}
newsavebox{myboxii}
newsavebox{myboxiii}
newsavebox{myboxiv}
newsavebox{myboxv}

newcounter{myboxes}

defnumname#1{%
ifcase#1or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
}

NewDocumentEnvironment{outerenv}{}{%
setcounter{myboxes}{0}%
}{%
tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
{%
%% This does NOT work:
foreach nn in {1,...,themyboxes}{%
edeftmpname{csname myboxromannumeralnnendcsname}typeout{tmpname}%
deftmpnum{numname{nn}}typeout{tmpnum}%
nodepart{tmpnum}usebox{tmpname}%
}%
%%%
%% This works:
% nodepart{one}{usebox{myboxi}}
% nodepart{two}{usebox{myboxii}}
% nodepart{three}{usebox{myboxiii}}
% nodepart{four}{usebox{myboxiv}}
% nodepart{five}{usebox{myboxv}}%
};%
}

NewDocumentEnvironment{innerenv}{}{%
stepcounter{myboxes}%
edeftmpname{csname myboxromannumeralthemyboxesendcsname}%typeout{tmpname}%
begin{glrbox}{tmpname}
begin{minipage}[t]{2in}
}{%
end{minipage}%
end{glrbox}%
}

begin{document}

begin{outerenv}

begin{innerenv}
First
end{innerenv}

begin{innerenv}
Second
end{innerenv}

begin{innerenv}
Third
end{innerenv}

end{outerenv}

end{document}


NOTE: I know that there are probably a million (gajillion?) other ways of doing this. But my curiosity is piqued as to why this apparently straightforward attempt fails.







tikz-pgf foreach






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 14 '18 at 17:28









sgmoye

3,78811225




3,78811225








  • 1




    With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
    – jfbu
    Dec 14 '18 at 19:49












  • @jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
    – sgmoye
    Dec 14 '18 at 20:19










  • @jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
    – sgmoye
    Dec 14 '18 at 20:44










  • the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
    – jfbu
    Dec 14 '18 at 21:23












  • Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
    – sgmoye
    Dec 14 '18 at 21:31














  • 1




    With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
    – jfbu
    Dec 14 '18 at 19:49












  • @jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
    – sgmoye
    Dec 14 '18 at 20:19










  • @jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
    – sgmoye
    Dec 14 '18 at 20:44










  • the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
    – jfbu
    Dec 14 '18 at 21:23












  • Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
    – sgmoye
    Dec 14 '18 at 21:31








1




1




With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
– jfbu
Dec 14 '18 at 19:49






With an xintFor* loop, it works with a single line: nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}. Thus I guess the problem is that nodepart does not like being scoped. Maybe you can use the un-scoping foreach loop from pgfplots?
– jfbu
Dec 14 '18 at 19:49














@jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
– sgmoye
Dec 14 '18 at 20:19




@jfbu Thank you, but could you flesh that out a bit? I tried xintFor* ##1 in {1,2,3,4,5} do {nodepart{numname{##1}}usebox{csname myboxromannumeral##1endcsname}} but TeX complains of a Missing begin{document}
– sgmoye
Dec 14 '18 at 20:19












@jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
– sgmoye
Dec 14 '18 at 20:44




@jfbu Oops. My bad. After fixing some silly errors, it is working. Thanks.
– sgmoye
Dec 14 '18 at 20:44












the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
– jfbu
Dec 14 '18 at 21:23






the xintFor* starred variant is for use with in {12345} or in {xintSeq{1}{5}} (too lazy to have done the 1, ..., 5 type syntax but I will... it would be 1...5 here). The non-starred variant xintFor is for in {1, 2, 3, 4, 5} and there is no macro for generating thes csv values (there is one in xintexpr which recognizes a..b but it has private name). Anyway, glad you got it working :)
– jfbu
Dec 14 '18 at 21:23














Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
– sgmoye
Dec 14 '18 at 21:31




Quite deliriously happy using {xintSeq{<n_1>}{<n_m>} ;). Works like a charm! A puzzle (not entirely surprising perhaps) that foreach and nodepart do not seem to play well together. Ah well, live and learn...
– sgmoye
Dec 14 '18 at 21:31










1 Answer
1






active

oldest

votes


















4














It appears one can not use nodepart{..} inside a group (e.g. {nodepart{...}} or inside a LaTeX environment).



Alternative is to use some looping not using groups. For example the pgfplotsforeachungrouped or pgfplotsinvokeforeach of pgfplots.



As a poor man alternative you have lightweight package xinttools which provides xintFor* loop:



documentclass{article}

usepackage{tikz}
usepackage{xparse}
usepackage{etoolbox}
usetikzlibrary{shapes.multipart}

%% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
cslet{glrbox}lrbox
expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
cslet{endglrbox}endlrbox

newsavebox{myboxi}
newsavebox{myboxii}
newsavebox{myboxiii}
newsavebox{myboxiv}
newsavebox{myboxv}

newcounter{myboxes}

defnumname#1{%
ifcase#1 or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
}

usepackage{xinttools}% for xintFor/xintFor* loops

NewDocumentEnvironment{outerenv}{}{%
setcounter{myboxes}{0}%
}{%
tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
{%
% foreachnn in {1, ..., themyboxes}
% xinttools manual says to use "do" but we can use any token, such as ":"
xintFor* ##1 in {xintSeq{1}{value{myboxes}}}:
{%
% edeftmpname{csname myboxromannumeral##1endcsname}%
% deftmpnum{numname{##1}}%
% nodepart{tmpnum}usebox{tmpname}%
% nodepart{numname{nn}}usebox{csname myboxromannumeralnnendcsname}%
%begingroup% just testing to confirm with it same error as in OP
nodepart{numname{##1}}%
%endgroup % bien sûr nodepart n'aime pas cela...
usebox{csname myboxromannumeral##1endcsname}%
}%
%%%
%% This works:
% nodepart{one}{usebox{myboxi}}
% nodepart{two}{usebox{myboxii}}
% nodepart{three}{usebox{myboxiii}}
% nodepart{four}{usebox{myboxiv}}
% nodepart{five}{usebox{myboxv}}%
};%
}

NewDocumentEnvironment{innerenv}{}{%
stepcounter{myboxes}%
edeftmpname{csname myboxromannumeralthemyboxesendcsname}%
begin{glrbox}{tmpname}
begin{minipage}[t]{2in}
}{%
end{minipage}%
end{glrbox}%
}

begin{document}

begin{outerenv}

begin{innerenv}
First
end{innerenv}

begin{innerenv}
Second
end{innerenv}

begin{innerenv}
Third
end{innerenv}

end{outerenv}

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%2f464869%2fproblem-with-foreach-in-node-with-rectangle-split%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









    4














    It appears one can not use nodepart{..} inside a group (e.g. {nodepart{...}} or inside a LaTeX environment).



    Alternative is to use some looping not using groups. For example the pgfplotsforeachungrouped or pgfplotsinvokeforeach of pgfplots.



    As a poor man alternative you have lightweight package xinttools which provides xintFor* loop:



    documentclass{article}

    usepackage{tikz}
    usepackage{xparse}
    usepackage{etoolbox}
    usetikzlibrary{shapes.multipart}

    %% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
    cslet{glrbox}lrbox
    expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
    cslet{endglrbox}endlrbox

    newsavebox{myboxi}
    newsavebox{myboxii}
    newsavebox{myboxiii}
    newsavebox{myboxiv}
    newsavebox{myboxv}

    newcounter{myboxes}

    defnumname#1{%
    ifcase#1 or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
    }

    usepackage{xinttools}% for xintFor/xintFor* loops

    NewDocumentEnvironment{outerenv}{}{%
    setcounter{myboxes}{0}%
    }{%
    tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
    {%
    % foreachnn in {1, ..., themyboxes}
    % xinttools manual says to use "do" but we can use any token, such as ":"
    xintFor* ##1 in {xintSeq{1}{value{myboxes}}}:
    {%
    % edeftmpname{csname myboxromannumeral##1endcsname}%
    % deftmpnum{numname{##1}}%
    % nodepart{tmpnum}usebox{tmpname}%
    % nodepart{numname{nn}}usebox{csname myboxromannumeralnnendcsname}%
    %begingroup% just testing to confirm with it same error as in OP
    nodepart{numname{##1}}%
    %endgroup % bien sûr nodepart n'aime pas cela...
    usebox{csname myboxromannumeral##1endcsname}%
    }%
    %%%
    %% This works:
    % nodepart{one}{usebox{myboxi}}
    % nodepart{two}{usebox{myboxii}}
    % nodepart{three}{usebox{myboxiii}}
    % nodepart{four}{usebox{myboxiv}}
    % nodepart{five}{usebox{myboxv}}%
    };%
    }

    NewDocumentEnvironment{innerenv}{}{%
    stepcounter{myboxes}%
    edeftmpname{csname myboxromannumeralthemyboxesendcsname}%
    begin{glrbox}{tmpname}
    begin{minipage}[t]{2in}
    }{%
    end{minipage}%
    end{glrbox}%
    }

    begin{document}

    begin{outerenv}

    begin{innerenv}
    First
    end{innerenv}

    begin{innerenv}
    Second
    end{innerenv}

    begin{innerenv}
    Third
    end{innerenv}

    end{outerenv}

    end{document}





    share|improve this answer


























      4














      It appears one can not use nodepart{..} inside a group (e.g. {nodepart{...}} or inside a LaTeX environment).



      Alternative is to use some looping not using groups. For example the pgfplotsforeachungrouped or pgfplotsinvokeforeach of pgfplots.



      As a poor man alternative you have lightweight package xinttools which provides xintFor* loop:



      documentclass{article}

      usepackage{tikz}
      usepackage{xparse}
      usepackage{etoolbox}
      usetikzlibrary{shapes.multipart}

      %% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
      cslet{glrbox}lrbox
      expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
      cslet{endglrbox}endlrbox

      newsavebox{myboxi}
      newsavebox{myboxii}
      newsavebox{myboxiii}
      newsavebox{myboxiv}
      newsavebox{myboxv}

      newcounter{myboxes}

      defnumname#1{%
      ifcase#1 or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
      }

      usepackage{xinttools}% for xintFor/xintFor* loops

      NewDocumentEnvironment{outerenv}{}{%
      setcounter{myboxes}{0}%
      }{%
      tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
      {%
      % foreachnn in {1, ..., themyboxes}
      % xinttools manual says to use "do" but we can use any token, such as ":"
      xintFor* ##1 in {xintSeq{1}{value{myboxes}}}:
      {%
      % edeftmpname{csname myboxromannumeral##1endcsname}%
      % deftmpnum{numname{##1}}%
      % nodepart{tmpnum}usebox{tmpname}%
      % nodepart{numname{nn}}usebox{csname myboxromannumeralnnendcsname}%
      %begingroup% just testing to confirm with it same error as in OP
      nodepart{numname{##1}}%
      %endgroup % bien sûr nodepart n'aime pas cela...
      usebox{csname myboxromannumeral##1endcsname}%
      }%
      %%%
      %% This works:
      % nodepart{one}{usebox{myboxi}}
      % nodepart{two}{usebox{myboxii}}
      % nodepart{three}{usebox{myboxiii}}
      % nodepart{four}{usebox{myboxiv}}
      % nodepart{five}{usebox{myboxv}}%
      };%
      }

      NewDocumentEnvironment{innerenv}{}{%
      stepcounter{myboxes}%
      edeftmpname{csname myboxromannumeralthemyboxesendcsname}%
      begin{glrbox}{tmpname}
      begin{minipage}[t]{2in}
      }{%
      end{minipage}%
      end{glrbox}%
      }

      begin{document}

      begin{outerenv}

      begin{innerenv}
      First
      end{innerenv}

      begin{innerenv}
      Second
      end{innerenv}

      begin{innerenv}
      Third
      end{innerenv}

      end{outerenv}

      end{document}





      share|improve this answer
























        4












        4








        4






        It appears one can not use nodepart{..} inside a group (e.g. {nodepart{...}} or inside a LaTeX environment).



        Alternative is to use some looping not using groups. For example the pgfplotsforeachungrouped or pgfplotsinvokeforeach of pgfplots.



        As a poor man alternative you have lightweight package xinttools which provides xintFor* loop:



        documentclass{article}

        usepackage{tikz}
        usepackage{xparse}
        usepackage{etoolbox}
        usetikzlibrary{shapes.multipart}

        %% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
        cslet{glrbox}lrbox
        expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
        cslet{endglrbox}endlrbox

        newsavebox{myboxi}
        newsavebox{myboxii}
        newsavebox{myboxiii}
        newsavebox{myboxiv}
        newsavebox{myboxv}

        newcounter{myboxes}

        defnumname#1{%
        ifcase#1 or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
        }

        usepackage{xinttools}% for xintFor/xintFor* loops

        NewDocumentEnvironment{outerenv}{}{%
        setcounter{myboxes}{0}%
        }{%
        tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
        {%
        % foreachnn in {1, ..., themyboxes}
        % xinttools manual says to use "do" but we can use any token, such as ":"
        xintFor* ##1 in {xintSeq{1}{value{myboxes}}}:
        {%
        % edeftmpname{csname myboxromannumeral##1endcsname}%
        % deftmpnum{numname{##1}}%
        % nodepart{tmpnum}usebox{tmpname}%
        % nodepart{numname{nn}}usebox{csname myboxromannumeralnnendcsname}%
        %begingroup% just testing to confirm with it same error as in OP
        nodepart{numname{##1}}%
        %endgroup % bien sûr nodepart n'aime pas cela...
        usebox{csname myboxromannumeral##1endcsname}%
        }%
        %%%
        %% This works:
        % nodepart{one}{usebox{myboxi}}
        % nodepart{two}{usebox{myboxii}}
        % nodepart{three}{usebox{myboxiii}}
        % nodepart{four}{usebox{myboxiv}}
        % nodepart{five}{usebox{myboxv}}%
        };%
        }

        NewDocumentEnvironment{innerenv}{}{%
        stepcounter{myboxes}%
        edeftmpname{csname myboxromannumeralthemyboxesendcsname}%
        begin{glrbox}{tmpname}
        begin{minipage}[t]{2in}
        }{%
        end{minipage}%
        end{glrbox}%
        }

        begin{document}

        begin{outerenv}

        begin{innerenv}
        First
        end{innerenv}

        begin{innerenv}
        Second
        end{innerenv}

        begin{innerenv}
        Third
        end{innerenv}

        end{outerenv}

        end{document}





        share|improve this answer












        It appears one can not use nodepart{..} inside a group (e.g. {nodepart{...}} or inside a LaTeX environment).



        Alternative is to use some looping not using groups. For example the pgfplotsforeachungrouped or pgfplotsinvokeforeach of pgfplots.



        As a poor man alternative you have lightweight package xinttools which provides xintFor* loop:



        documentclass{article}

        usepackage{tikz}
        usepackage{xparse}
        usepackage{etoolbox}
        usetikzlibrary{shapes.multipart}

        %% Thanks to egreg, make lrbox* global (requires etoolbox.sty):
        cslet{glrbox}lrbox
        expandafterpatchcmdcsname glrboxendcsname{setbox}{globalsetbox}{}{}
        cslet{endglrbox}endlrbox

        newsavebox{myboxi}
        newsavebox{myboxii}
        newsavebox{myboxiii}
        newsavebox{myboxiv}
        newsavebox{myboxv}

        newcounter{myboxes}

        defnumname#1{%
        ifcase#1 or oneor twoor threeor fouror fiveor sixor sevenor eightor nineor tenor eleven or twelveor thirteenor fourteenor fifteenor sixteenor seventeenor eighteenor nineteenor twentyfi%
        }

        usepackage{xinttools}% for xintFor/xintFor* loops

        NewDocumentEnvironment{outerenv}{}{%
        setcounter{myboxes}{0}%
        }{%
        tikz node[draw,rectangle split,rectangle split parts=5,rectangle split ignore empty parts]
        {%
        % foreachnn in {1, ..., themyboxes}
        % xinttools manual says to use "do" but we can use any token, such as ":"
        xintFor* ##1 in {xintSeq{1}{value{myboxes}}}:
        {%
        % edeftmpname{csname myboxromannumeral##1endcsname}%
        % deftmpnum{numname{##1}}%
        % nodepart{tmpnum}usebox{tmpname}%
        % nodepart{numname{nn}}usebox{csname myboxromannumeralnnendcsname}%
        %begingroup% just testing to confirm with it same error as in OP
        nodepart{numname{##1}}%
        %endgroup % bien sûr nodepart n'aime pas cela...
        usebox{csname myboxromannumeral##1endcsname}%
        }%
        %%%
        %% This works:
        % nodepart{one}{usebox{myboxi}}
        % nodepart{two}{usebox{myboxii}}
        % nodepart{three}{usebox{myboxiii}}
        % nodepart{four}{usebox{myboxiv}}
        % nodepart{five}{usebox{myboxv}}%
        };%
        }

        NewDocumentEnvironment{innerenv}{}{%
        stepcounter{myboxes}%
        edeftmpname{csname myboxromannumeralthemyboxesendcsname}%
        begin{glrbox}{tmpname}
        begin{minipage}[t]{2in}
        }{%
        end{minipage}%
        end{glrbox}%
        }

        begin{document}

        begin{outerenv}

        begin{innerenv}
        First
        end{innerenv}

        begin{innerenv}
        Second
        end{innerenv}

        begin{innerenv}
        Third
        end{innerenv}

        end{outerenv}

        end{document}






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 14 '18 at 21:55









        jfbu

        46.1k66148




        46.1k66148






























            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.





            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464869%2fproblem-with-foreach-in-node-with-rectangle-split%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

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents