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.

Using the commands of the discussion How to check if a column type is defined? and How to implement a command that checks for loaded packages?

I have build an enviroment to check if more than one column is defined

\documentclass{scrbook}

\usepackage{etoolbox}
\usepackage{ragged2e}
\usepackage{array}

\makeatletter
\newcommand\CheckIfColumntypeDefined[1]{%
  \providebool{tpl@coltype@#1}
  \ifcsdef{NC@find@\string#1}%
    {\setbool{tpl@coltype@#1}{true}}%
    {\ifcsdef{columntype@\string#1}
      {\setbool{tpl@coltype@#1}{true}}%
      {\setbool{tpl@coltype@#1}{false}}%
    }%
}

\newcommand\IfColumntypeDefined[3]{%
  \CheckIfColumntypeDefined{#1}
  \ifboolexpr{ bool{tpl@coltype@#1} }{#2}{#3}%
}

\newcommand{\IfColumntypesDefined}[1]{%
  \@tempswatrue
  \def\do##1{%
    % define \@tempa with trimmed index element.
    \edef\@tempa{\zap@space##1 \@empty}%
    % check if package of current index is loaded
    \IfColumntypeDefined{\@tempa}{}{\@tempswafalse}%
  }%
  % Process csv list with command \do (etoolbox)
  \docsvlist{#1}%
  % ??
  \if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
}
\makeatother

\begin{document}

\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\Centering\arraybackslash\hspace{0pt}}p{#1}}

\IfColumntypeDefined{L}{L is defined}{L is not defined}
\IfColumntypeDefined{C}{C is defined}{C is not defined}

\IfColumntypesDefined{L,C}
{L and C columns are defined}
{L and C columns are not defined}

\end{document}

It however returns always false which I do not understand and do not know how to debug. So the output is

L is defined C is defined

L and C columns are not defined

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I don't see any point in defining \IfColumntypesDefined with a list of column types; however the problem is in the

\IfColumntypeDefined{\@tempa}{}{\@tempswafalse}

line. With

\expandafter\IfColumntypeDefined\expandafter{\@tempa}{}{\@tempswafalse}

you get the correct result. The reason is that \string#1 is used in \CheckIfColumntypeDefined (which is a good thing, because it protects against wrong input).

share|improve this answer

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.