2

The same question has been answered here but that solution does not work for me since I am not sure what is the empty field. Is there a way to drop all empty items?

Perhaps something like

\AtEveryBibitem{%

  if entry is empty {
             \clearfield{} 
  }
}

These are my attributes for biblatex:

\usepackage[
backend=biber,
backref=false,
sorting=nyt,
style=authoryear,
citestyle=authoryear]{biblatex}

This is how the references looks:

enter image description here

And the .cfg which I just used as-is:

\ProvidesFile{biblatex.cfg}

\DeclareNameAlias{sortname}{last-first}

% Put titles in quotes for most types
\DeclareFieldFormat
  [online,article,inbook,incollection,inproceedings,thesis,unpublished,patent]
  {title}{\mkbibquote{#1\addcomma}}
\DeclareFieldFormat
  [book]
  {title}{\mkbibemph{#1\addcomma}}

\DeclareFieldFormat
  [inbook,incollection,inproceedings]
  {booktitle}{\mkbibemph{#1\addcomma}}

% Attempted Fixes for ONLINE entries
\DefineBibliographyStrings{english}{%
  url = {available online at},
  }

\DeclareFieldFormat{url}{\bibstring{url}\space\url{#1}}
\DeclareFieldFormat{urldate}{\printtext{accessed}\space#1}

\renewbibmacro*{url+urldate}{%
  \printtext[parens]{%
   \printfield{url}\addsemicolon\space
   \printurldate
  }}

% Year formatting
\renewbibmacro*{date+extrayear}{%
  \iffieldundef{\thefield{datelabelsource}year}
    {}
    {\printtext{%
       \printfield{\thefield{datelabelsource}year}%
       \printfield{extrayear}}}}%
\renewbibmacro*{date}{%
  \iffieldundef{month}
    {}
    {\printdate}}%
\renewbibmacro*{issue+date}{%
  \ifboolexpr{
    test {\iffieldundef{issue}}
    and
    test {\iffieldundef{month}}
  }
    {}
    {\printtext{%
       \printfield{issue}%
       \setunit*{\addspace}%
       \printdate}}%
  \newunit}

% Fix names
\DeclareNameAlias{sortname}{last-first}
\renewcommand*{\labelnamepunct}{\addperiod\space }
\renewcommand*{\finalnamedelim}{,\addspace and\addspace }

% Fix "in"
\renewbibmacro*{in:}{%
  \printtext{%
    in\space}}

% Gotta get rid of the "in" before journal title
\DeclareBibliographyDriver{article}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author/translator+others}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{bytranslator+others}%
  \newunit\newblock
  \printfield{version}%
  \newunit\newblock
  \usebibmacro{journal+issuetitle}%
  \newunit
  \usebibmacro{byeditor+others}%
  \newunit
  \usebibmacro{note+pages}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{issn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \newunit\newblock
  \iftoggle{bbx:related}
    {\usebibmacro{related:init}%
     \usebibmacro{related}}
    {}%
  \usebibmacro{finentry}}

% Make (Volume:Issue)
\newbibmacro*{volume+number+eid}{%
  \printtext[parens]{%
  \printfield{volume}%
  \setunit*{:}%
  \printfield{number}}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

% Fix editor
\renewbibmacro*{byeditor+others}{%
  \ifnameundef{editor}
    {}
    {\printnames[byeditor]{editor}%
     \setunit{\addspace}%
     \printtext[parens]{\usebibmacro{apaeditorstrg}{editor}}%
     % \usebibmacro{byeditor+othersstrg}%
     \clearname{editor}%
     \newunit}%
  \usebibmacro{byeditorx}%
  \usebibmacro{bytranslator+others}}

\newbibmacro*{apaeditorstrg}[1]{%
  \iffieldundef{#1type}
    {\ifthenelse{\value{#1}>1\OR\ifandothers{#1}}
       {\bibstring{editors}}
       {\bibstring{editor}}}
    {\ifthenelse{\value{#1}>1\OR\ifandothers{#1}}
         {\bibcpstring{type\thefield{#1type}s}}
         {\bibcpstring{type\thefield{#1type}}}}}

% Fix appearance of , with name lists of two
\renewcommand*{\finalnamedelim}{%
  \ifnumgreater{\value{liststop}}{2}{\finalandcomma}{}%
  \addspace\bibstring{and}\space}
\endinput

icisfinal

 \LoadClass[10pt,letterpaper]{article}
Dambo
  • 359
  • 1
    biblatex already drops all formatting for empty fields if that formatting is added by the formatting directive in a \printfield call (this includes most formatting in the bibliography, but not all). In particular issuing a \clearfield when the field is already empty will not bring any improvement whatsoever. There are two main reasons that I can imagine for unwanted formatting remaining even though fields are empty: (1) A style relies on the presence of a mandatory field. This is the case for some settings of the standard authoryear style ... – moewe Apr 24 '19 at 19:58
  • ... which will show empty parentheses if the mandatory date/year is missing (cf. https://github.com/plk/biblatex/issues/793). In this particular case the formatting is added by an 'external' \printtext that can't check for emptiness of fields. Since year/date is mandatory, there is no test for emptiness of those fields. (2) The style is badly coded and does not use the usual biblatex idioms to format fields. – moewe Apr 24 '19 at 20:01
  • In any case it would help greatly, if you could give a concrete example of the problem you are trying to solve in the form of an MWE (https://tex.meta.stackexchange.com/q/228/35864). – moewe Apr 24 '19 at 20:01
  • 1
    Maybe https://tex.stackexchange.com/q/326567/35864 helps you already. This would be the mandatory date/year issue I used as an example for case (1). – moewe Apr 24 '19 at 20:05
  • Mhhh, I have never seen something like this before. Can you turn your code snippet into a full example document (https://tex.meta.stackexchange.com/q/228/35864, https://tex.meta.stackexchange.com/q/4407/35864) with \documentclass, \begin{document}...\end{document} and a relevant example .bib entry that reproduces the output you show when compiled in an empty folder? The output is decidedly non-standard especially if you take into account that you load the standard authoryear style. – moewe Apr 26 '19 at 13:39
  • @moewe thanks for your help I tried to minimize the .tex and .bib as much as I could, but I am not sure how to minimize the .cfg – Dambo Apr 26 '19 at 14:05
  • Aha! I dimly remembered seeing that code before and found this older question of yours: https://tex.stackexchange.com/q/476235/35864. It would have helped greatly if you had at least linked to that question or to the source of your biblatex.cfg. – moewe Apr 26 '19 at 14:42

1 Answers1

1

In general biblatex automatically drops all formatting of empty fields when the fields are printed with \printfield. But formatting for empty content can not be automatically dropped if it is applied by way of \printtext or other means. In that case the style must manually check if the contents of the \printtext would be empty or must (tacitly or not) assume that the contents are not empty.

It would not help at all to issue a \clearfield if a field is detected as empty since that would not change the state of the field in question for most relevant intents and purposes. An empty field is already cleared.


In your previous question How to mention where a citation is used in the references section? we established that you use the biblatex.cfg from https://github.com/rschuetzler/latex-icis-template/blob/master/biblatex.cfg.

Amongst other (outdated and questionable) constructions, the file contains

\renewbibmacro*{url+urldate}{%
  \printtext[parens]{%
   \printfield{url}\addsemicolon\space
   \printurldate
  }}

Implicitly this code assumes that each entry has a url or at least a urldate. This assumption need not hold for many entry types. The code will always print a pair of parentheses even if the is no url or urldate.

A more sensible definition could be

\renewbibmacro*{url+urldate}{%
  \iffieldundef{url}
    {}
    {\printtext[parens]{%
       \printfield{url}
       \setunit{\addsemicolon\space}%
       \printurldate}}}

This prints the url and urldate field in parentheses only if the url is present (it explicitly does not show urldate if there is no url). In particular your example entry should not show an empty pair of parentheses.

Note that this issue does not become apparent in the original template since there biblatex is called with the option url=false, which essentially means that the url+urldate macro is only called for @online entries, where a url field is quite probably not empty.

moewe
  • 175,683