# Editing bst file to add “page” or “pages”

I've got this bst file http://pastebin.com/z6mXByj7 and am using this tex:

\documentclass[10pt,oneside,letterpaper,spanish]{book}
\usepackage[utf8x]{inputenc}
\usepackage[activeacute,spanish]{babel}
\decimalpoint %\spanishdecimal{.}

\usepackage[spanish]{babel}
\usepackage{natbib}
\usepackage{ulem}
\def\bbluline#1{\uline#1}

\begin{document}
asdasd \citep{chsh_inequality} asdasd \citep*{aspect_test_bell}
\bibliography{ejem_biblio}

\end{document}


with this bib file

% This file was created with JabRef 2.5.
% Encoding: Cp1252

@ARTICLE{chsh_inequality,
author = {{Clauser}, J.~F. and {Horne}, M.~A. and {Shimony}, A. and {Holt}, R.~A.
},
title = "{Proposed Experiment to Test Local Hidden-Variable Theories}",
journal = {Physical Review Letters},
year = 1969,
month = oct,
volume = 23,
number = 15,
pages = {880-884},
doi = {10.1103/PhysRevLett.23.880},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

@ARTICLE{aspect_test_bell,
author = {{Aspect}, A. and {Grangier}, P. and {Roger}, G.},
title = "{Experimental Tests of Realistic Local Theories via Bell's Theorem}",
journal = {Physical Review Letters},
keywords = {Fluorescence, phosphorescence},
year = 1981,
month = aug,
volume = 47,
number = 15,
pages = {460-463},
doi = {10.1103/PhysRevLett.47.460},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}


which produces the following output

that is exactly what I need except for the fact that it should place the particle for pages "pp" before 460-460 and 880-884. Can this be done by editing the bst file?

-
By the way, why do you load babel twice? –  Guido Jan 5 '13 at 20:06
Uhhh well, I'm relatively new to latex, and still have a tendency to use other people's code blindly. I hadn't noticed. –  Oscar Lazo Jan 6 '13 at 0:08
Yes that can be done by editing the .bst file. –  Nicholas Hamilton Jan 6 '13 at 5:14

You have to change the definition of the function format.journal.pages as follows

FUNCTION {format.journal.pages}
{ pages duplicate$empty$ 'pop${ swap$ duplicate$empty$
{ pop$pop$ format.pages }
{
", " *
swap$pop$
format.pages *
}
if$} if$
}


Notice that this works only for entries of type article.

-
I suppose that the function format.pages should be modified. –  Herbert Jan 5 '13 at 20:39
That returned to me the following errors after bibtex ptr=1, stack= \textbf{80},pp 2245--2248 ---the literal stack isn't empty for entry wooters_cocurrence while executing---line 1586 of file fiuady.bst (There were 18 error messages) –  Oscar Lazo Jan 5 '13 at 20:46
I have updated the code. Does it work? –  Guido Jan 6 '13 at 4:21
@Herbert Modifying format.pages would not work in this case (unless very heavy modifications of the whole style). The in article the function format.journal.pages is used instead of format.pages and format.journal.pages takes care if other elements (journal number) is present. One has to do similar modification to the special functions used for the various entry types to output the pages. –  Guido Jan 6 '13 at 9:00

In my .bst file, I have the bbl.pages and bbl.page functions, which control the pre-formatting for references containing single and multiple pages.

FUNCTION {bbl.pages}
{ "pp." }

FUNCTION {bbl.page}
{ "p." }


These functions can be modified from from pp. to Pages:, and, p. to Page: respectively, as follows:

FUNCTION {bbl.pages}
{ "Pages:" }

FUNCTION {bbl.page}
{ "Page:" }


To appreciate how this will effect your final document, the functions bbl.pages and bbl.page, above, are later called in the format.pages function:

FUNCTION {format.pages}
{ pages duplicate$empty$ 'skip${ duplicate$ multi.page.check
{
bbl.pages swap$n.dashify } { bbl.page swap$
}
if$tie.or.space.prefix "pages" bibinfo.check * * } if$
}


In the format.pages function, after firstly checking whether the pages field is empty (skipping if true), it then checks whether single or multiple pages are involved (multi.page.check), calling the bbl.page and bbl.pages functions respectively.

-
In the provided bst style the function format.pages is the same as what you have. The issue is that article calls format.jornal.pages which calls format.pages when there is no volume number, but format directly the page numbers without inserting the page abbreviation ("pp" or "p"). –  Guido Jan 6 '13 at 7:14
@Guido, where is the switch based on no volume number? –  Nicholas Hamilton Jan 6 '13 at 7:30
If you look at the function format.journal.pages you can see that it puts pages on the stack, it duplicates it, and it the values is empty it removes it. Otherwise, it swaps pages with the previous element on the stack (and it is an educated guess from the output that it is the volume number), it duplicates it and check if it is empty. If it is it remove the last two elements from the stack (pop$pop$), where, now, the second last is pages and then executes format.pages. Then we have the branch where there is value of pages, and there is a value for the previous element. –  Guido Jan 6 '13 at 8:53