# A symbol table with protection issues

The problem is that at the beginning of table cells, TeX is expanding tokens looking for \omit or \span (for \multicolumn and such), so it expands \ne to \protect\ne␣, and \protect is \relax which (is not expandable so) is left alone and only then the table template is inserted with \collectcell\showSymbol, but at this point \ne is already expanded.

There are several ways you can work around this, but they boil down to either:

1. Look at the expanded \ne (or whatever command) and check that the first token is \protect and typeset the second in that case, or

2. Add something to stop TeX from expanding \ne.

For option 1 you can define \showSymbol like this (MWE 1 below):

\makeatletter
\newcommand\showSymbol[1]{%
\expandafter\ifx\@car#1\@nil\protect\@empty
\expandafter\@showSymbol\expandafter{\@cdr#1\@nil}%
\else
\@showSymbol{#1}%
\fi}
\newcommand\@showSymbol[1]{%
\hbox to 8em{\texttt{\detokenize{#1}}\hss}$#1$}
\makeatother


The line \expandafter\ifx\@car#1\@nil\protect\@empty will \ifx-compare the first token of #1 with with \protect (the \@empty is there for safety), and if so pass the remaining tokens to \@showSymbol. Note that this will pass \ne␣ rather than \ne to be typeset, so you might need to trim the trailing space.

For option 2 (MWE 2 below), quick and dirty, you can prefix \ne with \noexpand. When TeX expands \noexpand, it will temporarily do \let\ne\relax, and then the newly-redefined \ne will stop the expansion (and \ne will be restored to its original meaning). Then, when \collectcell does its job, \ne will be there, safe and sound:

\begin{tabular}{*4M}
\noexpand\ne & \approx & \prec & \preceq \\
<            & \le     & \ll   & \lll    \\
>            & \ge     & \gg   & \ggg    \\
\sim         & \simeq  & \succ & \succeq \\
\end{tabular}


MWE 1:

\documentclass{amsart}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\usepackage[verb]{collcell}

\makeatletter
\newcommand\showSymbol[1]{%
\expandafter\ifx\@car#1\@nil\protect\@empty
\expandafter\@showSymbol\expandafter{\@cdr#1\@nil}%
\else
\@showSymbol{#1}%
\fi}
\newcommand\@showSymbol[1]{%
\hbox to 8em{\texttt{\detokenize{#1}}\hss}$#1$}
\makeatother

\usepackage{array}
\newcolumntype{M}{>{\collectcell\showSymbol}l<{\endcollectcell}}

\begin{document}

\begin{tabular}{*4M}
\ne  & \approx & \prec & \preceq \\
<    & \le     & \ll   & \lll    \\
>    & \ge     & \gg   & \ggg    \\
\sim & \simeq  & \succ & \succeq \\
\end{tabular}

\end{document}


MWE 2:

\documentclass{amsart}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\usepackage[verb]{collcell}
\newcommand\showSymbol[1]{\hbox to 8em{\texttt{\detokenize{#1}}\hss}$#1$}
\usepackage{array}
\newcolumntype{M}{>{\collectcell\showSymbol}l<{\endcollectcell}}

\begin{document}

\begin{tabular}{*4M}
\noexpand\ne & \approx & \prec & \preceq \\
<            & \le     & \ll   & \lll    \\
>            & \ge     & \gg   & \ggg    \\
\sim         & \simeq  & \succ & \succeq \\
\end{tabular}

\end{document}