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.

I would like to automate the use of the following arrays. In the first one, the only arguments which change are \verb!\eqDef!, the commands tested, and A \eqDef B, the visual test.

My problem is that I would like one solution which also allows to use 1, 2, 3 or 4 commands tested ? In the second array, the commands tested are \verb!\eqDef!, \verb!\eqTest!, \verb!\eqVerif! and \verb!\eqId!, and the visual tests are A \eqDef B, A \eqTest B, A \eqVerif B and A \eqId B.

I give one file with the commands proposed in my examples.

One command tested --> Two columns

\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{llll} 
        \textbf{Style}            & \verb!\eqDef!
        \\ \hline
        \verb!\displaystyle!      & \displaystyle      A \eqDef B
        \\
        \verb!\textstyle!         & \textstyle         A \eqDef B
        \\
        \verb!\scriptstyle!       & \scriptstyle       A \eqDef B
        \\
        \verb!\scriptscriptstyle! & \scriptscriptstyle A \eqDef B
    \end{array}
\]

Four commands tested --> Five columns

\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{lllll} 
        \textbf{Style}
        & \verb!\eqDef!                   & \verb!\eqTest!
        & \verb!\eqVerif!                 & \verb!\eqId!
        \\ \hline
        \verb!\displaystyle!
        & \displaystyle      A \eqDef B   & \displaystyle      A \eqTest B
        & \displaystyle      A \eqVerif B & \displaystyle      A \eqId B
        \\
        \verb!\textstyle!
        & \textstyle         A \eqDef B   & \textstyle         A \eqTest B
        & \textstyle         A \eqVerif B & \textstyle         A \eqId B
        \\
        \verb!\scriptstyle!
        & \scriptstyle       A \eqDef B   & \scriptstyle       A \eqTest B
        & \scriptstyle       A \eqVerif B & \scriptstyle       A \eqId B
        \\
        \verb!\scriptscriptstyle!
        & \scriptscriptstyle A \eqDef B   & \scriptscriptstyle A \eqTest B
        & \scriptscriptstyle A \eqVerif B & \scriptscriptstyle A \eqId B
    \end{array}
\]

One functionnal code

% Source : http://tex.stackexchange.com/questions/35404/is-there-a-wider-equal-sign

\documentclass{scrartcl}
    \usepackage{amsmath}
    \usepackage{mathtools}

    \usepackage{graphicx}

    \makeatletter
        \newcommand{\@@eqLikeDef}[3]{%
            \ensuremath{\overset{\mathclap{\text{\scalebox{#1}{#2}}}}{#3}}%
        }
        \newcommand*{\@eqLikeDef}[2]{
            \mathchoice
                {% \displaystyle
                    \@@eqLikeDef{0.7}{#1}{#2}
                }
                {% \textstyle
                    \@@eqLikeDef{0.7}{#1}{#2}
                }
                {% \scriptstyle
                    \@@eqLikeDef{0.6}{#1}{#2}
                }
                {% \scriptscriptstyle
                    \@@eqLikeDef{0.5}{#1}{#2}
                }
        }

        \newcommand*{\eqDef}{\@eqLikeDef{Def}{=}}
        \newcommand*{\eqTest}{\@eqLikeDef{Test}{=}}
        \newcommand*{\eqVerif}{\@eqLikeDef{?}{=}}
        \newcommand*{\eqId}{\@eqLikeDef{Id}{=}}
    \makeatother

\begin{document}

\section{Equality Signs}

\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{lllll} 
        \textbf{Style}
        & \verb!\eqDef!                   & \verb!\eqTest!
        & \verb!\eqVerif!                 & \verb!\eqId!
        \\ \hline
        \verb!\displaystyle!
        & \displaystyle      A \eqDef B   & \displaystyle      A \eqTest B
        & \displaystyle      A \eqVerif B & \displaystyle      A \eqId B
        \\
        \verb!\textstyle!
        & \textstyle         A \eqDef B   & \textstyle         A \eqTest B
        & \textstyle         A \eqVerif B & \textstyle         A \eqId B
        \\
        \verb!\scriptstyle!
        & \scriptstyle       A \eqDef B   & \scriptstyle       A \eqTest B
        & \scriptstyle       A \eqVerif B & \scriptstyle       A \eqId B
        \\
        \verb!\scriptscriptstyle!
        & \scriptscriptstyle A \eqDef B   & \scriptscriptstyle A \eqTest B
        & \scriptscriptstyle A \eqVerif B & \scriptscriptstyle A \eqId B
    \end{array}
\]

\end{document}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I am not sure if I fully understand what is required.

Choose Columns:

If you mean that you want to use the same table data, and selectively choose which columns to print then one way of doing that is to use the collcell package which allows the contents of the table to be passed to a macro. Using this I have defined a macro that takes the data entry and returns an empty string when the S column type is used:

\newcommand*{\SupressEntry}[1]{}%
\newcolumntype{S}{>{\collectcell\SupressEntry}{l}<{\endcollectcell}}%

So, if you want the column printed use the usual l, but if you don't want it printed use L. Here is the output using the \begin{array}{l l l l l}:

enter image description here

and same table with \begin{array}{l l S l S} (i.e., suppress columns 3 and 5): enter image description here

Choose Rows:

If you question is about selecting rows, there are many ways to do that. One way is to use newtoggle from the etoolbox package. For example \newtoggle{ShowDisplayStyle}. Then when you want to enable this row, just set \toggletrue{ShowDisplayStyle} to show this row, but if you want this row suppressed \togglefalse{ShowDisplayStyle}.

Here is the outout with \togglefalse{ShowTextStyle} and \togglefalse{ShowScriptStyle}:

enter image description here

Reuse Table without Repeating Data:

I would also suggest wrapping the data into a macro as I have below with the \TableData macro to make it less error prone.

Code:

\documentclass[border=2pt]{standalone}
    \usepackage{amsmath}
    \usepackage{mathtools}
    \usepackage{collcell}
    \usepackage{etoolbox}
    \usepackage{graphicx}

    \newcommand*{\SupressEntry}[1]{}%
    \newcolumntype{S}{>{\collectcell\SupressEntry}{l}<{\endcollectcell}}%

    \newtoggle{ShowDisplayStyle}
    \newtoggle{ShowTextStyle}
    \newtoggle{ShowScriptStyle}
    \newtoggle{ShowScriptScriptStyle}

    % Chose which ones are printed:
    \toggletrue{ShowDisplayStyle}
    \toggletrue{ShowTextStyle}
    \toggletrue{ShowScriptStyle}
    \toggletrue{ShowScriptScriptStyle}


    \makeatletter
        \newcommand{\@@eqLikeDef}[3]{%
            \ensuremath{\overset{\mathclap{\text{\scalebox{#1}{#2}}}}{#3}}%
        }
        \newcommand*{\@eqLikeDef}[2]{
            \mathchoice
                {% \displaystyle
                    \@@eqLikeDef{0.7}{#1}{#2}
                }
                {% \textstyle
                    \@@eqLikeDef{0.7}{#1}{#2}
                }
                {% \scriptstyle
                    \@@eqLikeDef{0.6}{#1}{#2}
                }
                {% \scriptscriptstyle
                    \@@eqLikeDef{0.5}{#1}{#2}
                }
        }

        \newcommand*{\eqDef}{\@eqLikeDef{Def}{=}}
        \newcommand*{\eqTest}{\@eqLikeDef{Test}{=}}
        \newcommand*{\eqVerif}{\@eqLikeDef{?}{=}}
        \newcommand*{\eqId}{\@eqLikeDef{Id}{=}}
    \makeatother

\newcommand{\Label}[1]{\texttt{\textbackslash#1}}%
\newcommand{\TableData}{%
        \textbf{Style}
        & \Label{eqDef}                   & \Label{eqTest}
        & \Label{eqVerif}                 & \Label{eqId}
        \\ \hline
    \iftoggle{ShowDisplayStyle}{
        \Label{displaystyle}
        & \displaystyle      A \eqDef B   & \displaystyle      A \eqTest B
        & \displaystyle      A \eqVerif B & \displaystyle      A \eqId B
        \\
    }{}
    \iftoggle{ShowTextStyle}{
        \Label{textstyle}
        & \textstyle         A \eqDef B   & \textstyle         A \eqTest B
        & \textstyle         A \eqVerif B & \textstyle         A \eqId B
        \\
    }{}
    \iftoggle{ShowScriptStyle}{
        \Label{scriptstyle}
        & \scriptstyle       A \eqDef B   & \scriptstyle       A \eqTest B
        & \scriptstyle       A \eqVerif B & \scriptstyle       A \eqId B
        \\
     }{}
     \iftoggle{ShowScriptScriptStyle}{
       \Label{scriptscriptstyle}
        & \scriptscriptstyle A \eqDef B   & \scriptscriptstyle A \eqTest B
        & \scriptscriptstyle A \eqVerif B & \scriptscriptstyle A \eqId B
        \\
     }{}
}
\begin{document}

\section{Equality Signs: All Styles and Commands}
\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{l l l l l} 
        \TableData
    \end{array}
\]

\section{Equality Signs: Only Columns 3 and 5}
\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{l l S l S} 
        \TableData
    \end{array}
\]

\section{Equality Signs:Only textstyle and scriptstyle Commands}
    \togglefalse{ShowTextStyle}
    \togglefalse{ShowScriptStyle}
\[
    \renewcommand{\arraystretch}{1.2}%
    \begin{array}{l l l l l} 
        \TableData
    \end{array}
\]
    \toggletrue{ShowTextStyle}
    \toggletrue{ShowScriptStyle}

\end{document}
share|improve this answer
    
You may also use @ egreg's answer or @ MartinScharrer's comment in Easiest way to delete a column? that does not require the collcell package - that is, LaTeX provides boxing capability by default. Regardless, I like your approach to keep the entire structure and filter columns. –  Werner Nov 20 '11 at 16:43
    
@Peter Grill: thanks. Indeed, I would like to have the possibilty to change what I've called arguments in my question. I'll adapt your proposition to do one command with one to four arguments which are each couples of arguments (nameOfTheCommand, textUsedForTest). It would not be hard. –  projetmbc Nov 20 '11 at 19:53

Your Answer

 
discard

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

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