TransWikia.com

Custom biblatex style for articles

TeX - LaTeX Asked by philipp_th on March 7, 2021

I have to use a quite unique citation style for my dissertation and have therefore strated to customize a biblatex.cfg file. I use verbose style as a base and came quite far already with other items, however, articles still pose a problem. Articles have to be cited in the following format:

author, title, journalshort year, firstpage (pageref).

In consequent citations the title is dropped. If journalshort is not available, then I have to use journaltitle

For now I have the following biblatex.cfg:

 % -- comma between bibliography units
 renewcommand*{newunitpunct}{addcommaspace}
 
 % -- No prefix for pages 
 DeclareFieldFormat{pages}{#1}
 DeclareFieldFormat{postnote}{#1}
 DeclareFieldFormat{multipostnote}{#1}
 
 % -- No italic titles
 DeclareFieldFormat{title}{#1}
 DeclareFieldFormat{booktitle}{#1}
 DeclareFieldFormat{citetitle}{#1}
 DeclareFieldFormat{journaltitle}{#1}
 
 % -- No "'" for title
 DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{citetitle}{#1}
 DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
 
 % -- Authors and editors in italic and only show surname
 DeclareNameFormat{family}{mkbibemph{%
     usebibmacro{name:family}
     {namepartfamily}
     {namepartgiven}
     {namepartprefix}
     {namepartsuffix}}%
     usebibmacro{name:andothers}}
 DeclareNameAlias{default}{family}
 DeclareNameAlias{sortname}{default}
 DeclareNameAlias{labelname}{default}
 
 % -- "/" between names but "," and "and" in textcite
 DeclareDelimFormat{multinamedelim}{slash}
 DeclareDelimAlias{finalnamedelim}{multinamedelim}
 DeclareDelimFormat[textcite]{multinamedelim}{addcommaspace}
 DeclareDelimFormat[textcite]{finalnamedelim}{addnbspacebibstring{and}space}
     
 DeclareBibliographyDriver{article}{%
 usebibmacro{bibindex}%
 usebibmacro{begentry}%
 usebibmacro{author}%
 setunit{printdelim{nametitledelim}}newblock
 usebibmacro{maintitle+title}%
 setunit{addcommaaddspace}newblock
 iffieldundef{shortjournal}{iffieldundef{journaltitle}{}{printtext[journaltitle]{printfield{journaltitle}}}}{printtext[journaltitle]{printfield[titlecase]{shortjournal}}}%
 setunit{addspace}newblock
 printfield{year}%
 mkfirstpage{printfield{pages}}%
 setunit{addspace}newblock
 parentext{usebibmacro{pageref}}%
 newunitnewblock
 iftoggle{bbx:related}{usebibmacro{related:init}%
 usebibmacro{related}}{}%
 usebibmacro{finentry}}

Using this example:

documentclass{article}
usepackage[backend=biber, style=verbose]{biblatex}
addbibresource{jobname.bib}
usepackage{filecontents}

begin{filecontents}{jobname.bib}
@article{citation,
  title = {Short title: Long title},
  shorttitle = {Short title},
  author = {Doe, John},
  date = {1995},
  journaltitle = {Journal Title},
  shortjournal = {JT},
  pages = {120--130}
}
end{filecontents}

begin{document}

cite[125]{citation}

cite[127]{citation}

printbibliography

end{document}

I get:

Doe, Short title: Long title, JT 1995(), 125

Doe, Short title, 127

References

Doe, Short title: Long title, JT 1995120–130().

But I would need:

Doe, Short title: Long title, JT 1995, 120 (125).

Doe, JT 1995, 120 (128).

References

Doe, Short title: Long title, JT 1995, 120.

  1. How can I show the first page of the article appears on? I cannot
    seem to show mkfirstpage{printfield{pages}}.
  2. How can I put pageref in parenthesis?
  3. How can I drop the title in subsequent citations?

One Answer

  1. mkfirstpage{printfield{pages}} won't work as expected. You need to use mkfirstpage in DeclareFieldFormat, because it expects simple text and not a complex macro as input. (Plus it is always recommended to use formatting commands only in DeclareFieldFormat and not directly in bibmacros or drivers. Using macros around printfield can have other unintended consequences especially if the field happens to be empty.) So you want

    DeclareFieldFormat[article]{pages}{mkfirstpage{#1}} 
    
  2. The pageref macro does not format the page number you pass to your cite command. That page number is formatted by postnote. pageref is used for back-references. You need to modify the postnote field format and probably want to leave pageref alone.

  3. This is trickier. Printing the journal name in subsequent short citations, but not the title obviously only makes sense for @article entries and not for other types, so you need type-specific short citations. This can be implemented as shown in Customize verbose citation style, Custom type disappears in subsequent citations and Make style=verbose's short citations for @online more verbose.

In total you could try something like this

documentclass{article}
usepackage[backend=biber, style=verbose]{biblatex}

renewcommand*{newunitpunct}{addcommaspace}

renewcommand*{mkbibnamefamily}{mkbibemph}

DeclareNameFormat{family}{%
  usebibmacro{name:family}
    {namepartfamily}
    {namepartgiven}
    {namepartprefix}
    {namepartsuffix}%
  usebibmacro{name:andothers}}

DeclareNameAlias{default}{family}
DeclareNameAlias{sortname}{default}
DeclareNameAlias{labelname}{default}

DeclareDelimFormat{multinamedelim}{slash}
DeclareDelimAlias{finalnamedelim}{multinamedelim}
DeclareDelimFormat[textcite]{multinamedelim}{addcommaspace}
DeclareDelimFormat[textcite]{finalnamedelim}{addnbspacebibstring{and}space}

DeclareFieldFormat{title}{#1}
DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{title}{#1}
DeclareFieldFormat{booktitle}{#1}
DeclareFieldFormat{citetitle}{#1}
DeclareFieldFormat[article,inbook,incollection,inproceedings,patent,thesis,unpublished]{citetitle}{#1}
DeclareFieldFormat{journaltitle}{#1}

renewcommand*{subtitlepunct}{addcolonspace}

DeclareFieldFormat{pages}{#1}
DeclareFieldFormat[article]{pages}{mkfirstpage{#1}}
DeclareFieldFormat{postnote}{mknormrange{#1}}
DeclareFieldFormat[article]{postnote}{%
  ifpages{#1}
    {mkbibparens{mknormrange{#1}}}
    {mknormrange{#1}}}
DeclareFieldFormat{multipostnote}{#1}

DeclareDelimFormat{postnotedelim}{%
  ifboolexpr{
        test {ifentrytype{article}}
    and test {iffieldpages{postnote}}}
    {addspace}
    {addcommaspace}%
}

DeclareBibliographyDriver{article}{%
  usebibmacro{bibindex}%
  usebibmacro{begentry}%
  usebibmacro{author}%
  setunit{printdelim{nametitledelim}}newblock
  usebibmacro{maintitle+title}%
  setunit{addcommaaddspace}newblock
  iffieldundef{shortjournal}
    {printfield{journaltitle}}
    {printtext[journaltitle]{%
       printfield[titlecase]{shortjournal}}}%
  setunit{addspace}newblock
  printdate
  setunit{bibpagespunct}%
  printfield{pages}%
  setunit{bibpagerefpunct}newblock
  usebibmacro{pageref}%
  newunitnewblock
  iftoggle{bbx:related}
    {usebibmacro{related:init}%
     usebibmacro{related}}
    {}%
  usebibmacro{finentry}}

renewbibmacro*{cite:short}{%
  ifbibmacroundef{cite:short:@strfield{entrytype}}
    {usebibmacro{cite:short:standard}}
    {usebibmacro*{cite:short:@strfield{entrytype}}}}

newbibmacro*{cite:short:standard}{%
  printnames{labelname}%
  setunit*{printdelim{nametitledelim}}%
  printtext[bibhyperlink]{%
    printfield[citetitle]{labeltitle}}}

newbibmacro*{cite:short:@article}{%
  printnames{labelname}%
  setunit*{printdelim{nametitledelim}}%
  printtext[bibhyperlink]{%
    iffieldundef{shortjournal}
      {printfield{journaltitle}}
      {printtext[journaltitle]{%
         printfield[titlecase]{shortjournal}}}%
    setunit{addspace}newblock
    printdate
    setunit{bibpagespunct}%
    printfield{pages}}}

begin{filecontents}{jobname.bib}
@article{citation,
  author       = {Doe, John},
  title        = {Short title},
  subtitle     = {Long title},
  date         = {1995},
  journaltitle = {Journal Title},
  shortjournal = {JT},
  pages        = {120--130},
}
end{filecontents}
addbibresource{jobname.bib}

begin{document}
cite[125]{citation}

cite[127]{citation}

printbibliography
end{document}

Doe, Short title: Long title, JT 1995, 120 (125)//Doe, JT 1995, 120 (127)

Correct answer by moewe on March 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP