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.

I am getting spurious blank spaces inserted upon loading a dtltool db.

The MWE below produces links to all the image files named with a prefix the same as the .tex file:

enter image description here

But if I comment out the \DTLloaddb line (as indicated by the comments in the code), this produces:

enter image description here

Note that the indentation increases as the number of files being linked to increases. Even with zero matches (as is the case for the A.tex file), there is still an indentation.

I suspect that this is related to an earlier problem of mine where I was seeing a Spurious blank space when adding a member to a database within \foreach. I tried to use added an \unskip whenever I invoke \AddMemberToDB, but that does not help in this case.

Bonus Question:

  • This is not really TeX related, but how do I change the invocation of ls such that the error messages such as the following are not displayed in the console.

    ls: B-*.pdf: No such file or directory

    I had this working with a discussion in the chat room, but started to break in my real use case.

Code:

\documentclass{article}
\usepackage{datatool}
\usepackage{xparse}
\usepackage{xstring}
\usepackage{tikz}
\usepackage{showframe}
\usepackage{hyperref}

%% -------------------------------------- Create the necessary files
%% Four .tex files:
\begin{filecontents*}{A.tex}
\end{filecontents*}

\begin{filecontents*}{B.tex}
\end{filecontents*}

\begin{filecontents*}{C.tex}
\end{filecontents*}

\begin{filecontents*}{D.tex}
\end{filecontents*}

% No .png file associated with A

% One image file associated with B
\begin{filecontents*}{B-1.png}
\end{filecontents*}

% Two image files associated with C
\begin{filecontents*}{C-1.png}
\end{filecontents*}
\begin{filecontents*}{C-2.jpg}
\end{filecontents*}

% Three image files associated with D
\begin{filecontents*}{D-1.png}
\end{filecontents*}
\begin{filecontents*}{D-2.png}
\end{filecontents*}
\begin{filecontents*}{D-3.jpg}
\end{filecontents*}
%% -------------------------------------- 


% http://tex.stackexchange.com/questions/51854/dtldeletedb-from-datatool-package-has-no-effect-within-foreach
%
%  Usage: Use \DTLgdeletedb instead of \DTLdeletedb
\makeatletter
\newcommand*{\DTLgdeletedb}[1]{%
  \DTLifdbexists{#1}{%
    \dtlforeachkey(\@dtl@key,\@dtl@col,\@dtl@type,\@dtl@head)\in{#1}\do
    {%
      \global\expandafter\let\csname dtl@ci@#1@\@dtl@key\endcsname\undefined
    }%
    \global\expandafter\let\csname dtldb@#1\endcsname\undefined
    \global\expandafter\let\csname dtlkeys@#1\endcsname\undefined
    \global\expandafter\let\csname dtlrows@#1\endcsname\undefined
    \global\expandafter\let\csname dtlcols@#1\endcsname\undefined
  }{%
    \PackageError{***** Error: Can't delete database `#1':
       database doesn't exist}{}{}%
  }%
}
\makeatother



\newcommand{\AddLinkToFile}[3][black]{%
    %#1 = text color
    %#2 = file to open upon clicking
    %#3 = text to display
    %
    \href{run:#2}{\protect\textcolor{#1}{#3}}%
}%


\newcommand{\ListAllAssociatedImageFilesOfTypeInCSV}[3][\jobname.ImageDB]{%
    % #1 = temp file name
    % #2 = dir        
    % #3 = file extension
    \immediate\write18{%
        ls -1 #2#3 %
        | grep -v "No such file or directory" %
        | sort -f%
%       >&2 % List ALL files
        > ./#1% Store in given file name 
    }%
}%


\newcounter{NumRowElements}
\newcommand*{\NumberOfElementsBeforeLinebreak}{2}
\newcommand*{\ListOfImageFileTypes}{jpg,png,pdf}

\begin{document}
    \setcounter{NumRowElements}{0}%
    \par\noindent%
    \foreach \x in {A,...,D}{%
        \DTLifdbexists{ImageDB}{\DTLgdeletedb{ImageDB}}{}%
        \ListAllAssociatedImageFilesOfTypeInCSV[\jobname.ImageDB]
                {\x}{-*.{\ListOfImageFileTypes}}%
        % If comment out the following \DTLloaddb, the no additional indentation
        \DTLloaddb[noheader,keys={FileName}]{ImageDB}{\jobname.ImageDB}%
        %------------------------------------------------------------
        \makebox[4.0cm][l]{%
            \AddLinkToFile[red]{\x.tex}{\x}%
            \hspace*{1.0ex}%
            \DTLifdbexists{ImageDB}{%
                \DTLifdbempty{ImageDB}{%
                    % no associated image files found.
                }{%
                    \DTLforeach{ImageDB}{\ImageFile=FileName}{%
                        \hspace*{1.0ex}%
                        \AddLinkToFile[gray]{\ImageFile}{\ImageFile}%
                    }%
                }%
            }{}%
        }%
        % Add a new line if we are at the appropriate multiple
        \stepcounter{NumRowElements}%
        \IfEq{\arabic{NumRowElements}}{\NumberOfElementsBeforeLinebreak}{%
            \setcounter{NumRowElements}{0}%
            \par\noindent%
        }{}%
    }%
\end{document}
share|improve this question
    
I forgot to comment out an EOL character in \@dtl@readline. I'll get it fixed in the next version of datatool. –  Nicola Talbot Dec 9 '12 at 14:17
    
This problem has been fixed in 2013/01/15 v2.13 version of datatool. –  Peter Grill Jan 20 '13 at 5:43

1 Answer 1

up vote 3 down vote accepted

Here's a patch until the next version:

\makeatletter
\renewcommand*{\@dtl@readline}[2]{%
  \read#1 to #2%
  \ifdefempty{#2}%
  {%
  }%
  {%
    \dtl@trim#2%
  }% <- added comment character
}
\makeatother

(You can track the progress of the bug with my bug tracker.)

share|improve this answer
    
So, this is different than the problem discovered in Spurious blank space when adding a member to a database within \foreach. It seems that \let\Old@dtl@updatekeys\@dtl@updatekeys \renewcommand*{\@dtl@updatekeys}[3]{\Old@dtl@updatekeys{#1}{#2}{#3}\unskip} also works so thought that perhaps that was related. –  Peter Grill Dec 10 '12 at 0:42
    
@PeterGrill It's a different problem but the same basic cause (a missing percent character at the end of a line). The problem with \@dtl@updatekeys was fixed in v2.11, so Werner's patch in your link is no longer required. (I tried neatening up the code in datatool.sty to make it easier to read, but I think I must've missed commenting some EOL characters. Hopefully that's the last one!) –  Nicola Talbot Dec 10 '12 at 8:40

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.