9

Combination of biblatex-chicago and Zotero produces many excessive fileds in the bibliography. This problem could be solved by adding to the preambule caveats like this:

\AtEveryBibitem{%
\ifentrytype{online}
{}
{\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}}

(Described in detail in the answer to my previous question: Excessive fields in biblatex chicago author-date style.)

This solution worked well for me, but now I have to produce a syllabus using \fullcite command. Unfortunately, this solution does not solve the problem for full bibliographic entries outside of the bibliography itself.

Here is the code with bibliography inside (to get the author's first and last name in the right order I use the following solution: Biblatex-chicago: \fullcite flips first and last name):

\begin{filecontents*}{database.bib}
    @book{dalton_apartisan_2012,
        title = {The Apartisan American: Dealignment and Changing Electoral Politics},
        isbn = {9781452216942},
        url = {http://books.google.com/books?id=eYkczUyX5wMC},
        shorttitle = {The Apartisan American},
        pagetotal = {241},
        publisher = {{CQ} Press},
        author = {Dalton, Russell J.},
        urldate = {2014-04-03},
        date = {2012-02-22},
        langid = {english},
        keywords = {Political Science / Political Process / Elections, Political Science / Public Policy / General}
    }
\end{filecontents*}
\documentclass[11pt]{article}
\usepackage[hmargin=3cm,vmargin=3cm]{geometry}
\usepackage[onehalfspacing]{setspace}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{booktabs,graphicx}
\usepackage{paralist}
\usepackage{cancel,soul}
\usepackage{enumitem}
\usepackage[authordate,backend=biber,bibencoding=utf8,bookpages=false,doi=only,isbn=false,footmarkoff]{biblatex-chicago}
\usepackage[colorlinks, pdfstartview={XYZ null null 1.25},bookmarksopen=true,bookmarksopenlevel=\maxdimen,citecolor={blue},urlcolor={blue}]{hyperref}
\addbibresource{database.bib}
\DeclareCiteCommand{\fullcite}
{\usebibmacro{prenote}}
{\usedriver
    {}
    {\thefield{entrytype}}}
{\multicitedelim}
{\usebibmacro{postnote}}
\AtEveryBibitem{%
    \ifthenelse{\ifentrytype{article}\OR\ifentrytype{book}\OR\ifentrytype{collection}\OR\ifentrytype{incollection}\OR\ifentrytype{mvbook}\OR\ifentrytype{mvcollection}\OR\ifentrytype{mvincollection}}
    {\clearfield{month}\clearfield{url}\clearfield{doi}\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}}


\begin{document}
\begin{center}
{\huge Partisanship in Old, New and Non-Democracies}\\
\end{center}

\vspace{30pt}
\noindent\textbf{Instructor: }  \hfill
\textbf{Time and Location:} TBA\\
\textbf{Contact:} 
\hfill
\hfil \textbf{Office Hours:} TBA\\

\vspace{-20pt}



\subsection*{Partisanship in the United States}


\begin{enumerate}
    \item \parencite{dalton_apartisan_2012}
    \item \fullcite{dalton_apartisan_2012}
\end{enumerate}

\printbibliography[heading=bibintoc]

\end{document} 

Here is the output. Note the excessive fileds in the in-text full citation (they are absent in the References):

enter image description here

Any help, especially simple acessible solutions would be greatlly apreciated.

  • 4
    There's an \AtEveryCite as well as an \AtEveryCitekey in biblatex. – jon Feb 21 '15 at 19:13
  • 2
    In addition to jon's suggestion, you could still map all these fields to null using sourcemapping. – moewe Feb 21 '15 at 19:29
  • As @moewe says, the best way to do this is to do this as early as possible before biblatex even sees the data, using the biber sourcemapping feature. There are many examples of this on TSE. – PLK Feb 21 '15 at 23:31
  • @jon: OK, so I tried to add to my \AtEveryBibitem code exactly the same code but starting with \AtEveryCitekey and it resolves the issue, but produces the following mess in front of every citation: "blx@hook@citekey@next" (like (blx@hook@citekey@nextDalton 2012). (Also I am curious why you have to include both? And you have to, because if only code starting with \AtEveryCitekeyis included, the thing doesn't compile at all. Here they also use both: [http://tex.stackexchange.com/questions/40097/disable-issn-but-keep-isbn-with-biblatex]). – homo_loquens Feb 22 '15 at 08:27
  • @moewe and PLK, I looked up souremapping in biber manual and, unfortunately, it's beyond by proficiency level in biblatex. – homo_loquens Feb 22 '15 at 08:30

2 Answers2

15

If you want to control the urldate in bibliography and citations independently, \AtEveryBibitem and \AtEveryCitekey are the way to go.

\AtEveryBibitem performs its actions at every item in the bibliography, while \AtEveryCitekey performs its actions at every item cited. (See pp. 228-229 of the biblatex documentation).

So to get rid of, say, the title only in citations, you would go with \AtEveryCitekey{\clearfield{title}} - the title is then ignored in citations, but still printed in the bibliography. Analogously, \AtEveryBibitem{\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}} gets rid of the URL date only on the bibliography, not in the citations.

In order to get rid of the URL date everywhere, you could therefore issue

\AtEveryBibitem{\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}
\AtEveryCitekey{\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}

Type restrictions can be applied by \ifentrytype or even more complex constructs like so

\AtEveryBibitem{%
  \ifentrytype{online}
    {}
    {\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}}

\AtEveryCitekey{%
  \ifboolexpr{test {\ifentrytype{article}} or test {\ifentrytype{book}}}
    {\clearfield{urlyear}\clearfield{urlmonth}\clearfield{urlday}}
    {}}

The first example deletes the URL date for all but @online entries, while the second deletes them only for @article and @book.


For technical reasons (I could think of possible label date creation) it is better though to get rid of the URL date as early as possible, if you don't want to use it at all. Here Biber's sourcemapping comes in (see §4.5.2 Dynamic Modification of Data, pp. 148-156 of the doc).

We want to get rid of the urldate field in your .bib file, so we just set it to null.

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=urldate, null]
    }
  }
}

With sourcemapping, type restrictions can be imposed by \pertype like so

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{article}
      \pertype{book}
      \step[fieldset=urldate, null]
    }
  }
}

This map now only applies to @articles and @books. Sadly, with \pertype one cannot use negations as we did above (as in "only apply this to entries that are not @online"), maybe that's worth a feature request (- it was worth one and our wish has been granted).

Since the date field is a bit special in how it's handled by biblatex. In the document it is available as three fields year, month and day (so one could use \AtEveryCitekey{\clearfield{month}} without any trouble), for source-mapping purposes (remember, source-mapping is one of the first steps Biber takes with a file, at this point nothing has been interpreted or read from the file) often the date is input as date = {YYYY-MM-DD}, that is why just deleting the month field in source-mapping will only help those who input the date as year = {2014}, month = {03}, day={04} (which is possible, but slightly less comfortable). What we can do though is, we can make the date year-only with RegEx

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldset=month, null]
      \step[fieldsource=date,
            match=\regexp{([0-9]{4})-[0-9]{2}(-[0-9]{2})*},
            replace=\regexp{$1}]
    }
  }
}

We look for a string of the form "YYYY-MM-DD" or possibly just "YYYY-MM-DD" and just retain the "YYYY" part, thus retaining only the year. We also set the month to null for those who prefer to input the date more verbosely.

MWE

\documentclass{article}
\usepackage[style=authoryear,backend=biber,mergedate=false]{biblatex}
\addbibresource{biblatex-examples.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pertype{online}
      \step[fieldset=urldate, null]
    }
    \map{
      \step[fieldset=month, null]
      \step[fieldsource=date,
            match=\regexp{([0-9]{4})-[0-9]{2}(-[0-9]{2})*},
            replace=\regexp{$1}]
    }
  }
}

\begin{document}
\cite{baez/online,itzhaki,markey}

\printbibliography
\end{document}

Gives

enter image description here

Below is the output without any source-mapping for comparison

enter image description here

moewe
  • 175,683
  • Thanks, your second solution worked! I just want to clarify for other users how to make it work for more complex purposes and also why I was not able to make your first solution work for my purposes. \AtEveryCitekey (unlike, \AtEveryBibitem) was not able to swallow \ifthenelse{\ifentrytype{...}}clauses. Since in most cases I need to delete particular fields for particular types of entries, this did not work for me. – homo_loquens Feb 23 '15 at 06:02
  • Sourcemapping solves this problem, but (compared to \AtEveryBibitem) the syntax to specify entry types and fields is a bit different: for both purposes you just need to add a new line. For example to delete both url/doi and urldate for both books and articles you have to write the following: \DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \pertype{article} \pertype{book} \step[fieldset=urldate, null] \step[fieldset=url, null] \step[fieldset=doi, null] } } } – homo_loquens Feb 23 '15 at 06:02
  • 1
    @homo_loquens Both \AtEveryCitekey and \AtEveryBibitem support \ifentrytype and even more complex conditional constructions, the error you mentioned in your other comments looks suspiciously like this. – moewe Feb 23 '15 at 06:07
  • yes, right you are, in my case the whole misunderstanding came from my improper modification of your elegant solution here, where you had then rather than else part empty. I think \AtEveryBibitem was just less vulnerable to my erratic syntax and worked where \AtEveryCitekey failed. – homo_loquens Feb 23 '15 at 06:28
  • One last clarification: I have a problem with the field month (which, if not removed, produces a date, say, September 20, for both books and articles). Both \AtEveryBibitem and \AtEveryCitekey remove it easily like any other field (doi or url, for example). Sourcemapping though has no effect on it. (Note that we are taking about date of publication here, not date of access/urldate. Date is specified in .bib file as in my example: YYYY-MM-DD). – homo_loquens Feb 23 '15 at 18:59
  • 1
    @homo_loquens That's due to the special format date fields have, for source-mapping purposes a date specified as date = {YYYY-MM-DD} is just a date field, while for biblatex styles the date splits into year, month and date, so you can only selectively get rid of months by dropping them later (or by using regex in the source-mapping). – moewe Feb 23 '15 at 21:01
  • Thanks for clarifying this! If you would feel like that, it would be great to see the sketch of this regex source-mapping (or even better if you make it part of your MWE). But if it would help nobody but me, I can just use AtEveryCitekey. – homo_loquens Feb 24 '15 at 01:51
  • 1
    @homo_loquens Have a look at the modified answer, it now features a get-rid-of-all-date-parts-but-the-year-source-mapping. – moewe Feb 24 '15 at 06:38
  • Great! Thanks a lot! One thing I don't get though, is what to do with the $ sign in the replace part - it renders the whole subsequent code as in math mode. – homo_loquens Feb 25 '15 at 02:42
  • 1
    @homo_loquens Mhh, it shouldn't $1 is a place-holder for the first match, which in our case is going to be the year. Maybe you are using an older version of biblatex/Biber. Did you try the actual MWE above and did get this strange behaviour? – moewe Feb 25 '15 at 06:43
  • I did try it, but in my new editor, TeXstudio. However in Winedt everything works properly, so it's probably TeXstudio problem. I will leave them a ticket. – homo_loquens Feb 25 '15 at 19:56
  • @homo_loquens That is very odd indeed. This code should not (and to my knowledge does not) depend on the editor at all. – moewe Feb 25 '15 at 20:28
  • FYI http://sourceforge.net/p/texstudio/bugs/1155/ (my ticket was closed and redirected to this) – homo_loquens Feb 25 '15 at 20:56
  • @homo_loquens So it was entirely a syntax-highlighting and not a biblatex/Biber or actual output problem problem? – moewe Feb 25 '15 at 21:00
  • Yes, but it is also important. Actually their solution does not fix all the problems, such as folding preamble. – homo_loquens Feb 25 '15 at 22:26
0

The second solution from @moewe worked for me (even for \fullcite), but I found here a shorter solution:

\AtEveryCitekey{\UseBibitemHook}