How does one construct macros, each taking some arbitrary number of tuples inputs, that output the parameters into a designed paragraph form? Also, exist macros taking again some of the inputs, and then printing the corresponding inputs that were not entered but associated with these in the tuples substructures.

We color and text size organize and rank a descending ordered set of text entries.


Also we enumerate text entries tuples. We display the number of each entry on the left in the margin beside the entry. This is flush to the margin and hanging indented, to be easily distinguished from the other entries if there are other entries.


We can write for example ...

\pnkt {\useless%
    \textbf{AAA1}, \textbf{BBB1}; \textbf{AAA2}, \textbf{BBB2}; \textbf{AAA3}, \textbf{BBB3}. %
    \textbf{CCC}. \textit{DDD}. EEE.}
\pnkt {\mixedquality%
    \textbf{AAA1}, \textbf{BBB1}; \textbf{AAA2}, \textbf{BBB2}. %
    \textbf{CCC}. DDD. \textit{EEE} FFF.}

but we prefer writing this ...


and so on: for arbitrary numbers of AAA and BBB parameters. This is difficult because \def and \newcommand are defined only no more than nine parameters.

Any solution to a problem like this can be adapted for any repetitive case, such as write up of a series of experiments or mathematical statements where the number of variables is itself variable but the paragraph is basically unchanged. For example, ``if AAA1 then BBB1 and if AAA2 then BBB2 and ... and if AAAn then BBB2, and in case we also suppose CCC, then we infer DDD, which is same as EEE ...'' This is isomorphic to the references problem.

We enumerated all paragraphs. So later in the text we want to write, for example, This suggestion was proved years later \ranked{3}{AAA1}{AAA2}{AAA3} to display This suggestion was proved years later [the \pnkt number of the reference corresponding to \book{rank}{3}{AAA1 ... BBB3}{CCC}{DDD}{EEE}].

We then want to write for example ... \extracted{3}{AAA1}{AAA2}{AAA3} to display ... (AAA1, AAA2, AAA3 CCC) or ... (AAA1, AAA2, AAA3, useful) or ... (AAA1, AAA2, AAA3, DDD), all depending on how we define \rank.

EDIT 1: Bounty for this question. EDIT 2: Question is rewritten for easy printing.

  • 2
    What are you actually trying to do with these macros? – Thruston Jun 6 '14 at 7:50
  • I don't really understand what you mean. But IMHO, I wouldn't use macros to fasten the input. If you want, there are snippet applications (sometimes the text editor itself gives you the option) which you can program. Now, if there's really an “entity” after that command, then sure. But still, I think the question could be clarified a bit… – Manuel Jun 6 '14 at 11:29
  • 1
    @GuidoJorg Such things have been done for \cite and \ref before, and for many other stuff to, mostly using some variant of foreach. So depending on what you need it for, very likely you'll be re-discovering America. – yo' Jun 6 '14 at 12:31
  • 1
    To a part of your question, which now is a little bit clear, you could use some kind of delimited argument and solve the “n” arguments. Something like (I'm not sure) \def\foo#1#2!#3#4#5{...} and inside that the argument which holds all the {AAA1}{BBB1}…{AAAn}{BBBn} is #2, then make some sort of “mapping” (in LaTeX3 is very easy with something like \tl_map_inline:Nn but with two arguments) which takes two arguments each time. – Manuel Jun 8 '14 at 15:28
  • 2
    @GuidoJorg No, it doesn't require XeTeX. By the way, even better could be something like \foo{rank}{aaa1,bbb1,aaa2,bbb2,…,aaan,bbbn}{ccc}{ddd}{eee}. Would it be acceptable? – Manuel Jun 8 '14 at 16:02

May be this is what you need. But I am not sure...



\def\monograf#1#2#3{\setdata{#1}\textbf{#1}. \textit{#2}. #3.\egroup\par}
\def\mirpages#1#2#3#4{\setdata{#1}\textbf{#1}. #2. \textit{#3} #4.\egroup\par}



\def\book{\let\finalparams=\monograf \bookoressy}
\def\essy{\let\finalparams=\mirpages  \bookoressy}

   \csname#1\endcsname \tmpnmbr=0 \def\authornumber{#2}\authornamedB
\def\authornamedB#1#2{\textbf{#1}, \textbf{#2}%
   \addto\tmp{#1, }%
   \advance\tmpnmbr by1
   \expandafter\authornamedB\else. \expandafter\finalparams\fi
\def\pnkt{\advance\pnktnum by1
   \noindent \hangindent=9mm \llap{\textbf{\textit{\the\pnktnum}}\kern18mm}\ignorespaces

\def\ranked#1{\bgroup\tmpnmbr=0 \def\finalprint{[\csname num:\tmp\endcsname]}%
\def\extracted#1{\bgroup\tmpnmbr=0 \def\finalprint{(\tmp\csname data:\tmp\endcsname)}%
\def\rankedorextracted#1{\addto\tmp{#1, }%
   \advance\tmpnmbr by1
   \expandafter \rankedorextracted \else \finalprint\egroup \fi



This suggestion was proved years later \ranked{2}{AAAx1}{AAAx2}.

... \extracted{1}{AAAy1}

... \extracted{3}{AAA1}{AAA2}{AAA3}


There are two barriers for me: first one: LaTeX (I am not using LaTeX), second one: I don't understand your specification well. But I hope that the previous code will be usefull. You can inspire.

  • If the code works it doesn't really matter if its TeX or LaTeX, yes? LaTeX is implemented mostly with TeX anyway, so there is no problem. The code you wrote works great and is very clear and can be generalized. => bounty, +1, accepted – Guido Jorg Jun 10 '14 at 23:25
  • Yes. May be it looks like assembler code inside C++ language but it works. It is only macrolanguage based on TeX. Potential problem is only if something is redefined by LaTeX (\end, \input primitive, \line macro...). – wipet Jun 11 '14 at 15:44

The problem is that the question is not given clearly. I'll try to retell the question (but I am not sure that I understood it well).

The \rnk macro has two fixed parameters followed by 2n+4 next parameters. First fixed parameter gives the "preamble" (font and colors setting given by special name), second fixed parameter includes the number n. Following 2n parameters have to be created as `\textbf{parameter}, \textfb{parameter}; etc. The last couple is closed by dot instead semicolon. Then the last 4 parameters have to be printed in given way.

If this is true then the following code implements \rnk:


% preambles:
\def\ALLUSEFULx  {\normalsize\color{black}}
\def\PARTUSEFULx {\normalsize\color{green}}
\def\NOTUSEFULx  {\footnotesize\color{blue}}

\def\rnk #1#2{\broup \csname #1x\endcsname \tmpnum=0 \def\rnknum{#2}\rnkA}
\def\rnkA #1#2{\textbf{#1}, \textbf{#2}%
   \advance\tmpnum by1 
   \ifnum\tmpnum<\rnknum; \expandafter\rnkA \else. \expandafter\rnkB \fi
\def\rnkB #1#2#3#4{\textbf{#1}. #2. \textit{#3} #4.\egroup}

\begin{document} % if you really are using LaTeX...



Note: the output of \rnk starts by fonts and colors setting but it is not enclosed in group. This may be a little bug, but this exactly follows the assignment from asker.

The second part of the question is absolutely not understandable for me. What means "the reference given by the number", what means the letter n or p in square brackets of \rankd etc. If you await an answer to the second part of the question then give it clearly.

  • 2
    Sorry, your code is not compilable: ! LaTeX Error: Undefined color 'gray', ! Undefined control sequence \rnk etc. So I've only suspect what do you mean, how do you manipulate with colors but I did'n try it. I've added the header to my code now, so it is MWE. Sorry, I've read all your texts carefully but I mean that you problem is that you cannot experss the idea clearly. This is the reason why there are no answers (except mine). – wipet Jun 8 '14 at 4:07
  • Although I believe the question is clear, not everybody agrees. I'll provide a detailed explanation of existing macros in the MWE in the question text itself and clarify the question further. Please wait a bit. (BTW I +1 your answer and +1 your edit; your suggestion works for single instances. But it break down when many entries use the macro. The biggest problem is that the counter seems to not refresh, and so upon entering the number n of authors the next time the macro is used, the count is off, and the macro assumes the wrong number of {}. Each next execution is more off in the same way. – Guido Jorg Jun 8 '14 at 9:23
  • 1
    OK, \tmpnum was not reset. It was my mistake. I've corrected it. – wipet Jun 8 '14 at 9:42
  • Please refer to the clarified question. Is there a way to allow the macro as you designed it to stack with other macros? It does not combine with most other macros unlike the usual \def or \newcommand; if ... then is sensitive to {} or the whole thing is treated as one symbol until it is compiled, when it is too late to operate on it meaningfully. I suspect the output can to be stored and sent to another macro as text and that macro can be manipulated, either to display the result or combined with further macros. This would make your solution more general. Is this possible? – Guido Jorg Jun 8 '14 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.