BibTeX, biblatex and biberManually formatted bibstyle for natbib, removing a comma

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Manually formatted bibstyle for natbib, removing a comma

Post by Bozack »

I have a custom style file for natbib, and have a reference to an incollection entry that seems to get an extra comma, like the following:
Result of the minimal working example.
Result of the minimal working example.
Capture.PNG (25.35 KiB) Viewed 22239 times
I would very much like to remove this extra comma, can anyone help me with understanding how to edit the style file such that it is not shown? This might just be a question of deleting the apparent print of a field that is not set.

The minimal working example used to show this:

Code: Select all

\documentclass{article}
\usepackage[english]{babel}
\usepackage{natbib}
  \bibliographystyle{custombst}
\begin{document}
  I now refer to \citet{Wondratschek2006}.
  \bibliography{refs}
\end{document}
with the BiBTeX file refs.bib containing the following entry,

Code: Select all

@incollection{Wondratschek2006,
    author = {Wondratschek, H.},
    booktitle = {International Tables for Crytallography Volume A: Space-group symmetry},
    chapter = {8.1},
    edition = {1st online},
    editor = {Hahn, T.},
    pages = {720--725},
    publisher = {International Union of Crystallography},
    title = {{Basic concepts}},
    year = {2006}}
and the custom style file:
custombst.bst
Custom bst style file needed for the minimal working example to compile.
(31.87 KiB) Downloaded 751 times
babelbst.tex
Babel definitions for the custom bst style.
(3.78 KiB) Downloaded 674 times
On a related note, I would love to be able to edit the style file to write the book title in emphasized format instead of with quotation marks around it.

Thank you so much in advance for anyone spending time on this, it's immensely appreciated! :)
Last edited by Bozack on Sun Jan 12, 2014 6:19 pm, edited 1 time in total.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
mgmillani
Posts: 16
Joined: Fri Dec 20, 2013 7:26 pm

Manually formatted bibstyle for natbib, removing a comma

Post by mgmillani »

It appears that I also need a babelbst.tex file to be able to compile your example.

I would first try to change your editor in the .bib file to:

Code: Select all

 editor = {T. Hahn},
If that doesn't work, my guess would be that the problem is with the definition of \bbleditor or \bbleditors on your babelbst.tex . If you could provide me with that file, I may be able to help you further.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Manually formatted bibstyle for natbib, removing a comma

Post by Bozack »

mgmillani wrote:It appears that I also need a babelbst.tex file to be able to compile your example.
Oh, sorry, I forgot - I've edited the original message to have that file in as well. Just for completeness' sake, here's the content:

Code: Select all

\def\bbland{and}                \def\bbletal{et~al.}
\def\bbleditors{editors}        \def\bbleds{eds.}
\def\bbleditor{editor}          \def\bbled{ed.}
\def\bbledby{edited by}
\def\bbledition{edition}        \def\bbledn{edn.}
\def\bblvolume{volume}          \def\bblvol{vol.}
\def\bblof{of}
\def\bblnumber{number}          \def\bblno{no.}
\def\bblin{in}
\def\bblpages{pages}            \def\bblpp{pp.}
\def\bblpage{page}              \def\bblp{p.}
\def\bbleidpp{pages}
\def\bblchapter{chapter}        \def\bblchap{chap.}
\def\bbltechreport{Technical Report}
\def\bbltechrep{Tech. Rep.}
\def\bblmthesis{Master's thesis}
\def\bblphdthesis{Ph.D. thesis}
\def\bblfirst{First}            \def\bblfirsto{1st}
\def\bblsecond{Second}          \def\bblsecondo{2nd}
\def\bblthird{Third}            \def\bblthirdo{3rd}
\def\bblfourth{Fourth}          \def\bblfourtho{4th}
\def\bblfifth{Fifth}            \def\bblfiftho{5th}
\def\bblst{st}  \def\bblnd{nd}  \def\bblrd{rd}
\def\bblth{th}
\def\bbljan{January}  \def\bblfeb{February}  \def\bblmar{March}
\def\bblapr{April}    \def\bblmay{May}       \def\bbljun{June}
\def\bbljul{July}     \def\bblaug{August}    \def\bblsep{September}
\def\bbloct{October}  \def\bblnov{November}  \def\bbldec{December}
mgmillani wrote:I would first try to change your editor in the .bib file to:

Code: Select all

 editor = {T. Hahn},
Changing from editor = {Hahn, T.} to editor = {T. Hahn} doesn't seem to change anything.
mgmillani wrote:If that doesn't work, my guess would be that the problem is with the definition of \bbleditor or \bbleditors on your babelbst.tex.
Unfortunately I don't see any commas in the babelbst.tex definitions, do you have any ideas?
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
mgmillani
Posts: 16
Joined: Fri Dec 20, 2013 7:26 pm

Manually formatted bibstyle for natbib, removing a comma

Post by mgmillani »

Those commas seem to appear on these 2 functions:

Lines 849-855

Code: Select all

FUNCTION {bt.enquote}
{ duplicate$ empty$ 'skip$
  { "\enquote{" swap$ *
    "}, " *          % Here
  }
  if$
}
Lines 861-879

Code: Select all

FUNCTION {format.in.ed.booktitle}
{ format.booktitle duplicate$ empty$ 'skip$
    {
      format.bvolume duplicate$ empty$ 'pop$
        { ", " swap$ * * }
      if$
      editor "editor" format.names.ed duplicate$ empty$ 'pop$
        {
          bbl.edby
          " " * swap$ *
          swap$
          "," *         % Here
          " " * swap$
          * }
      if$
      word.in swap$ *
    }
  if$
}
I don't know which one is wrong, but replacing one of them with "" works for the example given.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Manually formatted bibstyle for natbib, removing a comma

Post by Bozack »

mgmillani wrote:Those commas seem to appear on these 2 functions [...]
Thank you, you lead me to the correct place! :)
Changing the lines 861-879 to

Code: Select all

FUNCTION {format.in.ed.booktitle}
{ format.booktitle duplicate$ empty$ 'skip$
    {
      format.bvolume duplicate$ empty$ 'pop$
        { ", " swap$ * * }
      if$
      editor "editor" format.names.ed duplicate$ empty$ 'pop$
        {
          bbl.edby
          " " * swap$ *
          swap$
          "" *
          " " * swap$
          * }
      if$
      word.in swap$ *
    }
  if$
}
that is, removing the comma from the "," * on line 872, seems to do the trick.
Bozack wrote:On a related note, I would love to be able to edit the style file to write the book title in emphasized format instead of with quotation marks around it.
Do you think you have an answer on the second part of my original question as well?


You can safely ignore the rest below here, this is simply for future reference if anyone should stumble over this post searching for similar answers:

Just on a side-note, changing line 849-855 to
[code]FUNCTION {bt.enquote}
{ duplicate$ empty$ 'skip$
{ "\enquote{" swap$ *
"}" *
}
if$
}[/code]that is, removing the comma and the space from "}, " on line 852, actually removes the unwanted comma in the final output. However, I am then missing the comma and space before the chapter entry in another reference;
[code]@incollection{Smart1995Chap2part,
author = {Smart, Lesley and Moore, Elaine},
booktitle = {Solid State Chemistry},
chapter = {2.6-2.9},
edition = {2nd},
pages = {102--113},
publisher = {Springer US},
title = {{X-ray diffraction}},
year = {1995}}[/code]The only difference between this Smart1995Chap2part and the reference that I gave earlier, Wondratschek2006, is that Wondratschek2006 has an editor keyword, while Smart1995Chap2part does not.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
mgmillani
Posts: 16
Joined: Fri Dec 20, 2013 7:26 pm

Manually formatted bibstyle for natbib, removing a comma

Post by mgmillani »

If you want to write any title (I refer to the title attribute of bibtex entries ) in emphasized format, you can change this function:

Lines 498-508

Code: Select all

FUNCTION {format.title}
{ title
  "title" bibinfo.check
  duplicate$ empty$ 'skip$
    {
      "\emph{" swap$ * % \enquote replaced with \emph
      "}" *
    }
  if$
}
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Manually formatted bibstyle for natbib, removing a comma

Post by Bozack »

First of all sorry for the late reply, I've been out sick :(
mgmillani wrote:If you want to write any title (I refer to the title attribute of bibtex entries ) in emphasized format, you can change this function: [...]
This indeed changes the formatting of titles, but I actually wanted to change in the booktitle attribute (the title of a book than an incollection entry is from). From what I gather in your example for title, I should edit something in one of the following functions instead:

Lines 856-860

Code: Select all

FUNCTION {format.booktitle}
{
  booktitle "booktitle" bibinfo.check
  bt.enquote
}
I can remove the bt.enquote in the first, and the quotation marks around the book title will disappear. I ended up trying to replace the whole bt.enquote line with the formatting part of your suggestion, so the function is now replaced by

Code: Select all

FUNCTION {format.booktitle}
{
  booktitle "booktitle" bibinfo.check
  duplicate$ empty$ 'skip$
    {
      "\emph{" swap$ *
      "}" *
    }
  if$
}
This seems to at least make the book title emphasized as wanted. But now a new problem arises: The comma between the book title and the chapter+page entries disappears for entries that do not have an editor written as well:
Capture.png
Capture.png (86.82 KiB) Viewed 20916 times
I've attached the updated tex, bst and bib files again, so it should be easy to reproduce with

Code: Select all

\documentclass{article}
\usepackage[english]{babel}
\usepackage{natbib}
  \bibliographystyle{custombst}
\begin{document}
  I now refer to \citet{Wondratschek2006} and \citet{Smart1995Chap2part}.
  \bibliography{refs}
\end{document}
Attachments
refs.bib
(664 Bytes) Downloaded 540 times
babelbst.tex
(3.78 KiB) Downloaded 560 times
custombst.bst
(31.93 KiB) Downloaded 583 times
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
mgmillani
Posts: 16
Joined: Fri Dec 20, 2013 7:26 pm

Manually formatted bibstyle for natbib, removing a comma

Post by mgmillani »

custombst.bst, lines 856-865

Code: Select all

FUNCTION {format.booktitle}
{
  booktitle "booktitle" bibinfo.check
  duplicate$ empty$ 'skip$
    {
      "\emph{" swap$ *
      "} " * % add a space after the '}' here
    }
  if$
}
Just adding that space there seems to do the trick.
Post Reply