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

xkeyval macro vs argument declaration

0 views
Skip to first unread message

Mathieu G

unread,
Jul 23, 2008, 2:34:07 PM7/23/08
to
Hello,

In the following example why is the column declaration troublesome
through the xkeyval macro, yet not via an argument declaration?
I'm afraid this has to do with expansion or so... and then I have no
idea how to correct that!

Can you help me please?

Best regards,

Mathieu

\documentclass{article}
\usepackage[latin1]{inputenc}% LaTeX source encoding
\usepackage[T1]{fontenc}% Font encoding
\usepackage{caption,floatrow,booktabs,array,longtable,multirow,tabularx}%
Tools for tables
\usepackage{xkeyval,lipsum}
\begin{filecontents}{File.tex}
\toprule
\textbf{Column A}
&\textbf{Column B}
&\centering \textbf{Column C}
\tabularnewline
\midrule
Cell A1
&Cell B1
&Cell C1\newline\lipsum[2]
\tabularnewline
Cell A2
&Cell B2
&Cell C2\newline\lipsum[2]
\tabularnewline
\bottomrule
\end{filecontents}
\begin{document}
\makeatletter%
\define@cmdkeys[MG]{table}{%
,defcolumns%
}%
\presetkeys[MG]{table}{%
,defcolumns={}%
}{}%
\newcommand*{\InsTab}[2]{%
\setkeys[MG]{table}{#1}%
\floatsetup[tmpset]{capposition=top}%
\begin{table}%
\floatbox[\nocapbeside]{table}[\textwidth]%
{\caption{\lipsum[2]}\label{table-label}}%
{%
\begin{tabularx}{\textwidth}{\cmdMG@table@defcolumns}%
% \begin{tabularx}{\textwidth}{#2}%
\@@input File.tex%
\end{tabularx}%
}%
\end{table}%
}%
\makeatother%
\InsTab{defcolumns=ccX}{ccX}
\end{document}

Joseph Wright

unread,
Jul 23, 2008, 2:51:16 PM7/23/08
to

Expansion is the issue. The easiest approach here seems to be to ensure
that \cmdMG@table@defcolumns is expanded before
\begin{tabularx}{\textwidth} is looked at. So for example:

{\def\@tempa{\begin{tabularx}{\textwidth}}
\expandafter\@tempa\expandafter{\cmdMG@table@defcolumns}%


% \begin{tabularx}{\textwidth}{#2}%
\@@input File.tex%
\end{tabularx}%
}%
\end{table}%
}%
\makeatother%
\InsTab{defcolumns=ccX}{ccX}
\end{document}

--
Joseph Wright

Heiko Oberdiek

unread,
Jul 23, 2008, 3:01:28 PM7/23/08
to
Mathieu G <elloc...@free.fr> wrote:

> In the following example why is the column declaration troublesome
> through the xkeyval macro, yet not via an argument declaration?
> I'm afraid this has to do with expansion or so...

Yes, the column declaration must be given explicitely, not hidden
in a macro.

> \begin{tabularx}{\textwidth}{\cmdMG@table@defcolumns}%

\begingroup
\edef\process@me{\endgroup
\noexpand\begin{tabularx}{\noexpand\textwidth}%
{\cmdMG@table@defcolumns}%
}%
\process@me

* \edef expands, \noexpand prevent expansion inside \edef.
* The only purpose of the group is that the definition of
\process@me is thrown away after use. (Prevent name clashes.)

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Mathieu G

unread,
Jul 23, 2008, 3:21:38 PM7/23/08
to
Again thank you!
Your two "different" solutiosn brought some light on my understanding of
expansion!
Best regards,
Mathieu
0 new messages