# Error arising when using \typeout & \meaning with \midrule

In order to facilitate debugging some experimental code, I created a version of \typeout that will break its content into multiple lines:

%% dummy macro for simulating newlines in output to terminal
\def\my@linefeed{}
\def\mytypeout#1\my@linefeed#2\@nil{%%
\typeout{\detokenize{#1}}%%
% \typeout{\meaning#1}%%
\expandafter\ifx\expandafter\relax\detokenize{#2}\relax\else
\mytypeout#2\@nil
\fi}


I would use it as follows:

\mytypeout ==> A testing mytypeout on its own\my@linefeed
==> B testing mytypeout on its own\my@linefeed
==> C testing mytypeout on its own\my@linefeed
==> D testing mytypeout on its own\my@linefeed
==> E testing mytypeout on its own\my@linefeed
==> F testing mytypeout on its own\my@linefeed\@nil


my \mytypeout{...} seemed to work fine until I started using it in conjunction with booktabs.

The following MWE compiles:

\documentclass{article}
\usepackage{booktabs}
\usepackage{etoolbox}
\usepackage{pgffor}

\makeatletter
%%\let\my@linefeed\relax%% --> raises errors!
%% dummy macro for simulating newlines in output to terminal
\def\my@linefeed{}
\def\mytypeout#1\my@linefeed#2\@nil{%%
\typeout{\detokenize{#1}}%%
% \typeout{\meaning#1}%%
\expandafter\ifx\expandafter\relax\detokenize{#2}\relax\else
\mytypeout#2\@nil
\fi}

%% \spaces added to make \typeout more readable
\def\my@row@of@table{%%
First column matter \space
&
\expandonce\x \space
\noexpand\\
%% Neither \meaning nor \detokenize raise an error
%% if this next line is commented out
% \noexpand\midrule
\noexpand\my@linefeed
}

\def\full@agenda{}
\def\build@agenda{%%
\foreach \x in \list@of@agenda@items {%%
\xdef\full@agenda{%%
\expandonce\full@agenda
\my@row@of@table}%%
\expandafter\mytypeout\full@agenda\my@linefeed\@nil
\typeout{---DONE----}%%
}}

\def\setagenda#1{%%
\bgroup
\def\list@of@agenda@items{#1}%%
\build@agenda
\begin{tabular}{cl}
\toprule
\full@agenda
\bottomrule
\end{tabular}%%
\egroup
\def\full@agenda{}}

\makeatother
\begin{document}

\setagenda{
{A Line of random content},
{B Not too involved math: $x\cdot y$ },
{C Some more random text.},
{D Random },
{E Hello world},
{F no more}
}

\end{document}


If I uncomment the line

  % \noexpand\midrule


then in order to get the above MWE to compile, I had to change the definition of \mytypeout. Namely, I had to change

\typeout{\meaning#1}


to

\typeout{\detokenize{#1}}


I can't quite figure out what's going on here. I tried isolating the error by testing the following code

%% No problems with \typeout + \meaning in either of the next two examples:
%% example #1
\def\aetemp{\midrule}
\typeout{TEMP(A):\meaning\aetemp}
%% example #2
\def\aetemp{\noexpand\midrule}
\typeout{TEMP(B):\meaning\aetemp}


But I didn't get any errors.

What's happening here? What am I missing?

• I think I get what's going on here. I think the problem is that \meaning works on one token. Instead I'm applying \meaning to #1 which is a sequence of tokens. – A.Ellett Oct 27 '13 at 6:25
• Moderators, should I keep this question posted? Or is this too localized? – A.Ellett Oct 27 '13 at 6:31
• I am not a moderator, but vote for keep it open – I have learned something from it. I'd suggest to add an answer. – Daniel Oct 27 '13 at 7:43
• If you want sensible answers, you should make an example that shows the error, or give precise instructions for modifying the presented code. If I leave \noexpand\midrule commented and uncomment the \typeout{\meaning#1} line I get several errors. – egreg Oct 27 '13 at 10:13
• @egreg I see what you mean. I had tried improving the answer and in the process didn't notice that I broke the code either way you went with \typeout{\meaning#1) and \noexpand\midrule. – A.Ellett Oct 27 '13 at 14:58

If I add \showtokens{#1} in the definition of \mytypeout, just before the \typeout, I get, for the first call,

> First column matter  & A Line of random content \\ .
\mytypeout ...@linefeed #2\@nil ->\showtokens {#1}
\typeout {\detokenize {#1}...
l.62     }


This clearly means that \meaning#1 is completely out of place, because it would just act on F, with an expansion such as

The character F


So \typeout{\meaning#1} is definitely not what you want. You can use \meaning, but like

  \begingroup\def\next{#1}%
\typeout{\expandafter\strip@prefix\meaning\next}%%
\endgroup


This will give as output

First column matter  & A Line of random content \\
First column matter  & B Not too involved math: $x\cdot y$  \\
First column matter  & C Some more random text. \\
First column matter  & D Random  \\
First column matter  & E Hello world \\
First column matter  & {F no more}  \\


which of course is no different from what you get with the \detokenize version.