# Expansion Issue with omit list provided to \DTLdisplaydb

In my DB the number of columns is rather large. Hence, I am trying to eliminate any columns which contain only 0 entries.

The number of columns, nor the column keys, are know upfront. So, I step through the DB and generate a list of columns that are to be omitted. When I do that the omit list provided seems to be ignored. Below I have omitted the code that determines which columns are

There are no problems for the case of:

• Manually specified omit list: So \DTLdisplaydb[A,C]{myDB} works fine.

• Omit list specified by a macro that has fixed content: So

\def\ListOfColumnsToOmit{A,C}
\DTLdisplaydb[\ListOfColumnsToOmit]{myDB}


also works fine.

Only for the case where I compute the list of columns to omit and add them to \ListOfColumnsToOmit via the \AddToCommaSeparateList macro do things break.

So, the correct result would be that the last table was identical to the two middle tables.

## Code:

\documentclass{article}
\usepackage{xstring}
\usepackage{datatool}

% Make csv for question
\usepackage{filecontents}
\begin{filecontents*}{MyData.csv}
A, B, C, D, E
0, 1, 0, 2, 3
0, 0, 0, 4, 4
0, 2, 0, 0, 5
\end{filecontents*}

\makeatletter
% #1 = separator
% #2 = listname
% #3 = content to add to CSV list
%
% Extra brace group in case #3 contains a comma
\begingroup\edef\x{\endgroup%
}%
\makeatother

\begin{document}

With \emph{no} omit list provided:\par
\noindent\DTLdisplaydb{myDB}%

With manually specified omit list:\par
\noindent\DTLdisplaydb[A,C]{myDB}%

\def\ListOfColumnsToOmit{A,C}
With fixed macro  omit list:\par
\noindent\DTLdisplaydb[\ListOfColumnsToOmit]{myDB}%

\def\ListOfColumnsToOmit{}
With generated macro omit list:\par
\noindent\DTLdisplaydb[\ListOfColumnsToOmit]{myDB}%

The omit list was: \ListOfColumnsToOmit
\end{document}

-
Wow, 22 days without an expansion related question from me. Must be a new record. :-) –  Peter Grill Dec 22 '12 at 0:38

The expansion of \ListOfColumnsToOmit in the last case is

{A},\space {C}


which is obviously wrong. Even omitting the \space, which serves no purpose, the additional braces don't allow datatool to recognize the column names.

If I use

\newcommand*{\AddToCommaSeparateList}[3][,]{%
% #1 = separator
% #2 = listname
% #3 = content to add to CSV list

Hmmm.. Well it is obviously wrong only in this case - has been working great when I want to typeset the list.. So I guess I'll define in starred variant which does not add the \space, and the extra brace group. –  Peter Grill Dec 22 '12 at 2:36