How to switch to math mode for a whole ROW of a tabular or to text mode for a whole ROW of an array?

For the second case (make the whole row math) you can do something in spirit of the first answer in Format whole row of table as bold:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx}
\newcommand\setrow[1]{\gdef\rowmac{\begin{#1}}\gdef\erowmac{\end{#1}}\begin{#1}\ignorespaces}
\newcommand\clearrow{\global\let\rowmac\relax \global\let\erowmac\relax}
\clearrow

\begin{document}
Or the first row to math here:
\begin{center}
\begin{tabular}{*{13}{>{\rowmac}c<{\erowmac}}>{\rowmac}c<{\erowmac\clearrow}}
\setrow{math} \dfrac{17}{91} &\dfrac{78}{85} & \dfrac{19}{51} &
\dfrac{23}{38} & \dfrac{29}{33} & & & & & & & & & \dfrac{55}{1} \\[10pt]
A & B & C & D & E & F & G & H & I & J & K & L & M & N \\
\setrow{bf}A & B & C & D & E & F & G & H & I & J & K & L & M & N \\
\end{tabular}   
\end{center}
\end{document}

produces

enter image description here


The following enables you to specify a command which's argument should be the content of each cell of the row for this it uses collcell. I also specified the two column types e and E both taking one argument which should be the column type to which the effects should be applied. E should be the last column in a row which should be affected as it resets the definition.

With this approach you can use amsmath's \text in an array or \ensuremath in a tabular to achieve both goals.

I created a macro \setrowC which takes a command as its argument and a \setrowE which takes an environment as its argument. They both work on the e and E type columns.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tabularx}
\def\setrowC#1#2&{%
  \gdef\rowmac{#1}\rowmac{#2}&}
\def\setrowE#1#2&{%
  \gdef\rowmac##1{\begin{#1}##1\end{#1}}%
  \rowmac{#2}&}
\newcommand*\clearrow{%
  \global\let\rowmac\relax}
\clearrow

\usepackage{collcell}
\newcolumntype{e}[1]{>{\collectcell\rowmac}#1<{\endcollectcell}}
\newcolumntype{E}[1]{e{#1}<{\clearrow}}

\begin{document}
Or the first row to math here:
\begin{center}
  \begin{tabular}{*{13}{e{c}}E{c}}
\setrowC{\ensuremath} \dfrac{17}{91} &\dfrac{78}{85} & \dfrac{19}{51} &
\dfrac{23}{38} & \dfrac{29}{33} & & & & & & & & & \dfrac{55}{1} \\[10pt]
A & B & C & D & E & F & G & H & I & J & K & L & M & N \\
\setrowE{bf}A & B & C & D & E & F & G & H & I & J & K & L & M & N \\
\end{tabular}   
\end{center}
\[
  \begin{array}[]{e{c}E{c}}
    \setrowC{\text} text & text\\
    \frac{5}{4} & \frac{4}{5}
  \end{array}
\]
\end{document}

If you want to have a \setrow with a starred and unstarred version, you can use the following (neither the builtin \@ifstar nor xparse did work so I defined \myifstar):

\def\setrow#1{%
  \myifstar{#1}%
    {\setrowE}%
    {\setrowC{#1}}%
  }
\makeatletter
\def\myifstar#1{%
  \if*#1
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}
\makeatother