0

Two small questions here:

  • Why is Subentry3 not in \scriptsize?
  • How to arrange ... Mainentry1 so that it will only appear at the end of the last Subentry (however many pairs that may be), instead of at the end of the first pair (i.e. at the end of Subentry2)?

MWE

% !TEX TS-program = lualatexmk

\documentclass{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%
%
%
%
\newenvironment {mainentry} {\mainentryA}{}
\def\mainentryA#1#2#3{%
   \def\subentry##1##2{%
\scriptsize ##1 \space \Huge ##2 ... #1
   }%
#1 #2 #3
}
%
%
%
\def\subentry{\def\subentryS{\def\subentryS{\endgraf}}\futurelet\next\subentryA}
\def\subentryA{\ifx\bgroup\next\expandafter\subentryB\fi}
\def\subentryB#1#2{\subentryS\subentry{#1}{#2}\futurelet\next\subentryA}
%
%
%
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{mainentry}{
Mainentry1
}{
Mainentry2
}{
Mainentry3
}

\subentry{
Subentry1
}{
Subentry2
}{
Subentry3
}{
Subentry4
}

\end{mainentry}

\end{document}
O0123
  • 1,773
  • Why do you redefine the \subentry macro inside the environment. Why do you blemish the outer definition of \subentry: there is infinitive loop of calls because \subentryB includes \subentry again? It seems that you doesn't know basic principles of TeX. It is very difficult to explain you such basics. And you are not able to formulate, what is your intend. You can try to explain this by this way: "I want to print such thing ... when I write such code ... in my source document". – wipet Oct 11 '17 at 09:11
  • @wipet I tried to use your repetitive idea, but then somehow need to put it into an encompassing environment so that I may re-use the arguments coming from one level up. – O0123 Oct 11 '17 at 09:29
  • But if you need to reusing arguments then you must exactly know what you are doing. When you only blemish my code then I am not sure that you know how TeX works. – wipet Oct 11 '17 at 09:58

2 Answers2

2
\subentry{ Subentry1 }{ Subentry2 }{ Subentry3 }{ Subentry4 }

is

\scriptsize Subentry1 \space \Huge Subentry2 ... mainentry1 (Subentry3}{Subentry4}

so just the first is in \scriptsize and all the later ones are in Huge, the title asks about iteration but there is no iteration here, \subentry is only called once.

You can save mainentry1 in the begin code of the environment and use it at the end

\def\savedmain{#1}

in the begin code and use \savedmainin the end code after your subentries. Or (as in earlier questions) you could use the expl3 environment declarations that let you use #1 directly in the end code.

i think you are looking for something like this, but I would bnever use such a definition in a docuemnt. Iterating over a {] list is completely against latex syntax, where {} denotes a mandatory argument and here where you are actually using pairs it just obscures the document.

I would use simple non-iterative definitions and a syntax like

\begin{mainentry}{aa}{bb}{cc}

 \subentry{s1}{sss1}
 \subentry{s2}{sss2}
 \subentry{s3}{sss3}

\end{mainentry}

Then the code, and the document would be a lot clearer.

However:

\documentclass{scrreprt}

%%%%%%%%%%%%%%%%%%%%%%
%
%
%
\newenvironment{mainentry}[3]{#1 #2 #3\def\mainentrya{#1}\par}{\mainentrya}
%
\long\def\subentry#1#2{%
\ifx\par#1%
\endgraf\expandafter\end\else
{\scriptsize#1} {\huge#2}\expandafter\subentry
\fi}


%
%
%
%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{mainentry}{
Mainentry1
}{
Mainentry2
}{
Mainentry3
}

\subentry{
Subentry1
}{
Subentry2
}{
Subentry3
}{
Subentry4
}

\end{mainentry}

\end{document}
David Carlisle
  • 757,742
  • Thank you. That will solve the second problem. Are you sure there is no iteration? I mean, why do Subentry3 and Subentry4 even show up? One can add as many pairs of Subentries, isn't that sort of an iteration? I adapted the code from this answer. – O0123 Oct 11 '17 at 07:00
  • @VincentMiaEdieVerheyen why would there be any iteration? you only call subentry once (your loop definitions are not used at all) I will add some code. – David Carlisle Oct 11 '17 at 07:53
  • I tried to use the code from this answer, from another OP. – O0123 Oct 11 '17 at 07:56
  • @VincentMiaEdieVerheyen not with the definition of \subenry that you used inside the environment. The definition that you put at the end was never used at all (try deleting it and run your example you will see the same result. – David Carlisle Oct 11 '17 at 07:59
  • But, regarding the second question (bullet point in OP) ... your solution can put something right before the end of \end{mainentry}, isn't it? But imagine I have multiple instances of \subentry{...} after one another, then how do i get mainentry's first argument at the end of each \subentry{...}? – O0123 Oct 11 '17 at 08:28
  • @VincentMiaEdieVerheyen change \endgraf in the definition of \subentry to \endgraf\mainentrya\endgraf and take \mainentrya out of the end code of the enviornment. – David Carlisle Oct 11 '17 at 08:47
1

One your comment of another answer here implies that you need, maybe, to add some data which is declared at the very start of LaTeX environment to the each end of \subentry usage. It means, that

\begin{mainentry}{AAA}{B}{}
\Subentry{C}{D}{E}{F}
\Subentry{U}{V}{W}{X}{Y}{Z}
\end{mainentry}

would print something like this:

AAA B
(sub C, sub D) (sub E, sub F) (end: AAA)
(sub U, sub V) (sub W, sub X) (sub Y, sub Z) (end: AAA)

But I am not sure that this is exactly your intend because you are generating many questions of this topic at this site but none of them exactly explains your intend.

You can try to experiment with this code:

\documentclass[a4paper]{scrreprt}

\newenvironment {mainentry} {\mainentryA}{}
\def\mainentryA#1#2#3{%
   \def\SubentryE{\endgraf At the end of subentry collection is again (#1).}%
   \def\SubentryC##1##2{%
      Here is external paremater (#1) and second external (#2).
      And internal parameter is (##1) and second internal (##2).
   }
}
\def\Subentry{\def\SubentryS{\def\SubentryS{\endgraf}}\futurelet\next\SubentryA}
\def\SubentryA{\ifx\bgroup\next\expandafter\SubentryB\else\SubentryE\fi}
\def\SubentryB#1#2{\SubentryS\SubentryC{#1}{#2}\futurelet\next\SubentryA}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{mainentry}{A}{B}{}
\Subentry{C}{D}{E}{F}
NEXT
\Subentry{U}{V}{W}{X}{Y}{Z}
\end{mainentry}
Some text.
\end{document}
wipet
  • 74,238