1

Is it possible to have definitions take effect at the beginning of the first cell of a tabular row (using array.sty, if relevant), and still leave room for \multicolumn, \hline, etc.? The problem is, of course, that these commands begin with \omit, which gets upset by anything having been put into the cell already.

I've been able to hack around the issue (by using globals and simulating scopes, or by creating my own multicolumn command), but I'm wondering if there's some simple, non-hacky way of doing this? Intuitively, it seems to me that there's no real call for concern about there having been a definition earlier in the cell, as that doesn't use the formatting that isn't being changed…?

I'm aware that there cannot be contents before \omit, and, yes, in general you'd want to put stuff inside a \multicoumn, for example – but what I'm specifically after here is specifically placing the definitions before \omit. (If that isn't possible in any way, I have other, less satisfying solutions :-)

My thought was that perhaps there was something similar to \use_none:n that would actually perform the definition, but not leave any tokens in the input stream – perhaps by applying \exp_args:No to \use_none:n to perform the definition.

Here's an MWE:

\documentclass{article}
\usepackage{array, expl3}

\begin{document}

\ExplSyntaxOn

% % Problem with \omit
% \begin{tabular}{ll}
%     Goodbye, & cruel \\
%     \tl_set:Nn \l_mlh_place_tl {World}
%         \multicolumn{2}{l}{\l_mlh_place_tl}
% \end{tabular}
%
% % No definition happens
% \begin{tabular}{ll}
%     Goodbye, & cruel \\
%     \use_none:n { \tl_set:Nn \l_mlh_place_tl {world} }
%         \multicolumn{2}{l}{\l_mlh_place_tl}
% \end{tabular}

% Still no definition happens
\begin{tabular}{ll}
    Goodbye, & cruel \\
    \exp_args:No \use_none:n { \tl_set:Nn \l_mlh_place_tl {world} }
        \multicolumn{2}{l}{\l_mlh_place_tl}
\end{tabular}

\ExplSyntaxOff

\end{document}
  • why not simply \multicolumn{2}{>{\def\l_mlh_place_tl{world}}{\l_mlh_place_tl} ? – David Carlisle Apr 5 at 9:56
  • That's one of the less satisfying solutions :-) The definitions are part of user configurations performed locally by a redefined line break command, and I want the user to be able to use, say, \midrule or the like without having things break down. – Magnus Lie Hetland Apr 5 at 10:00
  • if you defined it as a new column type say L then you could use L at the top and \multicolumn{2}{L} and your custom command is inserted at the start of every cell. – David Carlisle Apr 5 at 10:04
  • Yes, I've used that solution, too. But the preamble is also user-configurable, and I'd like to keep it as simple as possible. I also have other solutions, including simulating my own scope stack (to avoid globals), and performing the definitions at the end of the previous line (as part of the redefined cr) – so, as is so often the case here on TeX SE, the specific MWA isn't the whole picture. I can solve the problem, but I'm wondering specifically about removing the imprint of definitions, so they can be put, e.g., at the beginning of the first cell of a row. – Magnus Lie Hetland Apr 5 at 10:07
  • But I am also interested in solving the problem this is motivated by, for sure, so thanks for the suggestions! I'm trying to figure out which way to go with this. I have a couple of implementations, but I'm trying different ways of cleaning it up, and the functionality I'm asking for would make one path more appealing. But maybe it's just a pipe dream :-) – Magnus Lie Hetland Apr 5 at 10:10
1

If you do not mind global definitions and you are at the start of a line you can use

\noalign{\gdef\l_mlh_place_tl {world}}

but to get before a general \multicolumn mid row you need to work harder, perhaps

enter image description here

\documentclass{article}
\usepackage{array}

\begin{document}



\begin{tabular}{|l|l|l|}
  1&2&3\\
    Goodbye, & cruel &zzz\\
   $\rightarrow$      &
  \omit
   \def\zzz{WORLD}%
    \bgroup\def\omit{\egroup}%
    \multicolumn{2}{l|}{\zzz}
\end{tabular}



\end{document}
  • Global definitions would have solved the problem on their own, for me – and are what I'm trying to work around. (Otherwise, I could just place the definitions before the line break.) The redefinition of \omit, and using \bgroup/\egroup to limit it, is really clever! And it'll work for \multicolumn, specifically, but not for other, similar things like, say, \hline and \midrule. (Note that in my motivating application, I don't need this mid-row, BTW.) – Magnus Lie Hetland Apr 5 at 10:40
  • But, as you said, it requires global definitions (which is what I'm trying to avoid), no? – Magnus Lie Hetland Apr 5 at 12:31
  • @MagnusLieHetland sorry I misread your comment yes \noalign is a group:-) (I will delete my comment above) – David Carlisle Apr 5 at 13:31
  • No worries! Thanks for the input, anyway :-) I may end up combining several of these ideas, but it seems I may still have to use global definitions, and keep track of a stack of them myself, or something. (I could swear I recently saw a package that did something like that, but I haven't been able to find it again. Oh, well.) – Magnus Lie Hetland Apr 5 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.