%% xypicman.bst derived from $Id: xypicman.bst,v 2.6 1992/06/24 01:23:34 kris Exp $ -*-tex-*-
%%
%% XPPT bibliography style for BibTeX version 0.99.
%% by Hans Dybkjaer <dybkjaer@ruc.dk> and Kristoffer H. Rose <kris@diku.dk>;
%% derived from "natsci.bst" and "plain.bst": very extensive changes!!!
%%
%% This file is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE.

ENTRY
  { address
    annote		%
    author
    booktitle
    chapter
    edition
    editor
    howpublished
    institution
    journal
    key
    month
    note
    number
    organization
    pages
    publisher
    school
    series
    title
    type
    volume
    year
  }
  { extra.num }
  { label citeextra }

STRINGS { s t longest.label }

FUNCTION {not}
{   { #0 }
    { #1 }
  if$
}

FUNCTION {and}
{   'skip$
    { pop$ #0 }
  if$
}

FUNCTION {or}
{   { pop$ #1 }
    'skip$
  if$
}

FUNCTION {field.or.null}
{ duplicate$
  empty$
    { pop$ "" }
    'skip$
  if$
}

STRINGS { lastby }

FUNCTION {output.preamble}
{ "\bibwidestlabel{" longest.label * "}" * write$ newline$
  preamble$ write$ newline$
  "" 'lastby :=
}

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

FUNCTION {output}  
{ pop$
  duplicate$ empty$
    { pop$ pop$ }
    { 's := duplicate$ "" = 'skip$ { " " * } if$ s * write$ newline$ }
  if$
}

FUNCTION {output.crossref}
{ pop$ " \bibcross \cite {" swap$ * "}" * * write$ newline$ }

FUNCTION {output.ref}
{ newline$
  "\bibref{" cite$ * "}{" * label * "}%" * write$ newline$
}

FUNCTION {output.endref}
{ "\endref" write$ newline$ }

FUNCTION {output.bysame}
{ pop$
  't :=
  t empty$ t "" = or
    'skip$
    { t lastby =
	{ "\bysame" }
	{ t duplicate$ 'lastby := }
      if$
      citeextra "" =
	'skip$
	{ " \bibyr {" * year field.or.null purify$ * citeextra * "}" * }
      if$
      write$ newline$ }
  if$
}

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

INTEGERS { nameptr namesleft numnames }

STRINGS {nameresult}


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

FUNCTION {format.author}
{ author empty$
    { "" }
    { "\by " author format.names * }
  if$
}

FUNCTION {format.editor}
{ editor empty$
    { "" }
    { editor num.names$ #1 >
	{ "\eds " editor format.names * }
	{ "\ed "  editor format.names * }
      if$ }
  if$
}

FUNCTION {format.author.or.editor}
{ author empty$
    { format.editor }
    { format.author }
  if$
}

FUNCTION {format.editor.or.key}
{ editor empty$
    { "\by " key * }
    { format.editor }
  if$
}

FUNCTION {format.author.or.editor.or.key}
{ author empty$
    { format.editor.or.key }
    { format.author }
  if$
}


FUNCTION {format.title}
{ title empty$
    { "" }
    { title }
  if$
}

FUNCTION {format.booktitle}
{ booktitle empty$
    { "" }
    { booktitle }
  if$
}

FUNCTION {format.title.or.booktitle}
{ title empty$
    { format.booktitle }
    { title }
  if$
}

FUNCTION {format.date}
{ year empty$
    { "" }
    { month empty$
	{ year }
	{ month " " * year * }
      if$ }
  if$
}

STRINGS {pageresult}

FUNCTION {n.dashify}
{ 't :=
  "" 'pageresult :=
    { t "" = not }
    { t #1 #1 substring$ "-" =
	{ pageresult "--" * 'pageresult :=
		{ t #1 #1 substring$ "-" = }
		{ t #2 global.max$ substring$ 't := }
	      while$ }
	{ pageresult t #1 #1 substring$ * 'pageresult :=
	  t #2 global.max$ substring$ 't := }
      if$ }
  while$
  pageresult
}

INTEGERS {multiresult}

FUNCTION {multi.page.check}
{ 't  :=
  #0 'multiresult :=
    { multiresult not
      t empty$ not
      and }
    { t #1 #1 substring$ "-" =
      t #1 #1 substring$ "," =
      or
	{ #1 'multiresult := }
	{ t #2 global.max$ substring$ 't := }
      if$ }
  while$
  multiresult
}

FUNCTION {format.pages}
{ pages empty$
    { "" }
    { pages multi.page.check
	{ "\pages " pages n.dashify * }
	{ "\page  " pages n.dashify * }
      if$ }
  if$
}

FUNCTION {format.chapter.pages}
{
  chapter empty$
    { "" }
    { type empty$
	{ "\bibchapter{" chapter * "}" * }
	{ type " " * chapter * }
      if$ }
  if$
  format.pages
  *
}

FUNCTION {format.edition}
{ edition empty$
    { "" }
    { edition "l" change.case$ " edition" * }
  if$
}

FUNCTION {format.type.num}
{ type empty$
    'skip$
    { pop$ type }
  if$
  number empty$
    'skip$
    { " " * number * }
  if$
}

FUNCTION {format.ed.ser.num}
{ format.edition
  series empty$
    'skip$
    { duplicate$ empty$ 'skip$ { ", " * } if$ series * }
  if$
  number empty$
    'skip$
    { duplicate$ empty$ { " {" * } { " \bibno{" * } if$ number * "}" * }
  if$
}

FUNCTION {format.volume}
{ volume empty$
    { "" }
    { volume }
  if$
}

FUNCTION {format.note}
{ note empty$
    { "" }
    { note "l" change.case$ }
  if$
}

FUNCTION {article}
{ output.ref 	format.author	"author"	output.bysame.check
  "\paper"	format.title	"title"		output.check
  ""		format.pages	"pages"		output
  crossref missing$
    { "\jour"	journal		"journal"	output.check
      "\vol"	volume		"volume"	output
      "\issue"	number		"number"	output
      "\yr"	format.date	"year"		output.check }
    { "\paperinfo" crossref	"crossref"	output.crossref }
  if$
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {book}
{ output.ref	format.author.or.editor "author or editor" output.bysame.check
  "\book"	format.title.or.booktitle "title or booktitle" output.check
  "\bookinfo"	format.ed.ser.num "edition, series, and/or number" output
  "\vol"	format.volume	"volume"	output
  "\publ"	publisher	"publisher"	output.check
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output.check
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {booklet}
{ output.ref	format.author	"author"	output.bysame
  "\book"	format.title	"title"		output.check
  "\publ"	howpublished	"howpublished"	output
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {inbook}
{ output.ref	format.author.or.editor	"author or editor" output.bysame.check
  crossref missing$
    { "\book"	format.title.or.booktitle "title or booktitle" output.check
      "\bookinfo" format.ed.ser.num "edition, series, and/or number" output
      ""	format.chapter.pages "chapter and/or pages" output.check
      "\vol"	format.volume	"volume"	output
      "\publ"	publisher	"publisher"	output.check
      "\publaddr" address	"address"	output
      "\yr"	format.date	"year"		output.check }
    { "\bookinfo" crossref	"crossref"	output.crossref
      ""	format.chapter.pages "chapter and/or pages" output.check }
  if$
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {incollection}
{ output.ref	format.author	"author"	output.bysame.check
  "\paper"	format.title	"title"		output.check
  crossref missing$
    { "\paperinfo" format.chapter.pages "chapter and/or pages" output.check
      "\inbook"	format.booktitle "booktitle"	output.check
      ""	format.editor	"editor"	output
      "\bookinfo" format.ed.ser.num "edition, series, and/or number" output
      "\vol"	format.volume	"volume"	output
      "\publ"	publisher	"publisher"	output.check
      "\publaddr" address	"address"	output
      "\yr"	format.date	"year"		output.check }
    { "\paperinfo" crossref	"crossref"	output.crossref
      ""	format.chapter.pages "chapter and/or pages" output.check }
  if$
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {inproceedings}
{ output.ref	format.author	"author"	output.bysame.check
  "\paper"	format.title	"title"		output.check
  ""		format.pages	"pages"		output.check
  crossref missing$
    { "\inbook" format.booktitle "booktitle"	output.check
      "\bookinfo" format.ed.ser.num "edition, series, and/or number" output
      "\vol"	format.volume	"volume"	output
      ""	format.editor	"editor"	output
      "\procinfo" address	"address"	output
      "\publ"	publisher	"publisher"	output
      "\yr"	format.date	"year"		output.check }
    { "\paperinfo" crossref	"crossref"	output.crossref }
  if$
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {conference} { inproceedings }

FUNCTION {manual}
{ output.ref	format.author.or.editor.or.key
				"author, editor, or key" output.bysame
  "\book"	format.title	"title"		output.check
  "\bookinfo"	format.edition	"edition"	output
  "\vol"	format.volume	"volume"	output
  "\publ"	organization	"organization"	output
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {mastersthesis}
{ output.ref	format.author	"author"	output.bysame.check
  "\book"	format.title	"title"		output.check
  "\bookinfo" "Masters Thesis" format.type.num "type and number" output
  "\publ"	school		"school"	output.check
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output.check
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {misc}
{ output.ref	format.author	"author"	output.bysame
  "\book"	format.title	"title"		output
  "\bookinfo"	howpublished	"howpublished"	output
  "\yr"		format.date	"year"		output
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {phdthesis}
{ output.ref	format.author	"author"	output.bysame.check
  "\book"	format.title	"title"		output.check
  "\bookinfo" "Ph.D. Thesis" format.type.num "type and number" output
  "\publ"	school		"school"	output.check
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output.check
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {proceedings}
{ output.ref	format.editor.or.key "editor or key" output.bysame
  "\book"	format.title.or.booktitle "title or booktitle" output.check
  "\bookinfo"	format.ed.ser.num "edition, series, and/or number" output
  "\vol"	format.volume	"volume"	output
  "\procinfo"	address		"address"	output
  "\publ"	publisher	"publisher"	output
  "\yr"		format.date	"year"		output.check
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {techreport}
{ output.ref	format.author	"author"	output.bysame.check
  "\book"	format.title	"title"		output.check
  "\bookinfo" "Tech. Report" format.type.num "type and number" output
  "\publ"	institution	"institution"	output.check
  "\publaddr"	address		"address"	output
  "\yr"		format.date	"year"		output.check
  "\finalinfo"	format.note	"note"		output
  output.endref
}

FUNCTION {unpublished}
{ output.ref	format.author	"author"	output.bysame.check
  "\book"	format.title	"title"		output.check
  "\yr"		format.date	"year"		output
  "\finalinfo"	format.note	"note"		output.check
  output.endref
}

FUNCTION {default.type} { book }

MACRO {jan} {"\bibmonth {1}"}

MACRO {feb} {"\bibmonth {2}"}

MACRO {mar} {"\bibmonth {3}"}

MACRO {apr} {"\bibmonth {4}"}

MACRO {may} {"\bibmonth {5}"}

MACRO {jun} {"\bibmonth {6}"}

MACRO {jul} {"\bibmonth {7}"}

MACRO {aug} {"\bibmonth {8}"}

MACRO {sep} {"\bibmonth {9}"}

MACRO {oct} {"\bibmonth {10}"}

MACRO {nov} {"\bibmonth {11}"}

MACRO {dec} {"\bibmonth {12}"}

READ


INTEGERS { label.len ascii.int}
STRINGS { prefix }

FUNCTION { is.letter } 
{ chr.to.int$   'ascii.int := 
  ascii.int  "A" chr.to.int$ #1 - >
  ascii.int  "Z" chr.to.int$ #1 + < 
  and
  ascii.int  "a" chr.to.int$ #1 - >
  ascii.int  "z" chr.to.int$ #1 + < 
  and 
  or 
}

FUNCTION { chop.macro.prefix }
{ s swap$ 's := "" 'prefix :=
  s #1 #1 substring$ "\" =
	{ s #2 global.max$ substring$ 's := }
	{ "chop.macro.prefix used in bad place" warning$ }
  if$ 
	{ s "" =  { #0 } { s #1 #1 substring$ is.letter } if$ }
	{ prefix s #1 #1 substring$ * 'prefix :=
	  s #2 global.max$ substring$ 's := }
  while$
  's := prefix 
}
 
INTEGERS { stringlength }

FUNCTION {length}
{   #0 'stringlength :=
    { duplicate$ "" = not }
    { #2 global.max$ substring$ #1 stringlength + 'stringlength := }
  while$
  pop$ stringlength
}

INTEGERS { int.etal int.yr int.and }

FUNCTION {label.width}
{ t swap$ 't :=
  #0 'label.len :=
    { t "" = not }
    { t #1 #1 substring$ "{" =
      t #1 #1 substring$ "}" =
      or
	{ t #2 global.max$ substring$ 't := }
	{ t #1 #1 substring$ "\" =
		{ t chop.macro.prefix 
		  duplicate$ "citeyr" =
			{ label.len int.yr + #1 - 'label.len := } 'skip$ if$
		  duplicate$ "citeand" =
			{ label.len int.and +  #1 - 'label.len := } 'skip$ if$
		  duplicate$ "citeetal" =
			{ label.len int.etal +  #1 - 'label.len := } 'skip$ if$
		  duplicate$ "" = 'skip$ { label.len #1 + 'label.len := } if$
		  t swap$ length #2 + global.max$ substring$ 't := }
		{ t #2 global.max$ substring$ 't := 
		  #1 label.len + 'label.len := }
	  if$  }
      if$ }
  while$
  't := label.len
}

FUNCTION {longest.label.of.two}
{ 's := 't := 
  s label.width t label.width <
    { t }
    { s }
  if$
}

FUNCTION {sortify}
{ purify$
  "l" change.case$
}

INTEGERS { len } 

FUNCTION {chop.word}
{ 's :=
  'len :=
  s #1 len substring$ =
    { s len #1 + global.max$ substring$ }
    's
  if$
}

INTEGERS { prev.or.next.extra.num }

FUNCTION {initialize.extra}
{ #0 'prev.or.next.extra.num :=
  "" 's :=
  "" 't :=
  "" 'longest.label :=
}

FUNCTION {sort.format.names}
{ 's :=
  #1 'nameptr :=
  ""
  s num.names$ 'numnames :=
  numnames 'namesleft :=
    { namesleft #0 > }
    { nameptr #1 >
	{ "   " * }
	'skip$
      if$
      s nameptr "{ll{ }}{  ff{ }}{  jj{ }}{vv{ } }" format.name$ 't :=
      nameptr numnames = t "others" = and
	{ "\citeetal " * }
	{ t sortify * }
      if$
      nameptr #1 + 'nameptr :=
      namesleft #1 - 'namesleft :=
    }
  while$
}

FUNCTION {sort.format.title}
{ 't :=
  "A " #2
    "An " #3
      "The " #4 t chop.word
    chop.word
  chop.word
  sortify
  #1 global.max$ substring$
}

FUNCTION {author.sort}
{ author empty$
    { key empty$
	{ "to sort, need author or key in " cite$ * warning$
	  ""
	}
	{ key sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {author.editor.sort}
{ author empty$
    { editor empty$
	{ key empty$
	    { "to sort, need author, editor, or key in " cite$ * warning$
	      "" }
	    { key sortify }
	  if$ }
	{ editor sort.format.names }
      if$ }
    { author sort.format.names }
  if$
}

FUNCTION {author.organization.sort}
{ author empty$
    { key empty$
	{ organization empty$
	    { "to sort, need author, key, or organization in " cite$ * warning$
	      ""
	    }
	    { "The " #4 organization chop.word sortify }
	  if$
	}
	{ key sortify }
      if$
    }
    { author sort.format.names }
  if$
}

FUNCTION {editor.organization.sort}
{ editor empty$
    { key empty$
	{ organization empty$
	    { "to sort, need editor, key, or organization in " cite$ * warning$
	      "" }
	    { "The " #4 organization chop.word sortify }
	  if$ }
	{ key sortify }
      if$ }
    { editor sort.format.names }
  if$
}

FUNCTION {commonpresort}
{ type$ "book" =
  type$ "inbook" =
  or
    'author.editor.sort
    { type$ "proceedings" =
	'editor.organization.sort
	{ type$ "manual" =
	    'author.organization.sort
	    'author.sort
	  if$
	}
      if$
    }
  if$
  "    "
  *
  year field.or.null sortify
  *
  "    "
  *
  title field.or.null
  sort.format.title
  *
}





FUNCTION {presort}
{ "" 'citeextra :=
  commonpresort #1 entry.max$ substring$ 'sort.key$ :=
}

ITERATE {presort}

SORT

INTEGERS { number.label }

FUNCTION {initialize.number.label}
{ #0 'number.label := }

EXECUTE {initialize.number.label}

FUNCTION {number.plain}
{
  number.label #1 + 'number.label :=
  number.label int.to.str$ 'label :=
}

ITERATE {number.plain}

FUNCTION {set.longest.label}
{ number.label int.to.str$ 'longest.label := }

EXECUTE {set.longest.label}


EXECUTE {output.preamble}

ITERATE {call.type$}

FUNCTION {finish.up} 
{ newline$ }

EXECUTE {finish.up}

