Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

%% `\space`s 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?

share|improve this question
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.