9

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?

7

@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}
12

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

\begin{document}

\sectiontitle{bar}

\sectiontitle{gizapyramid}

\end{document}

enter image description here

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.