[Tex/LaTex] Add parentheses in year in modified plain.bst file

bibtex

I need to correct a paper for a Japanese Journal, that was used for a conference. In the guidelines for Journal, it is stated that references should be:

Name of author(s): "Title", Name of Pubblication, Volume, Number, Page (Year and Month)

Journal provides a document class, but no bst file.
I'm trying to get parentheses in the end, without adding any new package to my source. I'm using bibtex, and I've modified the bst file as follow:

FUNCTION {format.date}
{ year empty$
    { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
          month
        }
      if$
    }
     { month empty$
         'year
        { " (" * year * ")" * }
      if$
    }
  if$
}

that does not work. Also I cannot understand what I've to modify to add : after authors name.

Trying to use the solution listed here (Put year in parentheses…) generates an error.

On this answer I have acknowledged the existence of Bibulous format, that I'll try tomorrow (it is really late here…)

Best Answer

The solution uses Bibulous project script.

Style file is declared as follows:

OPTIONS:
allow_scripts = True

VARIABLES:
formatdate = format_date_style(entry, options)
formatpages = format_pages_style(entry, options)
formatvolume = format_volumes_style(entry, options)

DEFINITIONS:
def format_date_style(entry, options):
  """
  Return correct year for ieej-jia -> (month if present, year) in parentheses
  """

  if ('year' not in entry):
    return(options['undefstring'])
  else:
    if ('month' not in entry):
      return('(' + str(entry['year']) + ')')
    else:
      return('(' + entry['month'].title() + ', ' + str(entry['year'])+ ')')

def format_pages_style(entry, options):
    """
    Returns pages if present
    """

    if ('pages' in entry):
        return(str(entry['pages']) + ', ')
    else:
        return('')

def format_volumes_style(entry, options):
    """
    Return Volume, Number
    """

    ret = ''
    if ('volume' in entry):
        ret = ret + str(entry['volume']) + ', '

    if ('number' in entry):
        ret = ret + str(entry['number']) + ', '

    return(ret)

TEMPLATES:
article       = <au>: ``<title>'', <journal>, <formatvolume> <formatpages> <formatdate>
book          = <au>: ``<title>'', <publisher>, <formatpages> (<year>)
electronic    = <au>: ``\href{<url>}{<title>}'',  (<year>)
inproceedings = <au>: ``<title>'', <booktitle>, <formatpages> (<year>)
incollection  = <au>: ``<title>'', <booktitle>, <publisher>, <formatpages> (<year>)
sortkey       = <citekey>

and reference to this file is inserted in main tex file

\bibliographystyle{previous_file}

Compilation requires three commands (example with pdflatex):

pdflatex main.tex     # to generate aux file
bibulous.py main.aux  # to generate bbl
pdflatex main.tex     # to generate final pdf

Hope it helps.

Related Question