biblatex - custom citation with conditional clause











up vote
1
down vote

favorite












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










share|improve this question


















  • 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
    yesterday






  • 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
    yesterday












  • @moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
    – Taunch
    16 hours ago















up vote
1
down vote

favorite












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










share|improve this question


















  • 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
    yesterday






  • 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
    yesterday












  • @moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
    – Taunch
    16 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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










share|improve this question













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







biblatex conditionals






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









Taunch

9810




9810








  • 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
    yesterday






  • 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
    yesterday












  • @moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
    – Taunch
    16 hours ago














  • 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
    yesterday






  • 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
    yesterday












  • @moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
    – Taunch
    16 hours ago








2




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
yesterday




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
yesterday




2




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
yesterday






... 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
yesterday














@moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
– Taunch
16 hours ago




@moewe Thanks for the recommendation, I had noticed that it was misbehaving when trying to cite multiple sources.
– Taunch
16 hours ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













You can use the biblatex command



ifentrytypes{article}{usebibmacro{journal}addcommaaddspace}{} 


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}addcommaaddspace}{}}
{multicitedelim}
{usebibmacro{postnote}}

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


enter image description here






share|improve this answer























  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
    – Taunch
    16 hours ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461307%2fbiblatex-custom-citation-with-conditional-clause%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













You can use the biblatex command



ifentrytypes{article}{usebibmacro{journal}addcommaaddspace}{} 


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}addcommaaddspace}{}}
{multicitedelim}
{usebibmacro{postnote}}

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


enter image description here






share|improve this answer























  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
    – Taunch
    16 hours ago















up vote
2
down vote













You can use the biblatex command



ifentrytypes{article}{usebibmacro{journal}addcommaaddspace}{} 


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}addcommaaddspace}{}}
{multicitedelim}
{usebibmacro{postnote}}

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


enter image description here






share|improve this answer























  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
    – Taunch
    16 hours ago













up vote
2
down vote










up vote
2
down vote









You can use the biblatex command



ifentrytypes{article}{usebibmacro{journal}addcommaaddspace}{} 


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}addcommaaddspace}{}}
{multicitedelim}
{usebibmacro{postnote}}

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


enter image description here






share|improve this answer














You can use the biblatex command



ifentrytypes{article}{usebibmacro{journal}addcommaaddspace}{} 


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}addcommaaddspace}{}}
{multicitedelim}
{usebibmacro{postnote}}

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


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Guido

23.8k54785




23.8k54785












  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
    – Taunch
    16 hours ago


















  • Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
    – Taunch
    16 hours ago
















Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
– Taunch
16 hours ago




Thank you, this solves my problem. But how would you address the problem @moewe has pointed out in the above comment?
– Taunch
16 hours ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461307%2fbiblatex-custom-citation-with-conditional-clause%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

サソリ

広島県道265号伴広島線

Accessing regular linux commands in Huawei's Dopra Linux