I implemented a short macro that processes a comma separated argument list to format them.
So by calling
\macroa{ABC, DEF}
it will format the text to ABC DEF
Now what I would like to have is either a macro or command (better macro), by calling
\macrob{{ABC, DEF}, {GHI, JKL}, {MNO, PQR}}
that can list the given lists by calling the macro I defined, macroa, which the amount of lists to be passed into macrob is variadic but surely less than 10. The result is to have output ABC DEF; GHI JKL; MNO PQR.
Second question is more advance but not essential. If I would like to consider the second argument of each list to determine the use semi-colon or comma, would there be a simple implementation that modify macrob to achieve? Say, I would like an empty second argument to use comma joining the next list passed.
\macroc{{ABC, }, {GHI, }, {MNO, PQR}, {STU, VWX}}
ABC, GHI, MNO PQR; STU VWX
Finally I would like to know the technical term for such "list".
Thank you very much for your help!
Have the problem partially solved. Thanks @egreg !!!
\documentclass[12pt,a4paper,notitlepage,openright]{report}
\usepackage{xparse}
\makeatletter
\def\awarddegree#1{\gdef\@awarddegree{#1 }}
\def\@awarddegree{\@latex@warning@no@line{No \noexpand\awarddegree given}}
\def\pastdegree#1{\expandafter\pastdegree@i#1\@nil}
\def\pastdegree@i#1,#2\@nil{\gdef\@pastdegree{#1 \textit{#2}}}
\def\@pastdegree{\@latex@warning@no@line{No \noexpand\pastdegree given}}
\def\atry#1{\expandafter\atry@i#1\@nil}
\def\atry@i#1,#2\@nil{\gdef\@atry{\pastdegree{#1}\@pastdegree; \pastdegree{#2}\@pastdegree}}
\def\@atry{\@latex@warning@no@line{No \noexpand\atry given}}
\makeatother
\atry{{B.A.,H.K.},{M.Phil.,Oxon.}}
\begin{document}
\makeatletter
\@atry
\makeatother
\end{document}
I see that the
- There should be no spaces in between elements in the list or nested list, then the elements can be passed successfully. (Through \tracingmarcros=1, discover such debugging method in another post)
- For the \def\atry@i#1,#2\@nil line, previously, there were only \gdef\@atry{\pastdegree{#1} \pastdegree{#2}} and resulted in no input. So observing the use of \@macro and \macro, I sees that \macro is probably "definition" in C's sense, and \@macro is the calling/use of the "definition", so I changed the line to the above solution.
Thanks so much again @egreg . I learnt a lot tonight!
Final Solution
\makeatletter
\def\pastdegree#1{\expandafter\pastdegree@i#1\@nil}
\def\pastdegree@i#1,#2\@nil{\gdef\@pastdegree{#1\IfStrEq{#2}{}{}{ }\textit{#2}}}
\def\@pastdegree{\@latex@warning@no@line{No \noexpand\pastdegree given}}
\newcommand{\ifsameinstitute}[1]{\IfEndWith{#1}{,}{,}{;}}
% WRITING A MACRO WITH COMMA EXPANSION LIST
%
% http://tex.stackexchange.com/questions/15716/how-do-i-write-a-macro-having-comma-separated-and-variable-number-of-arguments
\def\degreelist#1{\expandafter\degreelist@i#1,,,,,,,,\@nil}
\def\degreelist@i#1,#2,#3,#4,#5,#6,#7,#8,#9\@nil{%
\ifx$#2$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree}
\else
\ifx$#3$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree}
\else
\ifx$#4$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree}
\else
\ifx$#5$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree\ifsameinstitute{#3} %
\pastdegree{#4}\@pastdegree}
\else
\ifx$#6$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree\ifsameinstitute{#3} %
\pastdegree{#4}\@pastdegree\ifsameinstitute{#4} %
\pastdegree{#5}\@pastdegree}
\else
\ifx$#7$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree\ifsameinstitute{#3} %
\pastdegree{#4}\@pastdegree\ifsameinstitute{#4} %
\pastdegree{#5}\@pastdegree\ifsameinstitute{#5} %
\pastdegree{#6}\@pastdegree}
\else
\ifx$#8$ \gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree\ifsameinstitute{#3} %
\pastdegree{#4}\@pastdegree\ifsameinstitute{#4} %
\pastdegree{#5}\@pastdegree\ifsameinstitute{#5} %
\pastdegree{#6}\@pastdegree\ifsameinstitute{#6} %
\pastdegree{#7}\@pastdegree}
\else
\gdef\@degreelist{\pastdegree{#1}\@pastdegree\ifsameinstitute{#1} %
\pastdegree{#2}\@pastdegree\ifsameinstitute{#2} %
\pastdegree{#3}\@pastdegree\ifsameinstitute{#3} %
\pastdegree{#4}\@pastdegree\ifsameinstitute{#4} %
\pastdegree{#5}\@pastdegree\ifsameinstitute{#5} %
\pastdegree{#6}\@pastdegree\ifsameinstitute{#6} %
\pastdegree{#7}\@pastdegree\ifsameinstitute{#7} %
\pastdegree{#8}\@pastdegree}
\fi\fi\fi\fi\fi\fi\fi
}
\def\@degreelist{\@latex@warning@no@line{No \noexpand\degreelist given}}
\makeatother
\degreelist{{B.A.,},{M.Phil.,H.K.},{Ph.D.,Cantab.}}
\begin{document}
{\@degreelist}
\end{document}
Printout of Post-Nominals
\makeatletter
after\begin{document}
. I think that your point (2) above reflects a confusion but I don't know C so it is hard to be sure. I don't understand what you mean by a macro as opposed to a command. (You say you'd prefer a macro to a command but I'm not familiar with the distinction this refers to.)#define MAX 100
and when you compile, the preprocessor will substitute100
for wherever you wroteMAX
; this makes it easier to adjust. In TeX I don't think there is a distinction between macros and commands, since the way to define a macro in LaTeX is\newcommand
. As I understand it, everything in TeX is a command---the letter "a" in a TeX file is actually a command, "typeset the letter a". Everything that isn't a primitive command is a macro that expands to primitives.