4

The MWE adds blank space proportional to the maximum value of the \foreach iteration:

enter image description here

Why is this and how do I eliminate this additional space?

Note:

  • This problem seems similar to an earlier issue I had earlier in Text being output when none should be, but I don't know how to resolve this issue.
  • I am guessing this is some sort of expansion related issue as \dtlexpandnewvalue is required to get the correct output from the database.

Code:

\documentclass{article}

\usepackage{pgffor}
\usepackage{datatool}
\usepackage{showframe}

\newcommand*{\InitalizeDB}[1]{% 
    \DTLifdbexists{#1}%
        {\DTLcleardb{#1}}% DB exists, so just clear it
        {\DTLnewdb{#1}}%   DB does not exist, so create it
}%
\newcommand*{\AddMemberToDB}[3]{%
    % #1 = name of DB
    % #2 = db key to be used
    % #3 = member to be added to DB
    \dtlexpandnewvalue%
    \DTLnewrow{#1}%
    \DTLnewdbentry{#1}{#2}{#3}%
}%



\begin{document}
\InitalizeDB{MyDB}
\noindent
abc%
\foreach \x in {2,...,7} {%
    \AddMemberToDB{MyDB}{MyDBKey}{\x}%
}%
def

\bigskip\noindent
Database:\par
\DTLdisplaydb{MyDB}
\end{document}
2

1 Answer 1

4

The macro \@dtl@updatekeys defines \@defl@dogetprops via an \edef and doesn't insert % at the end of the line, causing the unwanted skip:

\newcommand*{\@dtl@updatekeys}[3]{%
  \@sDTLifhaskey{#1}{#2}%
  {%
    \expandafter\dtlcolumnnum\expandafter
      =\dtlcolumnindex{#1}{#2}\relax
    \edef\@dtl@dogetprops{\noexpand\@dtl@getprops
      {\noexpand\@dtl@key}{\noexpand\@dtl@type}%
      {\noexpand\@dtl@colhead}{\noexpand\@dtl@before}%
      {\noexpand\@dtl@after}{\the\csname dtlkeys@#1\endcsname}%
      {\number\dtlcolumnnum}}% <--------- inserted '%'
    \@dtl@dogetprops
    %...
}

Since \@dtl@updatekeys is quite large, issuing \unskip after you've added a member (either part of \AddMemberToDB or within the \foreach) solves the problem.

enter image description here

\documentclass{article}

\usepackage{pgffor}% http://ctan.org/pkg/pgf
\usepackage{datatool}% http://ctan.org/pkg/datatool
\usepackage{showframe}% http://ctan.org/pkg/showframe

\newcommand*{\InitalizeDB}[1]{% 
    \DTLifdbexists{#1}%
        {\DTLcleardb{#1}}% DB exists, so just clear it
        {\DTLnewdb{#1}}%   DB does not exist, so create it
}%
\newcommand*{\AddMemberToDB}[3]{%
    % #1 = name of DB
    % #2 = db key to be used
    % #3 = member to be added to DB
    \dtlexpandnewvalue%
    \DTLnewrow{#1}%
    \DTLnewdbentry{#1}{#2}{#3}%
}%

\begin{document}
\InitalizeDB{MyDB}
\noindent
abc%
\foreach \x in {2,...,7} {%
    \AddMemberToDB{MyDB}{MyDBKey}{\x}\unskip%
}%
def

\bigskip\noindent
Database:\par
\DTLdisplaydb{MyDB}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .