CSV 列が空の場合は何もしない -- これを実現するにはどうすればよいですか?

CSV 列が空の場合は何もしない -- これを実現するにはどうすればよいですか?

MWE (実際には完全に MWE ではありませんが、この方法の方が何が起こるかがわかりやすいと思います):

\documentclass{article}
\usepackage{csvsimple}
\usepackage{graphicx}

\begin{document}
\setlength\unitlength{1cm}

\csvreader[head to column names]{jobname2.csv}{}{%
\vfill
\artist

\includegraphics[height=37mm]{\filenameone}

\includegraphics[height=37mm]{\filenametwo}

\comment
}
\end{document}

の内容jobname2.csv

artist,filenameone,filenametwo,comment
Foo,example-image-a,example-image-b,Nothing
Foobar,example-image-a,,Something

列に何もない場合はfilenametwo、何も実行したくありません (これを適切に表現する方法がわかりません)。

答え1

csvsimple\ifcsvstrequal{X}{Y}{equal}{not equal}は、2 つのパラメータとが等しいかどうか (基本的には 2 つの -ed トークン リスト) に応じて条件付きでコードを実行するXマクロY\ifx提供します。次の\edefような追加パッケージを必要とせずに、このマクロを例で使用できます。xstring

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.csv}
artist,filenameone,filenametwo,comment
Foo,example-image-a,example-image-b,Nothing
Foobar,example-image-a,,Something
Bar,,example-image-b,Anything
\end{filecontents*}

\usepackage{csvsimple}
\usepackage{graphicx}

\begin{document}
\setlength\unitlength{1cm}

\csvreader[head to column names]{\jobname.csv}{}{%
\vfill
\artist

\ifcsvstrequal{\filenameone}{}{(no first image)}{%
    \includegraphics[height=37mm]{\filenameone}
}
\ifcsvstrequal{\filenametwo}{}{(no second image)}{%
    \includegraphics[height=37mm]{\filenametwo}
}

\comment
}
\end{document}

ここに画像の説明を入力してください

関連情報