# How do I check if a biblatex entry contains an author field?

I'm writing a paper on a very large number of pieces of artwork, and I've been trying to automate the creation of my section headings, but I've run into a roadblock when I try to check if a Biblatex author entry actually exists.

I would like to do something like this:

\documentclass{article}

\usepackage[backend=biber]{biblatex}

\newcommand{\sectiontitle}[1]{\section{%
%check for author field in #1 and include "\citeauthor{#1} - " if it exists%
\citetitle{#1}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ARTWORK{gizapyramid,
title = {Pyramids at Gizeh},
location = {Giza, Egypt},
year = {ca.\@ 2500 BCE}
}
@ARTWORK{bar,
title = {A Bar at the Folies-Berg\{e}re},
location = {London, England},
year = {1882},
author = {Manet, \'{E}douard}
}
\end{filecontents}

\begin{document}

\sectiontitle{bar}

\sectiontitle{gizapyramid}

\end{document}


To achieve the same result as this:

\documentclass{article}

\usepackage[backend=biber]{biblatex}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ARTWORK{gizapyramid,
title = {Pyramids at Gizeh},
location = {Giza, Egypt},
year = {ca.\@ 2500 BCE}
}
@ARTWORK{bar,
title = {A Bar at the Folies-Berg\{e}re},
location = {London, England},
year = {1882},
author = {Manet, \'{E}douard}
}
\end{filecontents}

\begin{document}

\section{\citeauthor{bar} - \citetitle{bar}}

\section{\citetitle{gizapyramid}}

\end{document}


However, I'm not sure how to do the check I want to accomplish this. How can I check if the Biblatex author entry actually exists and implement this into my code?

-

@lockstep beat me by a minute or two but this is a bit different perhaps so I post as it may be useful somewhere.

\documentclass{article}

\usepackage[backend=biber]{biblatex}

\makeatletter
\let\foo\blx@getdata@cite
\def\usefoo#1{\expandafter\expandafter\expandafter\@empty\csname abx@field@#1\endcsname}

\newcommand{\sectiontitle}[1]{%
\let\abx@name@author\relax\foo{#1}%
\section{%
\ifx\abx@name@author\relax
\else
\citeauthor{#1} --- %
\fi
\citetitle{#1}}}

\makeatother
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ARTWORK{gizapyramid,
title = {Pyramids at Gizeh},
location = {Giza, Egypt},
year = {ca.\@ 2500 BCE}
}
@ARTWORK{bar,
title = {A Bar at the Folies-Berg\{e}re},
location = {London, England},
year = {1882},
author = {\'{E}douard Manet}
}
\end{filecontents}

\begin{document}

\sectiontitle{bar}

\sectiontitle{gizapyramid}

\end{document}

-

A new citation command \citeauthortitle (modelled after \citetitle) that includes the \ifnameundef test seems to do the trick.

\documentclass{article}

\usepackage[backend=biber]{biblatex}

\DeclareCiteCommand{\citeauthortitle}
{\boolfalse{citetracker}%
\boolfalse{pagetracker}%
\usebibmacro{prenote}}
{\ifciteindex
{\indexfield{indextitle}}
{}%
\ifnameundef{author}{% NEW
}{% NEW
\printnames{labelname}~-- % NEW
}% NEW
\printfield[citetitle]{labeltitle}}
{\multicitedelim}
{\usebibmacro{postnote}}

\newcommand{\sectiontitle}[1]{\section{\citeauthortitle{#1}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@ARTWORK{gizapyramid,
title = {Pyramids at Gizeh},
location = {Giza, Egypt},
year = {ca.\@ 2500 BCE}
}
@ARTWORK{bar,
title = {A Bar at the Folies-Berg\{e}re},
location = {London, England},
year = {1882},
author = {Manet, \'{E}douard}
}
\end{filecontents}

Note: I used \ifnameundef because the author field is regarded a "name list" in biblatex. To test for "literal lists", one should use \iflistundef, for other fields \iffieldundef.