This is a follow-up to this question: @nameuse as conditional where i asked about how to use \expandafter
if i combine \@nameuse
with \ifx
. However, in my real-life example, i use \relax
as a default value for dynamically assigned csnames. I want to know if these control sequences have a specific value, or if they are default. My naive approach would be something like:
\documentclass{standalone}
\makeatletter
\parindent\z@
\@namedef{blafasel}{\relax}
\begin{document}
\expandafter\expandafter\expandafter\ifx\@nameuse{blafasel}\relax
true
\else
false
\fi
\end{document}
but this doesn't work. In its simplest form it gives "false", but in more complex form (with xmltex, a macro definition, and another ifx-structure around) i get Extra \else
errors. I'd like to understand why that is and what i need to do to make it work.
Bonus: I'd prefer a “plain” solution, i.e. no expl3-syntax or complex packages since i want to be as independent as possible from my code's user's configurations.
EDIT:
Here is the problem i'm facing: I want to store some information of the cells of a table. I'm using David Carlisle's xmltex mechanism to parse html tables. Elements are grabbed and transmitted directly into corresponding tex macros. The necessary counters are incremented at the beginning of every such macro.
In the cell definiton iterate over all cells and use a global macro
\gdef\SetCellProp#1#2{\expandafter\def\csname cell-\the\curtab-\the\currow-\the\curcel-#2\endcsname{#1}}
to store properties like the cells calculated width (content in \mybox
; \@tempdima=\wd\mybox
), its content, and its background-color. E.g., i am in the second table, third row, second column, then the width of that cell (e.g. "12mm") is stored with \SetCellProp{12mm}{width} which "creates" a control sequence named \cell-3-2-2-width
that yields the value "12mm".
Likewise, i have want to store the biggest value for width so far using
\gdef\SetColProp#1#2{\expandafter\def\csname col-\the\curtab-\the\curcel-#2\endcsname{#1}}
The macro that returns that value is defined as
\gdef\GetCurColProp#1{\csname cell-\the\curtab-\the\curcel-#1\endcsname}
Note, that this definition doesn't care about the row i am in. Since i re-count cells each row, i need to decide whether to overwrite the maximum value, or not if it is present at all.
To do so, in each cell, we need to check if
- a maxwidth for the column the current cell is in, is already given
- 2a. if no, make the current cell's width maxwidth for the whole column
- 2b. if yes, look if the value for the current width is larger than maxwidth for the column
- 3a if yes, make that current value the new maxwidth for the while column,
- 3b if no, leave everything as it is.
The part of my cell definition so far looks like:
%% check if maxwidth for the col is already given:
\ifx\csname cell-\the\curtab-\the\curcel-maxidth\endcsname\relax
%% if no, take current width (\@tempdima) as maxwidth
\expandafter\SetColProp\expandafter{\the\@tempdima}{maxwidth}%
\else
%% else check if current width is larger than maxwidth:
\expandafter\@tempdimb\GetCurColProp{maxwidth}%
\ifdim\@tempdimb<\@tempdima
%% if so, reassign maxwidth with curwidth:
\expandafter\SetColProp\expandafter{\the\@tempdima}{maxwidth}%
\fi
\fi
where \curtab
counts the tables, \currow
counts the current row, and \curcel
the number of the cell in the row (gets reset to 1 at the beginning of every row). The aim is to get the maximum width of any column my table has.
I hope that explains my problem a little bit.
> \blafasel=macro://->\relax .//l.9 \show\blafasel
and\relax=\relax.//l.10 \show\relax
show that\relax
and\blafasel
are different for\ifx
. One is a macro expanding to\relax
, the other one is\relax
.\expandafter\expandafter\expandafter\ifx\@nameuse{blafasel}\testrelax
where\testrelax
is\def\testrelax{\relax}
. Or\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\expandafter\ifx\@nameuse{blafasel}\relax
to test not\blafasel
against\relax
, but the expansion of\blafasel
.\ifx
compares the meaning of two tokens without expanding them previously, so\relax
is valid. Of course the comparison will only be true if both tokens expand to\relax
, for instance this code first yieldsfoo is NOT relax
because, obviously,\foo
is not\relax
, it only contains\relax
in its definition. The second comparison yieldsfoo is relax
because you make\foo
an exact copy of\relax
.\csname
s are\relax
by default, so if you had not initialisedblafasel
with\@namedef{blafasel}{\relax}
then\expandafter\expandafter\expandafter\ifx\@nameuse{blafasel}\relax
would have worked.\relax
).