[Tex/LaTex] How to check if a biblatex entry contains an author field

biblatexconditionals

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}
\addbibresource{\jobname.bib}

\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}
\addbibresource{\jobname.bib}

\begin{document}

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

\section{\citetitle{gizapyramid}}

\end{document}

Example of desired output

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?

Best Answer

@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}
\addbibresource{\jobname.bib}

\begin{document}



\sectiontitle{bar}

\sectiontitle{gizapyramid}

\end{document}