Is there a command that behaves like "\providecommand" but to define a counter or length ?
thank you in advance.
regards,
Yuko
General ⇒ Is there a "providecommand"-like cmd for counter & length?
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Is there a "providecommand"-like cmd for counter & length?
Not in the kernel: you want something like:
Code: Select all
\makeatletter
\newcommand*\providecounter[1]{%
\@ifundefined{c@#1}%
{\@definecounter{#1}}%
{}%
}
\makeatother
Joseph Wright
Re: Is there a "providecommand"-like cmd for counter & lengt
Thanks Joseph Wright,
The counter works well.
I tried to modify your code for the length but it did not work.
Thank you in advance.
regards,
Yuko.
The counter works well.

I tried to modify your code for the length but it did not work.
Thank you in advance.
regards,
Yuko.
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Is there a "providecommand"-like cmd for counter & length?
Well, LaTeX lengths are just TeX skips, so
The extra code here is needed as \@ifundefined needs the name of the new length (for example "mylength") and not the token ("\mylength"). See the same approach in \providecommand.
Code: Select all
\makeatletter
\newcommand*\providelength[1]{%
\begingroup
\escapechar\m@ne
\xdef\@gtempa{\string#1}%
\endgroup
\@ifundefined{\@gtempa}%
{\newskip#1}%
{}%
}
\makeatother
Joseph Wright
Re: Is there a "providecommand"-like cmd for counter & lengt
Thank Joseph Wright,
The code works well.
I am sorry, actually I have one more
I need \providesavebox associated with \newsavebox.
Should I create a new topic for this question?
Thank you in advance.
regards,
Yuko.
The code works well.

I am sorry, actually I have one more

I need \providesavebox associated with \newsavebox.
Should I create a new topic for this question?
Thank you in advance.
regards,
Yuko.