2

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

1 Answers1

1

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).

egreg
  • 1,121,712