1

It seems that embedding calls to \DTLifnullorempty inside one another leads to an extra space for each call to \DTLifnullorempty. Is there a way to prevent this behavior? In particular, I would like the following MWE to produce a document where each line has an equal amount of space between AAA and the preceding material. Compare:

enter image description here

\documentclass{article}

\setlength{\parindent}{0pt}

\begin{filecontents*}{test.csv}
One,Two,Three,Four
a,b,c,d
a,b,c,
a,b,,
a,,,
\end{filecontents*}

\usepackage{datatool}
\DTLloaddb{test}{test.csv}

\begin{document}

\section{Undesired output}
\frenchspacing
\DTLforeach*{test}{%
    \One=One,
    \Two=Two,
    \Three=Three,
    \Four=Four%
}{%
    \One\DTLifnullorempty{\Four}{%
        % If \Four is empty
        % Check if \Three is empty
        \DTLifnullorempty{\Three}{%
            % If \Three is empty
            % Check if \Two is empty
            \DTLifnullorempty{\Two}{%
                % If \Two is empty
                .%
            }{%
                % If \Two is not empty
                . \Two.
            }
        }{%
            % If \Three is not empty
            . \Two. \Three.%
        }
    }{%
        % If \Four is not empty
        . \Two. \Three. \Four.%
    }
    AAA\par
}

\section{Desired output}

a. b. c. d. AAA\par
a. b. c. AAA\par
a. b. AAA\par
a. AAA\par

\end{document}
4

The space only appears where you added it:

enter image description here

\documentclass{article}

\setlength{\parindent}{0pt}

\begin{filecontents*}{test.csv}
One,Two,Three,Four
a,b,c,d
a,b,c,
a,b,,
a,,,
\end{filecontents*}

\usepackage{datatool}
\DTLloaddb{test}{test.csv}

\begin{document}

\section{Undesired output}
\frenchspacing
\DTLforeach*{test}{%
    \One=One,
    \Two=Two,
    \Three=Three,
    \Four=Four%
}{%
    \One\DTLifnullorempty{\Four}{%
        % If \Four is empty
        % Check if \Three is empty
        \DTLifnullorempty{\Three}{%
            % If \Three is empty
            % Check if \Two is empty
            \DTLifnullorempty{\Two}{%
                % If \Two is empty
                .%
            }{%
                % If \Two is not empty
                . \Two.%
            }%
        }{%
            % If \Three is not empty
            . \Two. \Three.%
        }%
    }{%
        % If \Four is not empty
        . \Two. \Three. \Four.%
    }
    AAA\par
}

\section{Desired output}

a. b. c. d. AAA\par
a. b. c. AAA\par
a. b. AAA\par
a. AAA\par

\end{document}
  • Ahh ... that's embarrassing. Thanks, David! :P – Adam Liter Feb 18 '15 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.