4

I have the requirement to print the labels for the entries in the bibliography in bold, replace the , between multiple authors (if any) with ; and end them with :. The following picture is an example from my guidelines:
enter image description here
I suppose that should be possible by modifying my custom .bst file and especially the format.names function. Based on this and this I came up with the following function:

FUNCTION {makebold}{
{ duplicate$ empty$
    { pop$ "" }
    { "\textbf{" swap$ * "}" * }
  if$ 
}

However, when I add it to my bst file I only get compilation errors without even calling the function, just by copying it into the file.
This is my current format.names function.

FUNCTION {format.names}
{ 'bibinfo :=
  duplicate$ empty$ 'skip$ {
  's :=
  "" 't :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{vv~}{ll}{, jj}{, f{.}.}"
      format.name$
      bibinfo bibinfo.check
      't :=
      nameptr #1 >
        {
          nameptr #2
          #1 + =
          numnames #2
          > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
          namesleft #1 >
            { ", " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              "," *
              t "others" =
                {
                  " " * bbl.etal *
                }
                { " " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
  } if$
}

I have no experience with bst files at all, but need this fixed, because my instructor is already complaining that I should use Word instead of LaTeX and he will force me to migrate my paper if I can't sort out his beloved bibliography style :(

It would be really nice if someone could help me print my entries the way they should be!
Last remark: don't know if that's relevant, but the names should not be bold in the text like when I'm using \citep etc.

Update: I've managed (with pure trial and error) to get the labels bold (I had to rename the function to bolden instead of makebold, don't know why) and replace the comma between authors with a semicolon. What's still missing is the final colon between the author list and the title.
My current format.names looks like that:

FUNCTION {format.names}
{ 'bibinfo :=
  duplicate$ empty$ 'skip$ {
  's :=
  "" 't :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{vv~}{ll}{, jj}{, f{.}.}"
      format.name$ bolden
      bibinfo bibinfo.check
      't :=
      nameptr #1 >
        {
          nameptr #2
          #1 + =
          numnames #2
          > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
          namesleft #1 >
            { "; " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              "" *
              t "others" =
                {
                  " " * bbl.etal bolden *
                }
                { "; " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
  } if$
}
  • It is easier to modify using biblatex, as the commands are in latex style. – Bernard Feb 16 '14 at 13:29
  • @Bernard I would happily use biblatex instead, but don't have any clue about that either. So I'm afraid that migrating my whole custom bst file to biblatex would take even longer and I'm running out of time already. Wrong assumption? – marce Feb 16 '14 at 13:32
  • You don't really say much about the overall formatting requirements, so it's difficult to give a full solution. You may want to take at the file aer.bst (likely in the directory .../texmf-dist/bibtex/bst/economic) for an example of a bibliography style that puts the authors' names in bold. Or, take a look at the file ecta.bst (in the same directory as aer.bst) for an example of a style file that sets the authors' names in small caps; if the rest of the formatting performed by this style file suits your needs, changing the function \textsc to \textbf should be a snap. – Mico Feb 16 '14 at 14:58
  • Well, biblatex has, out of the box, an author-year style (several variants, actually), a natbib compatibility mode, so perchance it would be only a matter of some minor adjustments. For instance, the problem of semicolons would be solved by adding in the preamble : \renewcommand*{\multinamedelim}{\addsemicolon\space}. I think it's much easier to understand than the bibtex language. If you could send a minimal example of what you need precisely, I could give a try. – Bernard Feb 16 '14 at 14:58
  • @Bernard Sounds great, thanks! I have translated a part of the requirements for you link. If you can provide me with one or two working examples I hope that I will be able to construct the remaining myself. – marce Feb 16 '14 at 15:37
3

Here is a code using biblatex that seems to fulfill the requirements:

        \documentclass[german]{article}%mkbib
        \usepackage[T1]{fontenc}
        \usepackage[utf8]{inputenc}
        \usepackage{lmodern}
        \usepackage{babel}%
        \usepackage{csquotes}
        \usepackage{xpatch}
        \usepackage[backend=biber, style=authoryear, firstinits, mergedate=false]{biblatex}

        \addbibresource{marcedb.bib}
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        \renewcommand*{\multinamedelim}{\addsemicolon\space}
        \renewcommand*{\subtitlepunct}{\addcolon\space}
        \renewcommand*{\newunitpunct}{\addcomma\space}
        \renewcommand*{\finentrypunct}{\addperiod}
        \renewcommand*{\revsdnamepunct}{\addcomma\space}%
        \renewcommand*{\finalnamedelim}{\multinamedelim}
        \renewcommand*{\mkbibnamelast}[1]{\textsc{#1}}%
        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        \DeclareNameAlias{sortname}{last-first}
        \DeclareNameFormat{last-first}{%
          \iffirstinits
            {\mkbibbold{\usebibmacro{name:last-first}{#1}{#4}{#5}{#7}}}%
            {\mkbibbold{\usebibmacro{name:last-first}{#1}{#3}{#5}{#7}}}%
          \usebibmacro{name:andothers}}

        \renewcommand*{\labelnamepunct}{\bfseries\addcolon\space}

        \renewbibmacro*{date+extrayear}{}%

        \renewbibmacro*{date}{%
        \mkbibparens{\printdate}}%

        \renewbibmacro*{issue+date}{%
                \printtext{\usebibmacro{date}}
                \setunit*{\addcomma\space}
                \printfield{issue}
         \newunit}

        \renewbibmacro*{series+number}{%
         \addcomma\space
         \iffieldundef{series}{}{\printtext[parens]{\printfield{series}%
          \setunit*{\addsemicolon\space}%
          \printfield{number}}}%
          \newunit}

        \renewbibmacro*{publisher+location+date}{%
          \printlist{location}%
          \iflistundef{publisher}{}%
          {\addspace\printtext{u.a.:}}
          \printlist{publisher}%
          \addspace%
          \usebibmacro{date}%
          \newunit}

        \xpatchbibmacro{byeditor+others}%
        {\usebibmacro{byeditor+othersstrg}%
             \setunit{\addspace}%
             \printnames[byeditor]{editor}%
             \clearname{editor}%
             \newunit}%
        {\printnames[byeditor]{editor}%
             \clearname{editor}%
             \setunit{\addspace}
             \mkbibparens{Ed\addperiod}%
             \newunit}%

        \xpatchbibdriver{inbook}{%
          \newunit\newblock
        \usebibmacro{maintitle+booktitle}%
          \newunit\newblock
          \usebibmacro{byeditor+others}}%
          {%
          \iffieldundef{bybookauthor}{}%
         { \newunit\newblock}%
          \usebibmacro{byeditor+others}%
          \setunit{\addcolon\space}\newblock
          \usebibmacro{maintitle+booktitle}}%
          {}{}%

        \renewbibmacro*{journal+issuetitle}{%
          \usebibmacro{journal}%
          \setunit*{\addcomma\space}%
          \iffieldundef{series}
            {}
            {\newunit
             \printfield{series}%
             \setunit{\addspace}}%
          \usebibmacro{volume+number+eid}%
          \setunit{\addspace}%
          \usebibmacro{issue+date}%
          \setunit{\addcolon\space}%
          \usebibmacro{issue}%
          \newunit}

            \begin{document}

             \nocite{*}
              \printbibliography

            \end{document}

and the result:enter image description here

  • @marce: I posted a solution using biblatex, with a patched author-year style that seems to work with 4 examples (article, book and inbook entries). If there other specifications, let me know. – Bernard Feb 17 '14 at 16:11
  • 1
    @marce: I eventually localize the problem – due to author-year.bbx redefining the issue+date bibmacro. Now the spurious space between the opening parenthesis and the year has moved in front of the parenthesis, and I added a comma that I had forgotten (between the year and the issue). – Bernard Feb 27 '14 at 2:40
2

Alright, I was able to fix the problems :) I'll post the solution here in case someone else stumbles about the problem in the future.
Three steps are required. First, this is the correct format.names:

FUNCTION {format.names}
{ 'bibinfo :=
  duplicate$ empty$ 'skip$ {
  's :=
  "" 't :=
  #1 'nameptr :=
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { s nameptr
      "{vv~}{ll}{, jj}{, f{.}.}"
      format.name$ bolden
      bibinfo bibinfo.check
      't :=
      nameptr #1 >
        {
          nameptr #2
          #1 + =
          numnames #2
          > and
            { "others" 't :=
              #1 'namesleft := }
            'skip$
          if$
          namesleft #1 >
            { "\textbf{;} " * t * }
            {
              s nameptr "{ll}" format.name$ duplicate$ "others" =
                { 't := }
                { pop$ }
              if$
              "" *
              t "others" =
                {
                  " " * bbl.etal bolden * 
                }
                { "\textbf{;} " * t * }
              if$
            }
          if$
        }
        't
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
  } if$
  ": " bolden *
}

This is a working bolden method:

FUNCTION {bolden}
{ duplicate$ empty$
    { pop$ "" }
    { "\textbf{" swap$ * "}" * }
  if$
}

Step two is to add output.nonperiod after the format.authors call in an entry function to remove an additional dot.

FUNCTION {article}
{ output.bibitem
  format.authors output.nonperiod "author" output.check
  author format.key output
  new.block
  format.title "title" output.check
  new.block
  crossref missing$
    {
      journal
      "journal" bibinfo.check
      "journal" output.check
      format.vol.num.pages output
      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  format.issn output
  new.block
  format.note output
  format.eprint output
  fin.entry
}

Step three is the most annoying part: Repeat step two for every entry you are using.

This isn't a nice or clean solution, but the hack does what I need it to do, so I'm satisfied for the moment :)

Edit: Just for completeness, Bernard's answer should be preferred. I forgot to add the nonperiod methods here:

FUNCTION {output.nonperiod.nonnull}
{ 's :=
  write$
  s
}
FUNCTION {output.nonperiod}
{ duplicate$ empty$
    'pop$
    'output.nonperiod.nonnull
  if$
}

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.