0

Based on 2 former questions I have found another problem, I am not aware about that this could be a problem.

Question 1: Conditional complex column type

Question 2: Generic table definitions

But I failed. If I call the command once, everything is fine. Maybe there is some bug in the tablespecification command?

\documentclass{scrreprt}

\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[utf8]{inputenc} % Uses the utf8 input encoding

\usepackage{graphicx} % Required for including images
\usepackage{booktabs,array,ragged2e,multirow,colortbl}
\usepackage[table]{xcolor}
\usepackage{datatool}
\usepackage{longtable} % can be commented out, approach is an very generic method of tablespec


\providecommand{\conta}{\xspace\RIGHTarrow\xspace}
\newcolumntype{M}[1]{>{\hspace{0pt}\raggedright\arraybackslash}m{#1}}
\newcolumntype{Z}[9]{
      !{\color{#6}\vrule width #4 #7}
      >{\ifnum\pdfstrcmp{#2}{left}=0 \raggedright\arraybackslash \fi
        \ifnum\pdfstrcmp{#2}{center}=0 \centering\arraybackslash \fi
        \ifnum\pdfstrcmp{#2}{right}=0 \raggedleft\arraybackslash \fi
        \ifnum\pdfstrcmp{#2}{zero}=0 \fi
        \columncolor{#3}
        }
        p{#1 #8}
      !{\color{#6}\vrule width #5 #7}
    }


\makeatletter
\newcommand{\settablespec}[2]{%
  \toks@={}%
  \@tfor\next:=#2\do{ 
    \toks@=\expandafter{\the\expandafter\expandafter\expandafter\toks@\next} 
  } 
  \edef#1{\the\toks@} 
}
\newcommand{\tablebegin}[2]{ 
  \def\next{\begin{#1}} 
  \expandafter\next\expandafter{#2} 
}
\makeatother

    \xdefinecolor{mywhite}{rgb}{1,1,1}
    \xdefinecolor{myblack}{rgb}{1,1,1}



    \FPupn{vlinedistance}{0.2}
    \FPupn{hlinedistance}{0.2}
    \FPupn{outerlinedistance}{0.00}

\begin{document}


 \providecommand{\hlttextacs}{2.2}
 \providecommand{\hlttextbcs}{2.3}
 \providecommand{\hlttextccs}{2.2}
 \providecommand{\bheaderalacs}{left}
 \providecommand{\bheaderalbcs}{center}
 \providecommand{\bheaderalccs}{right}

    \providecommand{\AAastart}{}
    \providecommand{\AAasingle}{}
    \providecommand{\AAb}{}
    \providecommand{\AAc}{}
    \providecommand{\AAbend}{}
    \providecommand{\AAcend}{}


\renewcommand{\AAastart}{Z{\hlttextacs}{\bheaderalacs}{myblack}{\outerlinedistance}{0}{myblack}{em}{cm}{text}}
\renewcommand{\AAasingle}{Z{\hlttextacs}{\bheaderalacs}{myblack}{\outerlinedistance}{\outerlinedistance}{myblack}{em}{cm}{text}}
\renewcommand{\AAb}{Z{\hlttextbcs}{\bheaderalbcs}{myblack}{\vlinedistance}{0}{myblack}{em}{cm}{text}}
\renewcommand{\AAc}{Z{\hlttextccs}{\bheaderalccs}{myblack}{\vlinedistance}{0}{myblack}{em}{cm}{text}}
\renewcommand{\AAbend}{Z{\hlttextbcs}{\bheaderalbcs}{myblack}{0}{\outerlinedistance}{myblack}{em}{cm}{text}}
\renewcommand{\AAcend}{Z{\hlttextccs}{\bheaderalccs}{myblack}{0}{\outerlinedistance}{myblack}{em}{cm}{text}}


\providecommand{\mytablespec}[1]{
 \ifnum#1=1%
    \settablespec{\mytablespec}{%
        \AAasingle%
        }%
        \else%
        \fi%
 \ifnum#1=2%
    \settablespec{\mytablespec}{%
        \AAastart%
        \AAbend%
        }%
        \else%
        \fi%
 \ifnum#1=3%
    \settablespec{\mytablespec}{%
        \AAastart%
        \AAb%
        \AAcend%
        }%
        \else%
        \fi%
 }%


\mytablespec{2}  

\def\mytabletype{longtable}

\tablebegin{\mytabletype}{\mytablespec}
            A & CC \tabularnewline
            $D$ & DD
\end{\mytabletype}

\mytablespec{2}  


\def\mytabletype{longtable}
\tablebegin{\mytabletype}{\mytablespec}
        \specialrule{0.00em}{0.0em}{\hlinedistance em}%
A & B \tabularnewline
C & D  
\end{\mytabletype}

\end{document}

Question 1: Does anybody can see the bug? Question 2: Is there any resource for a deeper understanding of tex code which is recommended to study?

  • If you redefine a command \mytablespec, you cannot also continue to use it with its old definition. After you've done \mytablespec{2} once, you overwrite the definition and cannot use it in this way again. Now, it just contains the stuff for the table specification. I think. This seems excessively complicated. It is hard to believe this is a good approach since it will be extremely difficult for you to maintain code like this, won't it? – cfr Jan 16 '16 at 04:39
  • @cfr calling \settablespec{\mytablespec}{% \AAasingle% }% directly wont have this effect. I can call this more than once... but if I hide this sequence in a Macro, it wont... Thanks for your reference. – Peter Ebelsberger Jan 16 '16 at 12:14
  • Seems to me, that there will be no answer. – Peter Ebelsberger Feb 09 '16 at 18:14
  • When you say calling it once works fine, are you sure? There are easier ways to draw two black rectangles than this! – cfr Feb 09 '16 at 23:53
  • It works fine for me when I don't overwrite the macro. As I say, if you redefine \mytablespec, you can't continue using it with its old definition as well. – cfr Feb 10 '16 at 00:02