1

I have a custom footnote citation command defined by modifying this answer in the following way:

\DeclareCiteCommand{\citejournal}  % to get the journal entry                                                                                  
  {\usebibmacro{prenote}}                                                                                            
  {\usebibmacro{citeindex}%                                                                                          
    \usebibmacro{journal}}                                                                                           
  {\multicitedelim}                                                                                                  
  {\usebibmacro{postnote}}

\newcommand{\cfootcite}[1]{                                                                                          
  \tiny{\citeauthor{#1}, \citetitle{#1}, \citejournal{#1}, \citeyear{#1}}} % to get author, title, journal, year  

which works perfectly for .bib entries that have all those fields.

But now I have a .bib file consisting of many articles, but also some books (ergo without a journal entry) that I want to cite using this command.

How can I make a conditional that checks whether there is a journal entry in the .bib file, and changes the output accordingly?

I have tried playing around with the answers presented in this question, but apparently I am too unfamiliar with conditionals in LaTeX to make it work.

Any help is appreciated.

(I am aware that the simplest solution would be to define two separate commands for articles and books.)

MWI:

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents}{bib.bib}
@article{article,
    author = {Vimes, Samuel},
    title = {The Influence of Species Diversity in the City Watch},
    journal = {Unseen University Non-Magical Journal},
    date = {1988}
}
@book{book,
    author = {Vimes, Samuel},
    title = {How To Be A Good Copper},
    date = {2002}
}
\end{filecontents}

\usepackage[backend=biber,maxcitenames=1,maxbibnames=2,                                                         
giveninits=true]{biblatex}                                                                                      
\bibliography{bib.bib}


% \usepackage{xstring} % for if clause

\DeclareCiteCommand{\citejournal}                                                                                   
  {\usebibmacro{prenote}}                                                                                           
  {\usebibmacro{citeindex}%                                                                                         
    \usebibmacro{journal}}                                                                                          
  {\multicitedelim}                                                                                                 
 {\usebibmacro{postnote}}                                                                                             
\newcommand{\cfootcite}[1]{                                                                                         
  {\tiny{\citeauthor{#1}, \citetitle{#1}, \citejournal{#1}, \citeyear{#1}}}} % to get author, title, journal, year

\begin{document}

Article:\\ \cfootcite{article}

Book:\\ \cfootcite{book}

\end{document}

output of MWI

  • 2
    I strongly recommend not to build up \cite commands from other \cite... commands. Commands defined like \cfootcite usually can't deal with multiple citations (\cfootcite{sigfridsson,nussbaum}) properly and need extra work to process pre- and postnote arguments. Additionally it can get increasingly complicated to get citation tracking and other context-senstive stuff right when you execute several \cite...-like macros at once. Commands like these are better defined with \DeclareCiteCommand. The additional advantage of \DeclareCiteCommand for your case is that ... – moewe Nov 22 '18 at 20:31
  • 2
    ... additional information about the entry is available directly (such as the entry type), which can be used to deal with conditional formatting for entry types directly. Note how Audrey's answer to tex.stackexchange.com/a/29931/35864 uses just one \DeclareCiteCommand and declares everything within that one command. – moewe Nov 22 '18 at 20:32
  • @moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources. – Taunch Nov 23 '18 at 10:56
2

You can use the biblatex command

\ifentrytypes{article}{\usebibmacro{journal}\addcomma\addspace}{} 

in the definition of you auxiliary \citejournal cite command, and remove the comma after \citejournal{#1}.

Thus having

\DeclareCiteCommand{\citejournal}                                                                                   
  {\usebibmacro{prenote}}                                                                                           
  {\usebibmacro{citeindex}%                                                                                         
    \ifentrytype{article}{\usebibmacro{journal}\addcomma\addspace}{}}                                                                                          
  {\multicitedelim}                                                                                                 
 {\usebibmacro{postnote}}  

\newcommand{\cfootcite}[1]{                                                                                         
  {\tiny{\citeauthor{#1}, \citetitle{#1}, \citejournal{#1}\citeyear{#1}}}} 

enter image description here

  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment? – Taunch Nov 23 '18 at 11:02

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.