對 \DTLifnullorempty 的間距和嵌入調用

對 \DTLifnullorempty 的間距和嵌入調用

似乎將呼叫嵌入到\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}

相關內容