2

I'm trying to suppress the year field when I'm citing \ifentrytype{book}. I thought to be able to use \AtEveryCitekey{\ifentrytype{book}{\clearfield{year}}{}}, but for some reason it doesn't have the intended effect. Any ideas how to solve that? Thanks in advance!

I've included a working sample:

EDIT: Now I'm using the authoryear.cbx

\documentclass{scrartcl}
%
\usepackage[%
backend=biber,%
citestyle=authoryear,%
bibstyle=authortitle,%
]{biblatex}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{filecontents}
\usepackage{verbatim}
\usepackage{csquotes}
%
\addbibresource{\jobname.bib} 
% ===
%
\newbibmacro*{cite:extrainfo:shorttitle}{%
\newunit
\printfield{shorttitle}
}
%
\makeatletter
\newbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames{labelname}%
       \ifentrytype{book}%
        {\usebibmacro{cite:extrainfo:shorttitle}}{}% shorttitle in footnote
        \setunit{\printdelim{nameyeardelim}}}%
     \usebibmacro{cite:labeldate+extradate}}
    {\usebibmacro{cite:shorthand}}}
% ===
\makeatletter
\AtEveryCitekey{%
  \ifentrytype{book}{%
    \clearfield{year}%
  }{%
  }%
}
\makeatother
% ===
% === BIB
\begin{filecontents}{\jobname.bib}
@book{test2,
    author      = {Max Mustermann},
    shortauthor = {M-M},
    title       = {Musterbuch},
    shorttitle  = {MB},
    year        = {2018},
}
\end{filecontents}
%
\begin{document}
% ===
\printbibliography[title=Bibliography]
I want to achieve a that if I'm citing a book it won't cite the year. I thought I could achieve that with \verb|\AtEveryCitekey{\ifentrytype{book}{\clearfield{year}}{}}|. But it seems like the year is still being printed. Do I have to replace \verb|{year}| with another argument? \\\footcite[p. 85]{test2}
    How can I make it work?
\end{document}
8
  • 3
    At the moment the citation is generated, in which the hook you chose takes place, the citation uses labeldate, so clearing year at that point indeed is not much help. There are certainly ways to achieve the result, but you are using an authoryear citation style, if you clear the date you will likely end up with ambiguous citations. Are you really, really sure that's what you want?
    – gusbrs
    Apr 27, 2018 at 20:59
  • 2
    Well, to get things even more complicated, you have the comp variant of authoryear, so a lot of possible cases emerge. Technically the place to intervene would be cite bibmacro, which you already redefine. You can see there that several cases must be dealt with. E.g. suppose you cite an article and a book by the same author on the same year, should the date be maintained, or excluded? Should the year be present in the bibliography? Should the extradate exist for the book or not? And so on. I really advise against your attempt in these terms...
    – gusbrs
    Apr 27, 2018 at 21:58
  • 1
    Can you explain what exactly you want to achieve, please? What happens if you have to cite two @books by the same author? What happens if you cite a @book and an @article by the same author (you have a -comp style, so normally you'd get "Knuth (1984,1986)", assume the 84 work is a book the 86 work an article, would you want "Knuth (,1986)" - surely not, what about "Knuth, Knuth (1986)")? May I ask why you want to remove the year for @books - maybe there is a more elegant way overall to do this, what makes @books special?
    – moewe
    Apr 28, 2018 at 5:56
  • 1
    ... I know it is annoying if people question your motives and ask heretical questions, but since the presence of the year is quite integral to the citation style you want to modify, there are quite a few things one has to think about to make sure that doing what you want does not break the overall output of the style or messes up in certain situations.
    – moewe
    Apr 28, 2018 at 6:03
  • 1
    \footcite[85]{test2} is enough, you don't need to (and should not) include the p.~ prefix
    – moewe
    Apr 28, 2018 at 14:17

1 Answer 1

2

You are almost there. All you need to do is move the cite:labeldate+extradate macro from after the conditional into the 'else' branch of the conditional.

\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonameyeardelim}}}
       {\printnames{labelname}%
        \setunit{\printdelim{nameyeardelim}}}%   
     \ifentrytype{book}
       {\setunit{\printdelim{nametitledelim}}%
        \usebibmacro{cite:extrainfo:shorttitle}}
       {\usebibmacro{cite:labeldate+extradate}}}
    {\usebibmacro{cite:shorthand}}}

Deleting the year does not help because the cite commands work with labelyear. While labelyear may be a copy of year (depending on the \DeclareLabeldate configuration) it has been defined in a way that removing year (at the biblatex level) does not influence labelyear. So you would have to remove labelyear to prevent the date from being printed in citations. But then the \ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}} conditional kicks in and prints the replacement label instead of the labelname. This is undesired here. So all in all, it is safest and easiest with the code to not delete any field instead we just don't call the macro that prints the year in citations if we don't want the year.

For your cite:extrainfo:shorttitle I'd prefer

\newbibmacro*{cite:extrainfo:shorttitle}{%
  \printfield[citetitle]{labeltitle}}

This has the advantage that it prints something if you don't give a shorttitle field.

enter image description here

5
  • The result is not very uniform and at least in the example the use of shorttitle and shortauthor makes the source very, very hard to locate in the bibliography. But maybe the labels are easier to match up with the entries in your actual document.
    – moewe
    Apr 28, 2018 at 13:54
  • Thanks. Helped me. To figure out my redefinitions for books, while not messing up already used redefinitions for articles. In the end I used: \ifentrytype{book} {\setunit{\printdelim{nametitledelim}}\usebibmacro{cite:book:shorttitle}} {} I had to exclude {\usebibmacro{cite:labeldate+extradate}} completely.
    – texnewbie
    Apr 29, 2018 at 21:50
  • Concerning the shorttitle and shortauthor. I'm currently working on creating a biblatex/biber configuration for german law documents, because I'm unhappy with all bibtexsolutions. For german law documents there are strict requirements and I'm using the shorttitle and shortauthor fields to achieve those
    – texnewbie
    Apr 29, 2018 at 22:02
  • @texnewbie Mhhh, but if you remove \usebibmacro{cite:labeldate+extradate} completely, there is little point in using an authoryear-like style in the first place? Ah yes, law citations, apparently everyone has their own strict guidelines that people must abide by. Unfortunately, the two 'jura' styles for biblatex have not been updated in a very long time and should not be used any more. If you come up with something stable and want to maintain it for the foreseeable future, you may want to consider releasing your work when you are done.
    – moewe
    Apr 30, 2018 at 4:35
  • I reintroduce \usebibmacro{labeldate+extradate} for \ifentrytype{article}. We'll see if I get there lot's of work to do :) And I'll have to figure out how to create a style .cbx/.bbx file. Because right now I'm only using a biblatex.cfg and a .tex file with renewments.
    – texnewbie
    Apr 30, 2018 at 16:20

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.