0

I am defining my own bibliographic printouts, to be used with biblatex/biber:

\usepackage[minnames=20,maxnames=60,backend=biber,
            natbib=true,sorting=none]{biblatex}
\addbibresource{thisbiblio.bib}
\newcommand{\articleinfo}[1]{
\citename{#1}{author},
``\textit{\citefield{#1}{title}}'',
\citefield{#1}{journaltitle}
\textbf{\citefield{#1}{volume}},
\citefield{#1}{pages}
(\citefield{#1}{year}). \citefield{#1}{note}
}

The command above (\articleinfo{}) looks for a certain label (argument #1) in a bibtex file (thisbiblio.bib) and, when invoked in the document body, it prints a bunch of info from the bibtex entry's fields. I have a custom field called note, that I want to use to print custom info, for instance "a preprint of this paper is available from [url]". However, I want this to be optional, i.e., print the note field only if it is defined in the bibtex file for this particular entry, otherwise leave it blank. At the moment I get a note printout (like that, in bold face). How can I achieve that?

  • You should declare a new cite command with \DeclareCiteCommand and set field formats appropriately rather than construct things from the \citefield macro. – David Purton Sep 11 at 13:19
  • @DavidPurton This is not meant to be used as the \cite command, but to print bibliographic information in line. – Miguel Sep 11 at 13:24
  • hmmm. Can you provide a full MWE? I think a cite command is still what you want. – David Purton Sep 11 at 13:32
  • This is for a list of publications, so I'm using, e.g., \item \articleinfo{miguel_paper}. I have a bunch of different definitions, for instance if the paper is on arXiv or a regular journal, etc., each printing the info I want to display. – Miguel Sep 11 at 13:38
  • Right, but you can use a new cite command to format things like you want and then you can take advantage of punctuation tracker and \printfield. A citation command can print anything you want. I'll add an answer and see if it does what you want. – David Purton Sep 11 at 13:44
2

Instead of making new commands with \newcommand and \citefield, I suggest making a new cite command. Then you can take advantage of biblatex's punctuation tracker and the \printfield command, which tests if a field is used.

Depending on your exact requirements, you could minimise the code you repeat for your different sorts of articles with booleans and tests if various fields exist.

MWE

\documentclass{article}

\usepackage[minnames=20,maxnames=60,natbib=true,sorting=none]{biblatex}
\addbibresource{biblatex-examples.bib}

% I'm not sure if your field formats should be global or not.
% I've set the article ones globally to match your question.
\DeclareFieldFormat[article]{title}{\mkbibquote{\mkbibemph{#1}}}
\DeclareFieldFormat[article]{journaltitle}{#1}
\DeclareFieldFormat[article]{volume}{\mkbibbold{#1}}
\DeclareFieldFormat[article]{pages}{\mknormrange{#1}}

\DeclareCiteCommand{\articleinfo}
  {\usebibmacro{prenote}}
  {\renewcommand*{\newunitpunct}{\addcomma\space}%
   \usebibmacro{articleinfo}}
  {\multicitedelim}
  {\usebibmacro{postnote}}

\newbibmacro*{articleinfo}{%
  \usebibmacro{author}%
  \newunit
  \usebibmacro{title}%
  \newunit
  \usebibmacro{journal}%
  \setunit*{\addspace}%
  \printfield{volume}%
  \newunit
  \printfield{pages}%
  \setunit{\addspace}%
  \printtext[parens]{\usebibmacro{date}}%
  \setunit{\addperiod\space}%
  \printfield{note}}

\begin{document}
\articleinfo{baez/article}
\end{document}

MWE output

  • Fantastic, thanks so much. They only issue is that I can't use \mknormrange, it may be newer than my Livetex installation, so I changed it to \mkcomprange instead. Thanks again – Miguel Sep 11 at 14:23
  • @Miguel, Yes, I think \mknormrange is a new command. – David Purton Sep 11 at 14:25

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.