5

I am compiling a bibliography in a book by means of bibtex using plain.bst style (or rather its Polish version plplain.bst). Using answers to other questions on similar problems, I have modified plplain.bst so as to change the default order of names and surnames, and now an exemplary entry from my bibliography looks like this:

enter image description here

However, I do not know how to convince bibtex to put a comma after the name's initial (and before the title) to have something like the following:

[10] Surname, N., The title

and similarly in case of more than one author or more than one-letter initials. I tried tinkering with bst file, yet with no success. Currently, the part of the file responsible for names syntax looks like this:

FUNCTION {format.names}
{ 's :=
#1 'nameptr :=
s num.names$ 'numnames :=
    numnames 'namesleft :=
{ namesleft #0 > }
{ s nameptr "{vv }{ll}{, jj}{, f.}" format.name$ 't :=
  nameptr #1 >
{ numnames #2 =
    { ", " * }
    'skip$
 if$
     namesleft #1 >
    { ", " * t * }
    { numnames #2 >
    { "," * }
    'skip$
      if$
      t "others" =
            { " i~in." * }
            { " " * t * }
          if$
    }
  if$
}
't
  if$
  nameptr #1 + 'nameptr :=
  namesleft #1 - 'namesleft :=
}   
while$ }

I would be grateful if you could explain to me how to achieve what I want.

Following Guido's answer and my problems with implementation of his solution I thought I could add code of those fragments of bst file to which he refers.

FUNCTION {format.authors}
{ author empty$
{ "" }
{ author format.names }
if$
 }

FUNCTION {output.nonnull}
{ 's :=
    output.state mid.sentence =
    { ", " * write$ }
    { output.state after.block =
    { add.period$ write$
      newline$
      "\newblock " write$
    }
    { output.state before.all =
        'write$
        { add.period$ " " * write$ }
      if$
    }
      if$
      mid.sentence 'output.state :=
    }
  if$
  s
}

FUNCTION {output.check}
{ 't :=
  duplicate$ empty$
    { pop$ "empty " t * " in " * cite$ * warning$ }
    'output.nonnull
  if$
}

I probably misunderstood something from Guido's answer, so it would be great if you could help me to get it straight.

  • You seem to have output.state mid.sentence = rather than mid.sentence output.state :=. Or is that the original and not what you've tried? Note that you shouldn't be editing plplain.bst itself but a renamed copy of it. – cfr May 21 '16 at 0:55
  • I have edited <code>myplplain.bst</code>. The part you mention is in its original form. – Mad Hatter May 21 '16 at 5:17
7
+50

The punctuation sign after the name is determined by the function output.check that, in case the name is not empty calls the function output.nonnull. Shortly, output.nonnull prints a comma if we are in the middle of a sentence, or a period or a space. The style uses the variable output.state to store if we are in the middle of a sentence or elsewhere. Thus, one has to set that value while formatting a name. To achieve this we can insert such an assignment at the end of the function (followed by swap$ to keep the formatting of the name in the stack )

mid.sentence 'output.state :=
swap$

Thus the function now is:

FUNCTION {format.names}
{ 's :=
#1 'nameptr :=
s num.names$ 'numnames :=
    numnames 'namesleft :=
{ namesleft #0 > }
{ s nameptr "{vv }{ll}{, jj}{, f.}" format.name$ 't :=
  nameptr #1 >
{ numnames #2 =
    { ", " * }
    'skip$
 if$
     namesleft #1 >
    { ", " * t * }
    { numnames #2 >
    { "," * }
    'skip$
      if$
      t "others" =
            { " i~in." * }
            { " " * t * }
          if$
    }
  if$
}
't
  if$
  nameptr #1 + 'nameptr :=
  namesleft #1 - 'namesleft :=
  mid.sentence 'output.state :=
  swap$
}
while$ }

Notice, this will affect all the names (authors and editors). In case one wants to insert the comma only after the authors and not the editors, one can modify the format.authors function as follows:

FUNCTION {format.authors}
{ author empty$
    { "" }
    { author format.names
    mid.sentence 'output.state :=
    swap$
    }
  if$
}

A problem with the solution above is that different entry types use either output.check or output.nonnull (or output). The issue is that output.check and output.nonnull have different inputs, thus one has to change "<authors>" output.check to output.nonnull, also this requires more work for the editors.

Another alternative is to change the function that actually prints the comma (new.block). Thus we can create a my.new.block function with the following definition:

FUNCTION {my.new.block}
{ duplicate$ empty$
    { skip$ }
    {
     ", " * }
  if$
  before.all 'output.state :=
  new.block
}

and replace the first occurrence of new.block with my.new.block in all functions defining how the various entry types are going to be formatted.

For example, for article we get

FUNCTION {article}
{ output.bibitem
  format.authors "authors"  output.check
    my.new.block  %                    <=== was new.block 
  format.title "title" output.check
  new.block
  crossref missing$
    { journal emphasize "journal" output.check
      format.vol.num.pages output
      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  new.block
  note output
  fin.entry
}

enter image description here

  • When I put "mid.sentence output.state :=" into the output.nonnull function, the result is 568 errors and entries which consist of year itself only. Putting "mid.sentence output.state =" has no influence on the output (I already have " output.state mid.sentence =" in the function). In case of the latter suggestion (with format.authors), putting the string with ":=" has no influence on the outcome, with "=" causes bibtex to repeat authors' names. In the first case I have 61 errors, in the second 158. I do not think I grasped your ideas ;) – Mad Hatter May 19 '16 at 17:04
  • 1
    @MadHatter Indeed there was a problem in the previous solution. The definition above should now work. – Guido May 22 '16 at 1:35
  • It works, but only with book type entries. Journal entries are not affected at all. – Mad Hatter May 23 '16 at 14:56
  • Guido, to be more specific. The first proposal, with format.names results in putting a coma at the very beginning of every article entry, names follow, and there's no comma separating them from the title. The second proposal gives properly formatted book entries (i.e. with respect to my question). Yet article entries are the same as originally. Both proposals cause bibtex to say: Warning--empty author in ... in all article entries. – Mad Hatter May 23 '16 at 15:19
  • Guido, the solution with <code>my.new.block</code> function works perfectly. Thanks for all your help! – Mad Hatter May 25 '16 at 8:29

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.