0

I'm using biblatex with a custom bibstyle based on the trad-standard style:

\RequireBibliographyStyle{trad-standard}

In my custom style I redefined some appearances like bold text etc. but now I want to add the urldate to the output if a URL is given.

I have for example a website as reference. Mendeley exported the resource as @misc which seems to be correct, but the access date (saved as urldate) is not showing up. I now searched the code of the trad-standard bibstyle and didn't find the urldate key, so it's quite logical that there is no output. How could I add the functionality of always displaying the urldate, if a URL and the urldate is given, no matter what entry type I'm in?

My guess is to renew the doi+eprint+url macro as it is responsible for the output of the URL. So if I could append the urldate to the output, it should do what I want. The problem is, that I have no idea how tho append the urldate to the macro.


Here is my custom .bbx file:

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This is a custom bibliography style based on the trad-abbrv style
% by Marco Daniel (2012--2015) and Moritz Wemheuer (2016--).
%
% This package is released under the terms of the
% LaTeX Project Public License v1.3c or later
% See http://www.latex-project.org/lppl.txt
%
% Copyright (c) 2012 -- 2015 Marco Daniel
%               2016 --      Moritz Wemheuer
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% %%%%%%%%%%%%%
% Declare Style
% %%%%%%%%%%%%%

\ProvidesFile{custom-abbrv.bbx}[2017/10/18 v1.0.0 Custom abbrv Bibliography Style]



% %%%%%%%%%%%%%%
% Require Styles
% %%%%%%%%%%%%%%

\RequireBibliographyStyle{trad-standard}



% %%%%%%%%%%%%%
% Basic Options
% %%%%%%%%%%%%%

\ExecuteBibliographyOptions{
    abbreviate      = false,
    arxiv           = false
    autolang        = hyphen,
    backref         = false,
    dateabbrev      = true,
    eprint          = false,
    hyperref        = true,
    labelnumber     = true,
    maxnames        = 3,
    minnames        = 3,
    sorting         = none,
}



% %%%%%%%%%%%%%%%%%%%
% trad-abbrv Settings
% %%%%%%%%%%%%%%%%%%%

\@ifpackagelater{biblatex}{2016/03/01}{%
    \@ifpackagelater{biblatex}{2016/05/14}{%
        \DeclareNameFormat{abbrv}{%
            \usebibmacro{name:given-family}%
            {\namepartfamily}%
            {\namepartgiveni}%
            {\namepartprefixi}%
            {\namepartsuffixi}%
            \usebibmacro{name:andothers}%
        }%
    }{%
        \DeclareNameFormat{abbrv}{%
            \nameparts{#1}%
            \usebibmacro{name:given-family}%
            {\namepartfamily}%
            {\namepartgiveni}%
            {\namepartprefixi}%
            {\namepartsuffixi}%
            \usebibmacro{name:andothers}%
        }%
    }%
}{%
    \DeclareNameFormat{abbrv}{%
        \usebibmacro{name:first-last}{#1}{#4}{#6}{#8}%
        \usebibmacro{name:andothers}%
    }%
}%
\DeclareNameAlias{default}{abbrv}


\DeclareFieldFormat{bibentrysetcount}{\mkbibparens{\mknumalph{#1}}}
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\DeclareFieldFormat{shorthandwidth}{\mkbibbrackets{#1}}


\@ifpackagelater{biblatex}{2016/05/14}{%
    \defbibenvironment{bibliography}%
        {%
            \list{%
                \printtext[labelnumberwidth]{%
                    \printfield{labelprefix}%
                    \printfield{labelnumber}%
                }%
            }{%
                \setlength{\labelwidth}{\labelnumberwidth}%
                \setlength{\leftmargin}{\labelwidth}%
                \setlength{\labelsep}{\biblabelsep}%
                \addtolength{\leftmargin}{\labelsep}%
                \setlength{\itemsep}{\bibitemsep}%
                \setlength{\parsep}{\bibparsep}%
            }%
            \renewcommand*{\makelabel}[1]{\hss##1}%
        }
        {\endlist}
        {\item}%
}{%
    \defbibenvironment{bibliography}%
        {%
            \list{%
                \printtext[labelnumberwidth]{%
                    \printfield{prefixnumber}%
                    \printfield{labelnumber}%
                }%
            }{%
                \setlength{\labelwidth}{\labelnumberwidth}%
                \setlength{\leftmargin}{\labelwidth}%
                \setlength{\labelsep}{\biblabelsep}%
                \addtolength{\leftmargin}{\labelsep}%
                \setlength{\itemsep}{\bibitemsep}%
                \setlength{\parsep}{\bibparsep}%
            }%
            \renewcommand*{\makelabel}[1]{\hss##1}%
        }%
        {\endlist}%
        {\item}%
}

\defbibenvironment{shorthands}%
    {%
        \list{%
            \printfield[shorthandwidth]{shorthand}%
        }{%
            \setlength{\labelwidth}{\shorthandwidth}%
            \setlength{\leftmargin}{\labelwidth}%
            \setlength{\labelsep}{\biblabelsep}%
            \addtolength{\leftmargin}{\labelsep}%
            \setlength{\itemsep}{\bibitemsep}%
            \setlength{\parsep}{\bibparsep}%
            \renewcommand*{\makelabel}[1]{\hss##1}%
        }%
    }%
    {\endlist}%
    {\item}%

\DeclareBibliographyDriver{set}%
    {%
        \entryset%
        {%
            \ifbool{bbx:subentry}%
                {%
                    \printfield[bibentrysetcount]{entrysetcount}%
                    \setunit*{\addnbspace}%
                }%
                {}%
        }%
        {}%
        \newunit\newblock%
        \usebibmacro{setpageref}%
        \finentry%
    }



% %%%%%%%%%%%%%%%%%
% Appearance Styles
% %%%%%%%%%%%%%%%%%

% Name
\renewcommand{\labelnamepunct}{\addcolon\space}

% Title
\DeclareFieldFormat*{title}{\enquote{#1}\isdot}
\DeclareFieldFormat{journaltitle}{\mkbibemph{#1},}

% Volume
\DeclareFieldFormat[article]{volume}{#1}

% Number
\DeclareFieldFormat*{number}{\mkbibparens{#1}}

% Pages
\DeclareFieldFormat*{pages}{\space#1\space}
\renewcommand*{\bibpagespunct}{\addspace}

% Year
\DeclareFieldFormat{date}{\textbf{#1}}

% URL
\DeclareFieldFormat{url}{URL:\space\url{#1}}

% ISSN / ISBN
\DeclareFieldFormat{issn}{ISSN:\space\url{#1}}
\DeclareFieldFormat{isbn}{ISBN:\space\url{#1}}

% DOI
\DeclareFieldFormat{doi}{%
    DOI\addcolon\space
    \ifhyperref
        {\href{http://dx.doi.org/#1}{\nolinkurl{#1}}}
        {\nolinkurl{#1}}%
}

% Item Separation
\setlength\bibitemsep{.5\baselineskip}

% Alignment
\AtBeginBibliography{\raggedright}



% %%%%%%%%%%%%%%%%%%%%%%%
% Changes in the position
% %%%%%%%%%%%%%%%%%%%%%%%

% Change the position of the year to be in front of the volume
\renewbibmacro*{journal+issuetitle}{%
    \usebibmacro{journal}%
    \usebibmacro{date}% Added the date, right after the journal
    \newcommaunit*%
    \iffieldundef{series}
    {}
    {%
        \newunit
        \printfield{series}%
        \setunit{\addcomma\space}%
    }%
    \usebibmacro{volume+number+pages+eid}%
    \newcommaunit
    % \setunit{\addspace}%
    \usebibmacro{issue+date-parens}%
    \setunit*{\addcolon\space}%
    \usebibmacro{issue}%
    \newunit%
}

% Remove the date after the volume
\renewbibmacro*{issue+date-parens}{%
    \iffieldundef{issue}%
    {%
        % \usebibmacro{date}
    }%
    {%
        \printfield{issue}%
        \newcommaunit*%
        % \usebibmacro{date}
    }%
    \newunit%
}

\endinput
  • 1
    I think it is simpler. Does this tex.stackexchange.com/q/428959/105447 help? – gusbrs Apr 30 '18 at 10:44
  • 1
    Can you give an example (i.e. an MWE/MWEB), please? The unmodified biblatex-trad styles always display URLs and URL dates for all entry types. If you or your customisation set the url=false option, you will get URLs and URL dates for only @online entries (all other types don't display URLs then). If you see a different behaviour even with an explicit url=true, your custom style modifies trad-standard in a way that it destroys the standard behaviour. – moewe Apr 30 '18 at 11:36
  • @gusbrs That looks great, but unfortunately it has no effect on my output. – Sam Apr 30 '18 at 12:13
  • @moewe URL is set to true and even if I change @misc to @online no date is output. – Sam Apr 30 '18 at 12:14
  • 1
    Mhhh, the code looks OK and in fact works for me in a short document I created (see gist.github.com/moewew/4e100b2a1f044354ba07927ea6cfac6a). Can you show us a complete example along the line of my link, please? We need to see an example .bib file and how you load your custom style in your document. – moewe Apr 30 '18 at 12:21
3

As it turned out in the comments, the problem is actually a malformed urldate field as exported by Mendeley. All biblatex date fields must be written in YYYY-MM-DD format (ISO 8601/EDTF), DD.MM.YYYY is not acceptable input and generates a warning:

Invalid format '30.04.2018' of date field 'urldate' - ignoring

You should definitely contact the Mendeley developers about this.

In the meantime, here is a fix with Biber's sourcemapping

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[style=authoryear, backend=biber]{biblatex}

\begin{filecontents}{\jobname.bib}
@misc{appleby,
  author  = {Humphrey Appleby},
  title   = {On the Importance of the Civil Service},
  date    = {1980},
  url     = {http://example.com/~sirhumphrey/cc.pdf},
  urldate = {30.04.2018},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=urldate, match=\regexp{\A(\d{2}).(\d{2}).(\d{4})\Z}, replace={$3-$2-$1}]
    }
  }
}

\begin{document}
\cite{sigfridsson,appleby}
\printbibliography
\end{document}

enter image description here

But don't just use it: Complain to the Mendeley people!

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.