COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### About define a macro with multi-value style arguement.

• Follow

```I don't know if I've stated the problem clearly.

You know , with keyval related packages, we can define a macro with
{key=value} style arguement.
Now, I want to define a macro which takes the following form:
for instance,
\mvcmd{{some text1}, {some text 2},{},{some text 3},,,,}
as if each pair of {} would be added "key=" before it, so we can
process each value between the curly brackets {} orderly, if it's not
empty.

Maybe this problem seems somewhat strange, however, I still hope that
there's somebody can give any suggests or a little hints. Thanks a lot.
```
 0
Reply rockyzhz (6) 12/27/2009 4:19:52 PM

```On Dec 27, 4:19=A0pm, Rocky Zhang <rocky...@gmail.com> wrote:
> I don't know if I've stated the problem clearly.
>
> You know , with keyval related packages, we can define a macro with
> {key=3Dvalue} style arguement.
> Now, I want to define a macro which takes the following form:
> for instance,
> \mvcmd{{some text1}, {some text 2},{},{some text 3},,,,}
> as if each pair of {} would be added "key=3D" before it, so we can
> process each value between the curly brackets {} orderly, if it's not
> empty.
>
> Maybe this problem seems somewhat strange, however, I still hope that
> there's somebody can give any suggests or a little hints. Thanks a lot.

Perhaps you could use \@for from the LaTeX kernel to iterate over each
comma-separated value?

\newcommand*\mvcmd[1]{%
\@for\mv@temp:=3D#1\do{%
% Whatever you want to do with each comma-separated item
}%
}

It might help to know what you are actually trying to achieve. Could
you explain what the idea actually is?
--
Joseph Wright
```
 0

```Rocky Zhang <rockyzhz@gmail.com> wrote:

> I don't know if I've stated the problem clearly.
>
> You know , with keyval related packages, we can define a macro with
> {key=value} style arguement.
> Now, I want to define a macro which takes the following form:
> for instance,
> \mvcmd{{some text1}, {some text 2},{},{some text 3},,,,}
> as if each pair of {} would be added "key=" before it, so we can
> process each value between the curly brackets {} orderly, if it's not
> empty.

It's not entirely clear to me. If you want to process comma separated
lists, then \@for of LaTeX's kernel already can this.
Or you can use package `kvsetkeys', section "1.7 Comma separated
lists".

Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
```
 0

```On 12=D4=C228=C8=D5, =C9=CF=CE=E71=CA=B154=B7=D6, Joseph Wright <joseph.wri=
....@morningstar2.co.uk>
wrote:
> On Dec 27, 4:19 pm, Rocky Zhang <rocky...@gmail.com> wrote:
>
> > I don't know if I've stated the problem clearly.
>
> > You know , with keyval related packages, we can define a macro with
> > {key=3Dvalue} style arguement.
> > Now, I want to define a macro which takes the following form:
> > for instance,
> > \mvcmd{{some text1}, {some text 2},{},{some text 3},,,,}
> > as if each pair of {} would be added "key=3D" before it, so we can
> > process each value between the curly brackets {} orderly, if it's not
> > empty.
>
> > Maybe this problem seems somewhat strange, however, I still hope that
> > there's somebody can give any suggests or a little hints. Thanks a lot.
>
> Perhaps you could use \@for from the LaTeX kernel to iterate over each
> comma-separated value?
>
> \newcommand*\mvcmd[1]{%
>   \@for\mv@temp:=3D#1\do{%
>     % Whatever you want to do with each comma-separated item
>   }%
>
> }
>
> It might help to know what you are actually trying to achieve. Could
> you explain what the idea actually is?
> --
> Joseph Wright

Actually, this is just an part of the idea which is to mock the style
of a Mankiw's book <Principles of Economics>. On the every
chapter titlepage of that book, there's a panel consists of some
color blocks, varying the number by the given sentences which
are the keypoints of that chapter.

So, I just want to use these sentences to determine the number
of color blocks. Your hints and the help of Heiko Oberdiek make
this come to realized. This feather can loosen the constraint of
user That's so great! Thanks a lot!

The basic purpose of doing such a work is to make the format of
typesetting depart from the content. So that we can simply change
a header file to get the totally different style of the book, without
change the commands used in the common 'book' document class.
For example, to redifined the section command, we can realized
another style of section title even with a color frame. This can
make us generate different version of our books or articles, the plain
one is for print, another is for electronic reading. In a words, it's
just a book template with high compatibility.:-)

Thank you for your help. Also many thanks go to Heiko Oberdiek,
the command \comma@normalize is so amazing!

Best regards,
Rocky Zhang
```
 0

3 Replies
168 Views

Similiar Articles:

7/21/2012 5:36:34 PM