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:
But if I comment out the \DTLloaddb
line (as indicated by the comments in the code), this produces:
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*}
%% --------------------------------------
% https://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}
\@dtl@readline
. I'll get it fixed in the next version ofdatatool
.2013/01/15 v2.13
version ofdatatool
.