0

I hope I searched properly, because I couldn't find anything. I'm looking for a way to get a specific Information from a string. As shown below, there is a date in a field "usera" [(01.01.2009)] and a year for "userb" [(..., 2009)] which is the same information. How is it possible to get rid of "userb", get the information from "usera" and show in my Bibliography both. So I want only add the full date in usera and show it, and latex should extract only the year from usera and show it, too.

example cite

@online{kapselung,
  title = "Rheinwerk Computing :: Objektorientierte Programmierung – 2.2 Die Kapselung von Daten",
  shorttitle = "Kapselung von Daten",
  author = "Lahres, Bernhard and Rayman, Gregor",
  url = "http://openbook.rheinwerk-verlag.de/oop/oop_kapitel_02_002.htm",
  userb = 2009,
  usera = {01.01.2009},
  note = "13:21", 
  year = "28.04.2020"
}


\DeclareBibliographyDriver{online}{%
  \textit{\printnames{author}}%
  \newunit\space
  \printtext{$($}%
  \printfield{shorttitle}%
  \setunit*{\addcomma\addspace}%
  \printfield{userb}%
  \printtext{$)$}%
  \setunit*{\addcolon\space}%
  \printfield{title}%
  \setunit*{\addcomma\space<}%
  \textit{\printfield{url}>\space}%
  \printtext{$($}%
  \printfield{usera}%
  \printtext{$)$}%
  \setunit*{\space{[Zugriff}\space}%
  \printfield{year}%
  \setunit*{\space}%
  \printfield{note}%
  \printtext{\space{Uhr}}%
  \printtext{$]$}%
}
´´´

dhd80
  • 125
  • Not related to the question proper, but year = "28.04.2020" is not a good idea, date = {2020-04-28}, would be usual way to handle dates with finer granularity than year. – moewe May 01 '20 at 14:24
  • To me it looks like what you actually want is date = {2009-01-01}, (the publication date) and urldate = {2020-04-28T13:21:00}, (the access date with time). Those fields are stuff biblatex can handle out of the box. If you give the date in usera/userb in some other format, you essentially have to parse the date yourself (possible of course, but painful). – moewe May 01 '20 at 14:26
  • I've got to ask: Is this for the FOM bibliography/citation style? – moewe May 01 '20 at 14:27
  • Yes, you are right it is for the FOM and yes it is a bit messy because of different wishes from different Profs. And because Version date ist mostly the same as publishing year, i'will create a new cite type, different from \footcite. – dhd80 May 01 '20 at 14:35
  • Are you already aware of https://github.com/andygrunwald/FOM-LaTeX-Template and the many discussions about FOM style on goLaTeX (https://golatex.de/literaturverzeichnis-anpassung-t21484.html, https://golatex.de/erweiterter-chicago-style-t21409.html, https://golatex.de/viewtopic,p,92889.html, https://golatex.de/viewtopic,p,98865.html, https://golatex.de/viewtopic,p,99465.html)? – moewe May 01 '20 at 14:39
  • Thanks for the hint, but my FOM-Branch differs in expectation (don't know why) from Andy's Template on Github. So I decided, to do some major changes to it. – dhd80 May 01 '20 at 14:43
  • But I didn't know the golatex thread, many thanks! – dhd80 May 01 '20 at 14:44

1 Answers1

1

For dates I suggest you use biblatex's date fields. From what I can see you don't even need to define new date fields (which is possible, see e.g. askdate in How can I create entirely new data types with BibLaTeX/Biber?), you can just use date for the publication date (date = {2009-01-01}, in the example) and urldate for the access date (urldate = {2020-04-28T13:21:00}, in the example).

Then you can print the dates with \printdate and \printurldate and you can set up the date formats with the date and urldate options.


The bibliography driver shown in the question is a bit unidiomatic.

It is common to separate out logical blocks of code into reusable bibmacros so that the driver code is clearer (also: shorter) and easier to modify (you may only have to change the bibmacro, not the driver). Of course this is by no means a requirement, but it is very common.

Formatting commands like \textit should never appear on a driver and almost never appear on a bibmacro level

\textit{\printnames{author}}%

Instead formatting should be applied via field (or list or name) formats. To get italic names for authors/editors at the beginning of the entry, you would for example use

\DeclareNameWrapperFormat{sortname}{\mkbibemph{#1}}

with authoryear- and authortitle-based standard styles.

Similarly parentheses and angle brackets are usually applied in a field format and not via \setunit.

Hard-coded text like "Zugriff" and "Uhr" should ideally be replaced with bibstrings, in any case it too should be used in field formats.


As guessed and confirmed in the comments this is a version of the bibliography style for the German FOM university. A template for FOM term papers/theses is available at https://github.com/andygrunwald/FOM-LaTeX-Template, but apparently there are often small differences between what people need and the requirements say. There are also many discussions on the German goLaTeX forum about that style: https://golatex.de/viewtopic,p,104643.html, https://golatex.de/viewtopic,p,104202.html, http://golatex.de/viewtopic,p,92889.html, http://golatex.de/viewtopic,p,98865.html, http://golatex.de/viewtopic,p,99465.html

The following code from my answer in https://golatex.de/viewtopic.php?p=109679#p109679 should come quite close to the bibliography entry you show. As you can see it was not required to rewrite the bibliography driver. The desired result could be achieved by redefining bibmacros and some patching of the drivers.

Note that this code uses usera for the "Stichwort".

\documentclass[ngerman]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[autostyle, german=guillemets]{csquotes}
\usepackage[backend=biber, style=ext-authoryear,
  isbn=false,
  maxcitenames=2, maxbibnames=999,
  mergedate=false,
  innamebeforetitle, dashed=false,
  autocite=footnote, mincrossrefs=1,
  alldates=comp, labeldate=year,]{biblatex}


\setlength{\bibinitsep}{.5\baselineskip}

\setlength\bibhang{1cm}

\DeclareLabeldate{%
  \field{date}
  \field{year}
  \field{eventdate}
  \field{origdate}
  \literal{nodate}
}

\renewcommand*{\finentrypunct}{}

\renewcommand*{\newunitpunct}{\addcomma\space}
\DeclareDelimFormat[bib,biblist]{nametitledelim}{\addcolon\space}
\DeclareDelimFormat{titleyeardelim}{\newunitpunct}

\renewcommand*{\mkbibcompletename}{\mkbibemph}

\DeclareDelimAlias{finalnamedelim}{multinamedelim}

\DeclareNameFormat{family-given:init}{%
  \usebibmacro{name:family-given}
    {\namepartfamily}
    {\namepartgiveni}
    {\namepartprefix}
    {\namepartsuffix}%
  \usebibmacro{name:andothers}}

\DeclareNameAlias{default}{family-given}
\DeclareNameAlias{sortname}{default}
\DeclareNameAlias{labelname}{family-given:init}

\DeclareFieldFormat{editortype}{\mkbibparens{#1}}
\DeclareDelimFormat{editortypedelim}{\addspace}
\DeclareFieldFormat{translatortype}{\mkbibparens{#1}}
\DeclareDelimFormat{translatortypedelim}{\addspace}

\DeclareDelimFormat[bib,biblist]{innametitledelim}{\addcomma\space}

\DeclareFieldFormat*{citetitle}{#1}
\DeclareFieldFormat*{title}{#1}
\DeclareFieldFormat*{booktitle}{#1}
\DeclareFieldFormat*{journaltitle}{#1}

\newbibmacro*{organization+location}[1]{%
  \printlist{location}%
  \setunit*{\locdatedelim}%
  \printlist{organization}%
  \newunit}

\usepackage{xpatch}
\xpatchbibdriver{online}
  {\usebibmacro{organization+location+date}}
  {\usebibmacro{organization+location}}
  {}{}

\DeclareFieldFormat[online]{date}{\mkbibparens{#1}}

\DeclareFieldFormat{url}{<\url{#1}>}% oder {$\langle$\url{#1}$\rangle$} oder \textlangle/\textrangle
\DeclareFieldFormat{urldate}{\mkbibbrackets{\bibstring{urlseen}\addcolon\space#1}}
\renewbibmacro*{url+urldate}{%
  \usebibmacro{url}%
  \ifentrytype{online}
    {\setunit{\addspace}%
     \usebibmacro{date}}
    {}%
  \iffieldundef{urlyear}
    {}
    {\setunit*{\addspace}%
     \usebibmacro{urldate}}}

\renewbibmacro*{date+extradate}{%
  \printtext[parens]{%
    \printfield{usera}%
    \setunit{\printdelim{titleyeardelim}}%
    \printlabeldateextra}}

\renewbibmacro*{date}{%
  \usebibmacro{bbx:ifmergeddate}
    {}
    {\iffieldundef{year}
       {\printtext[date]{\bibstring{nodate}}}
       {\printdate}}}

\DefineBibliographyStrings{german}{
  nodate    = {{}o.\adddot \addabbrvspace J\adddot},
  andothers = {et\addabbrvspace al\adddot},
  urlseen   = {Zugriff},
}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pernottype{set}
      \step[notfield=translator, final]
      \step[notfield=editor, final]
      \step[fieldset=author, fieldvalue={\string{o.\noexpand\,V\noexpand\adddot\string}}, final]
      \step[fieldset=sortname, fieldvalue={zzzzzzzzz}]
    }
    \map{
      \pernottype{online}
      \step[fieldset=location, fieldvalue={o.\noexpand\,O\noexpand\adddot}]
    }
  }
}

\renewbibmacro*{cite}{%
  \iffieldundef{shorthand}
    {\ifthenelse{\ifnameundef{labelname}\OR\iffieldundef{labelyear}}
       {\usebibmacro{cite:label}%
        \setunit{\printdelim{nonametitledelim}}}
       {\printnames{labelname}%
        \setunit{\printdelim{nametitledelim}}}%
     \printfield{usera}%
     \setunit{\printdelim{titleyeardelim}}%
     \usebibmacro{cite:labeldate+extradate}}
    {\usebibmacro{cite:shorthand}}}

\renewbibmacro*{postnote}{%
  \setunit{\postnotedelim}%
  \iffieldundef{postnote}
    {\printtext{o\adddot\addabbrvspace S\adddot}}
    {\printfield{postnote}}}


\begin{filecontents*}{\jobname.bib}
@online{test1Mit,
  author  = {Artur Autor},
  title   = {Internetquelle mit Datum},
  url     = {http://example.edu/~elk/bronto.pdf},
  urldate = {2018-03-26},
  date      = {2000-06-09},
  usera   = {Test Stichwort1} ,
}
@online{test1Ohne,
  author  = {Artur Autor},
  title   = {Internetquelle ohne Datum},
  url     = {http://example.edu/~elk/bronto.pdf},
  urldate = {2018-03-26},
  usera   = {Test Stichwort2},
}
@book{test2Mit,
  author    = {Artur Autor},
  title     = {Buch mit Datum},
  edition   = {1},
  usera     = {Test Stichwort3},
  publisher = {FOMVerlag},
  location  = {Essen},
  date      = {2000}
}
@book{test2Ohne,
  author    = {Artur Autor},
  title     = {Buch ohne Datum},
  edition   = {1},
  usera     = {Test Stichwort4},
  publisher = {FOMVerlag},
  location  = {Essen},
}
\end{filecontents*}
\addbibresource{\jobname.bib}

\begin{document}
\cite{test1Mit}
\cite{test1Ohne}
\cite{test2Mit}
\cite{test2Ohne}
\printbibliography[nottype=online]
\printbibliography[type=online,title={Internetquellen}]
\end{document}

Autor, Artur (Test Stichwort1, 2000b): Internetquelle mit Datum, <http://example.edu/~elk/bronto.pdf> (9. Juni 2000) [Zugriff: 26. März 2018]

moewe
  • 175,683