似乎将对 的调用嵌入到\DTLifnullorempty
另一个调用中会导致每次对 的调用都产生额外的空间\DTLifnullorempty
。有没有办法防止这种行为?特别是,我希望以下 MWE 生成一个文档,其中每行与前面的材料之间都有相等的空间AAA
。比较:
\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}
答案1
空格仅出现在您添加它的位置:
\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}