Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to check if an argument is an empty string

538 views
Skip to first unread message

Marko Pinteric

unread,
Dec 4, 2002, 6:53:34 AM12/4/02
to
I want to redefine @makecaption to behave differently if specified
caption is empty or non-empty.
So I started command like this:

\long\def\@makecaption#1#2{%
\def\temptyA{#2}%
\ifx\temptyA\empty
....
\else
.....
\endif}

However, even if I use \caption{} (value of caption is passed by #2),
the ifx command is never true. Why?

Thanks for the answer,

Marko.

David Kastrup

unread,
Dec 4, 2002, 8:03:23 AM12/4/02
to
Marko Pinteric <marko.p...@uni-mb.si> writes:

I don't believe you, so you better give some more code. You are
probably goofing up with bracing levels (braced delimited arguments
get their braces stripped on macro calls, so you have to add them
again at each level).

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>

Marko Pinteric

unread,
Dec 4, 2002, 8:22:55 AM12/4/02
to
The problem seems to be in the fact that parameter from \caption is
passed to
\makecaption as {\ignorespaces #1} (at least, maybe there is even more
passing on of parameter). So even if \caption{} is specified, the
actual parameter to makecaption is something like {\ignorespaces
{ignorespaces {{}}}}. How can I get rid of all those brackets and
\ignorespaces , get simply {}and compare that to \empty?

Thanks

David Kastrup

unread,
Dec 4, 2002, 9:24:30 AM12/4/02
to
Marko Pinteric <marko.p...@uni-mb.si> writes:

> The problem seems to be in the fact that parameter from \caption is
> passed to
> \makecaption as {\ignorespaces #1} (at least, maybe there is even more
> passing on of parameter). So even if \caption{} is specified, the
> actual parameter to makecaption is something like {\ignorespaces
> {ignorespaces {{}}}}. How can I get rid of all those brackets and
> \ignorespaces , get simply {}and compare that to \empty?

Too complicated. Just compare to a macro set to whatever will result
from an empty argument instead of comparing to \empty.

Marko Pinteric

unread,
Dec 4, 2002, 12:38:15 PM12/4/02
to David Kastrup
David Kastrup wrote:

>Marko Pinteric <marko.p...@uni-mb.si> writes:
>
>
>
>>The problem seems to be in the fact that parameter from \caption is
>>passed to
>>\makecaption as {\ignorespaces #1} (at least, maybe there is even more
>>passing on of parameter). So even if \caption{} is specified, the
>>actual parameter to makecaption is something like {\ignorespaces
>>{ignorespaces {{}}}}. How can I get rid of all those brackets and
>>\ignorespaces , get simply {}and compare that to \empty?
>>
>>
>
>Too complicated. Just compare to a macro set to whatever will result
>from an empty argument instead of comparing to \empty.
>
>
>

How can I know what is "whatever will result from an empty argument".
Is it possible to make
LaTeX to display that precisely?

Thanks, Marko.

Marko Pinteric

unread,
Dec 4, 2002, 12:44:13 PM12/4/02
to David Kastrup
David Kastrup wrote:

>Marko Pinteric <marko.p...@uni-mb.si> writes:
>
>
>
>>The problem seems to be in the fact that parameter from \caption is
>>passed to
>>\makecaption as {\ignorespaces #1} (at least, maybe there is even more
>>passing on of parameter). So even if \caption{} is specified, the
>>actual parameter to makecaption is something like {\ignorespaces
>>{ignorespaces {{}}}}. How can I get rid of all those brackets and
>>\ignorespaces , get simply {}and compare that to \empty?
>>
>>
>
>Too complicated. Just compare to a macro set to whatever will result
>from an empty argument instead of comparing to \empty.
>
>
>

Marko Pinteric

unread,
Dec 4, 2002, 12:43:50 PM12/4/02
to David Kastrup
David Kastrup wrote:

>Marko Pinteric <marko.p...@uni-mb.si> writes:
>
>
>
>>The problem seems to be in the fact that parameter from \caption is
>>passed to
>>\makecaption as {\ignorespaces #1} (at least, maybe there is even more
>>passing on of parameter). So even if \caption{} is specified, the
>>actual parameter to makecaption is something like {\ignorespaces
>>{ignorespaces {{}}}}. How can I get rid of all those brackets and
>>\ignorespaces , get simply {}and compare that to \empty?
>>
>>
>
>Too complicated. Just compare to a macro set to whatever will result
>from an empty argument instead of comparing to \empty.
>
>
>

Michael Barr

unread,
Dec 4, 2002, 4:06:15 PM12/4/02
to
David Kastrup <David....@t-online.de> wrote in message news:<x5ptsho...@lola.goethe.zz>...

> Marko Pinteric <marko.p...@uni-mb.si> writes:
>
> > The problem seems to be in the fact that parameter from \caption is
> > passed to
> > \makecaption as {\ignorespaces #1} (at least, maybe there is even more
> > passing on of parameter). So even if \caption{} is specified, the
> > actual parameter to makecaption is something like {\ignorespaces
> > {ignorespaces {{}}}}. How can I get rid of all those brackets and
> > \ignorespaces , get simply {}and compare that to \empty?
>
> Too complicated. Just compare to a macro set to whatever will result
> from an empty argument instead of comparing to \empty.

What I found worked is in this code fragment:
\def\domorphism(#1,#2)|#3|/#4/<#5,#6>[#7`#8;#9]{%
\def\next{#4}%
\ifx\next\empty\relax

The \relax seems to be necessary for it to work properly. But I could
never find any procedure that invariably worked to find if an argument
was empty or expanded to \empty and this group couldn't either.
Replacing \def by \xdef usually worked until the day arrived that #4
was a matrix and then it bombed completely, choked on the ampersands.

David Kastrup

unread,
Dec 4, 2002, 4:49:52 PM12/4/02
to
Marko Pinteric <marko.p...@uni-mb.si> writes:

> David Kastrup wrote:
>
> >>The problem seems to be in the fact that parameter from \caption is
> >>passed to
> >>\makecaption as {\ignorespaces #1} (at least, maybe there is even more
> >>passing on of parameter). So even if \caption{} is specified, the
> >>actual parameter to makecaption is something like {\ignorespaces
> >>{ignorespaces {{}}}}. How can I get rid of all those brackets and
> >>\ignorespaces , get simply {}and compare that to \empty?
> >>
> >
> >Too complicated. Just compare to a macro set to whatever will result
> >from an empty argument instead of comparing to \empty.
> >
> >
> How can I know what is "whatever will result from an empty
> argument". Is it possible to make
> LaTeX to display that precisely?

Well, you said it above, but if you explicitly want it, \show\macro
will show the definition of \macro.

David Kastrup

unread,
Dec 4, 2002, 4:53:27 PM12/4/02
to
ba...@barrs.org (Michael Barr) writes:

Uh, what?

Anyhow, inside of alignments strange things can happen. Enclosing
the critical stuff that could contain & signs into
\ifnum`{=\z@\fi ... \ifnum`}=\z@\fi
should do the trick.

Robin Fairbairns

unread,
Dec 4, 2002, 6:41:45 PM12/4/02
to
Marko Pinteric <marko.p...@uni-mb.si> writes:
>How can I know what is "whatever will result from an empty argument".

you can only do that by experimentation -- for example:

\def\temp{#1}%
\typeout{argument: \expandafter\strip@prefix\meaning\temp}%

(between \makeatletter..\makeatother), or by reading the code -- see
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=ltxcmds

> Is it possible to make
>LaTeX to display that precisely?

what do you mean? a latex macro that tells you what mangling gets
applied by the macros enclosing where it's called from? nah, silly.
--
Robin Fairbairns, Cambridge -- the man with no voice (_again_)

David Kastrup

unread,
Dec 4, 2002, 7:35:18 PM12/4/02
to
r...@cl.cam.ac.uk (Robin Fairbairns) writes:

> Marko Pinteric <marko.p...@uni-mb.si> writes:
> >How can I know what is "whatever will result from an empty argument".
>
> you can only do that by experimentation -- for example:
>
> \def\temp{#1}%
> \typeout{argument: \expandafter\strip@prefix\meaning\temp}%

Oh, come on, the \strip@prefix trick is when you need to further
process the output in TeX's bowels. For just outputting them,
\toks@{#1}%
\typeout{argument: \the\toks@}%
will work fine.

> (between \makeatletter..\makeatother),

Ah yes, or write \toks0 instead of \toks@

Michael J Downes

unread,
Dec 5, 2002, 11:53:05 AM12/5/02
to
Marko Pinteric <marko.p...@uni-mb.si> writes:

> The problem seems to be in the fact that parameter from \caption is
> passed to
> \makecaption as {\ignorespaces #1} (at least, maybe there is even more
> passing on of parameter). So even if \caption{} is specified, the
> actual parameter to makecaption is something like {\ignorespaces
> {ignorespaces {{}}}}.

I ran into the same problem when working on "amsart" document class.
That is why the amsart definition of \@makecaption applies \@cdr:

\long\def\@makecaption#1#2{%
%
% Measure the contents of the caption. If \arg{2} is not
% empty, then we must add a period and an en-space before
% typesetting it. The \cs{@caption} macro adds an extra
% \cn{ignorespaces} at the beginning of \arg{2}, so in order
% to find out if the user-typed portion is empty we use
% \cs{@cdr} to pull off the \cn{ignorespaces}.
...
\@xp\@ifnotempty\@xp {\@cdr#2\@nil}%
{.\@captionfont\upshape\enspace#2}%

\@xp is an amsart shorthand for \expandafter and \@ifnotempty is a
special test that treats " " as equivalent to empty.

Because removing the first \ignorespaces seemed to be enough in
ordinary use, I never tried to handle more complicated possibilities.

PS. I don't recommend the amsart \@makecaption code as a good example
for anyone to follow :-) Some of the techniques I tried to apply were
ill-advised. But perhaps this little piece may be useful.

Marko Pinteric

unread,
Dec 5, 2002, 4:49:23 PM12/5/02
to Michael J Downes

Thank you for your answer. But since I am not a tex expert, how would
my problem be sloved without special shorthands and functions of amsart?
Especially, I would also like to do something with "else" case.

Thanks, Marko

Marko Pinteric

unread,
Dec 5, 2002, 4:52:45 PM12/5/02
to Michael J Downes

Thank you for your answer. But since I am not a tex expert, how would
my problem be sloved without special shorthands and functions of amsart?
Especially, I would also like to do something with "else" case.

Thanks, Marko

0 new messages