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

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

• Email
• 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

See related articles to this posting

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
184 Views

Similar Articles

12/15/2013 9:32:00 AM
page loaded in 67029 ms. (0)

Similar Artilces:

why not define ACE_HAS_SIGNAL_SAFE_OS_CALLS macro as default value in Unix/Linux?
Hi, all: ACE VERSION: 5.2 HOST MACHINE and OPERATING SYSTEM: P3 1G, Redhad 7.2 I found that ACE don't define ACE_HAS_SIGNAL_SAFE_OS_CALLS macro as default value in Unix/Linux's config-*.h files, so the os call such as select() will fail when interrupted by a signal. I wonder why not define this macro as default value ? Thanks Buding ...

Re: macro variable holding more than one value
On Sat, 19 Jun 2004 15:04:26 -0400, Anbu Arasu <aarumugam@STTHOMAS.EDU> wrote: >Ok. >I have only one macro variable that is created in Proc SQL. > >%macro runit(name); >proc sql; >select count(*) into :nObs, '&name' into :fullName from tab1; >quit; > >%mend runit; > >%runit(John); >%runit(Smith); > >data _null_; >if &nObs >0 then; >put "My full name is : &fullName"; >run; > >output expected: >My full name is John Smith > >oupput I got: >Smith > >Sorry for not being clear. Now I th...

macro to define other macros

Re: Macros: how to add one macro's value into the text of a second macro?
> data _null_; > set nonzeroskew; > call symput ('skewd',skewness); your mistake is that mvar Skewd does not exist -- or does not have the value you want -- until the next step: i.e., after the 'run' statement. unless you want to use this value elsewhere the fix below does not require this mvar allocation, so you can remove/delete the above. > call symput ('nonzeroskew' > ,"The skewness of the non-zero observations is &skewd"); > run; *mvars have values here/now; concatenate your value of skewness in symput: call symput ('nonzero...

Re: Can a macro define a macro?
Pascal Costanza wrote: > For example, why don't you just write this? > > (defun powersn (x n) > (loop for i from to n collecting (expt x i))) Rejected by SBCL: ; in: LAMBDA NIL ; (LOOP FOR I FROM TO N ; COLLECTING (EXPT X I)) ; ; caught ERROR: ; (in macroexpansion of (LOOP FOR I ...)) ; (hint: For more precise location, try *BREAK-ON-SIGNALS*.) ; unknown LOOP keyword: N ; current LOOP context: N COLLECTING. Clojure: (defn powersn [x n] (map #(Math/pow x %) (range 1 (inc n)))) WJ wrote: > Pascal Costanza wrot...

Defining field value to exist when not other value
I have a text field definition that I need to make either one value or another. When the record is created, I want it to be value 1, when the user changes it with a single checkbox option it should change to value 1. If the user unticks the checkbox the value should switch back to value 1. Simple concept, but how is this implemented in Filemaker? I've set the auto-enter data field to value 1. When I change the checkbox to value 2 then what happens is that both value 1 and value 2 are contained in the field instead of just value 2. Some help on the above will be very much appreciated. H...

#define macro to enclose an older macro with strings
Hey people, i'll try to keep this short ;) Here is what I want to type (or at least close too)... #define VER_BUILD 1 #define STR_VER_BUILD "VER_BUILD" But what happends is the preprocessor see the quots in STR_VER_BUILD and replaces that text with "VER_BUILD"... I need it to see the VER_BUILD and replace it with 1, and only after doing that replacement enclose the 1 in quots... I tried using a number sign without any luck (number sign in a macro that takes params encloses the next param in quots). #define VER_BUILD 1 #define THING_T...

How to supply macro value to macro in proc sql
Guys I am doing something like this for my table, I was under the impression that all the macros generated nature is Character then why is this I am getting an error could anybody can explain it. 87 proc sql noprint; 88 select count(itt) into : total 89 from d_header ; 90 select '(N='!!&total!!')' into : atotal 91 from d_header ; ERROR: Concatenation (||) requires character operands. 92 93 %put value of &total ; value of 161 94 %put value of &atotal ; value of N = 161 95 quit; Hi, The macro variables are just text. That is not wh...

getting commas into a macro-defining-macro expansion
I'm trying to write a macro-defining-macro in order to put a nice facade on top of my CL-to-R gateway. In particular, I'd like to be able to say (def-r-call r-plot (plot sequence) (xlab "") ylab) and have this expand into the following macro definition: (defmacro r-plot (sequence &rest rest &key (xlab "") ylab &allow-other-keys) (r plot ,sequence :xlab ,xlab :ylab ,ylab ,@(remove-plist rest :xlab :ylab))) I'm pretty close, but I can't quite seem to get it. Right now, I have (defmacro def-r-call ((macro-name...

Re: How to have macro variable the input value into the macro code
if you have your list of zip codes in a data set you can use list processing via SQL to generate calls of your macro for each zipcode instance check our most excellent archives: http://www.listserv.uga.edu/archives/sas-l.html search for: 'list processing' substring search: [X] subject contains: author's address: RJF2 since: Jan 2000 until: Ron Fehd the macro maven CDC Atlanta GA USA RJF2@cdc.gov > -----Original Message----- > From: Duck-Hye Yang [mailto:dyang@CHAPINHALL.ORG] > Sent: Friday, April 02, 2004 3:28 PM > To: SAS-L@LISTSERV.UGA...

Re: How to have macro variable the input value into the macro code
Another possibility is a DATA step incorporating a CALL EXECUTE statement. But you (Duckhye) will still have 300 separate result files. Is that satisfactory? If not, consider a second macro to wrap a loop around the existing macro, with an added PROC APPEND step to accumulate the results in one place. But that's kind of klunky. Consider reworking the existing macro to run against a vector of Zip codes rather than a single code. Typically this involves using (or extending the use of) BY group processing. If you posted your macro, it would be easier to make specific suggestions. If the m...

Re: How to compare a macro variable with a certain value in a macro program? #2
> From: Harry Droogendyk > I wonder if the specification of quotes might confuse a > newbie. There's no need, and may be good reasons not to, > wrap macro literals in quotes. IMHO the following is > probably a better way to go: > > %if &mvar eq string %then .... ; ah, Harry, yes, that is a good place to start however, it took me only two complete 8-hour daze twelve years ago to learn to dQuote certain strings: %macro StateName1(state=); %IF &State eq AL %then Alabama; %else %IF &State eq OR %then Oregon; %Mend; %Put %StateName1(state=AL); %Put %StateN...

Re: Macros that return values in specified macro variables #3 1540930
Hi Richard, Another alternative with macros like you present, NOT containing any SAS code, only macro code, is to return the value of RC as the result of the macro call. Thus in your macro code at the end just specify: &RC /* without semicolon */ and remove the RC argument from the parameter list; and call your macro by: %LET RC = %attrc (data=foo.bar, lib=libname, mem=memname); Se a.o. http://listserv.uga.edu/cgi-bin/wa?A2=ind0310C&L=sas-l&P=R13877 Regards - Jim. -- .. . . . . . . . . . . . . . . . Jim Groeneveld, MSc. Biostatistician Science Team...

macro design help for open style if-exists and if-does-not-exist style functions
To comp.lang.lisp, I find myself writing functions which take keyword parameters which automatically setup restart bindings to handle errors. An example within the CLHS is the function open: http://www.lispworks.com/documentation/HyperSpec/Body/f_open.htm. For a trivial example, take inserting an element into a set. (defun insert-value-into-set (set value &key (if-exists :error))) Now the default for this function (i.e. (eql if-exists :error)) is to signal an error that has a number of restarts available to it: 1. overwrite Remove the existing value and replace it with the give...

Re: Macro will execute if macro variable contains some value #5
Summary: Macro variable initialization problem. #iw-value=1 Kuladeep, You had a number of little errors in your code that prevented me from executing your code. After they were fixed, I made one change that I suspect accounts for the error. Since the NOT_RECEIVED data set is empty, the variable NOT_RECEIVED must be initialized. However, I agree with Richard that it is better to test with %LENGTH, and with Jim that generating stray semicolons is very dangerous. Here is my executable code. data not_received; input INITIATIVE_ID ; cards; ; run; PROC SQL NOPRINT; %let ...

Re: Macros that return values in specified macro variables #3 624792
> From: Richard A. DeVenezia [mailto:radevenz@IX.NETCOM.COM] > Sometimes a macro has to return a status value to the caller > so the caller can make a decision. Typically the status > value is some sort of error code, other times, the value is > one of several that get set by the macro. Yes, this is a major problem. The solution is to either write the macro as a function so that the usage is: %Let Value = %attrc(data = X ,lib = work ); in which case attrc has %local parameter ReturnValue and ends with &ReturnValue.%Mend; or pass the...

Re: Defining SAS-macros in config- or autoexec-file + sharing macros between platforms
> From: Jesper Sahner > What is the exact difference between defining your macros in > the SAS-config file like this: > > -SET SASAUTOS ( > "!sasroot\core\sasmacro" .... > "!sasext0\stat\sasmacro" > "!sasext0\webhound\sasmacro" > ) > > - or defining the macros in the autoexec-file like this: > > filename x1 '...'; > filename x2 '...'; > options sasautos=(x1 x2 sasautos); no major access difference that's not what I use because I want m...

Re: Macro [ab]usage (was: (OT) old style macro is still working) #2 #7
Don't forget the elegant macro-based access to the dictionary meta-data with SQL Select Into - functionality only accessible via SAS Macro. Paul Choate DDS Data Extraction (916) 654-2160 -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Paul M. Dorfman Sent: Monday, June 14, 2004 10:52 AM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Macro [ab]usage (was: (OT) old style macro is still working) Quentin McMullen, in part wrote: > So to rename a group of variables, I can code: > > data b; > set a (rename=(%rename(x y z,prefix=_))); run...

Re: Macro [ab]usage (was: (OT) old style macro is still working) #2 #8
Roger DeAngelis <xlr82sas@AOL.COM> wrote [in part]: > I asked for it and I got it. Toyota? :-) > . . . . . > However: > > I have had problems with 'call execute'. Who hasn't? > I tend to stay away from 'call execute'. It seems that it does not always > handle large amounts of code as well as the macro language. I think that everyone who has used CALL EXECUTE() on massive data sets has found that it does have limitations. Of course, so do nested formats, macro recursion, you name it. There have been a number of threads on this topic in SAS-...