Hack to put bibliography on a new page
[latex-mlastyle.git] / mlastyle.bst
index 83f4b76b6161947f6c09657cb2d6e230279bb0ae..1e4136742047f81a674159569e7946188409c908 100644 (file)
@@ -1,4 +1,4 @@
-% $Id: mlastyle.bst,v 1.13 2003-11-22 19:15:11 tpope Exp $
+% $Id: mlastyle.bst,v 1.20 2005-02-09 03:53:11 tpope Exp $
 % BibTeX bibliography style `mlastyle'
 % Based on BibTeX standard bibliography style `plain'
        % version 0.99a for BibTeX versions 0.99a or later, LaTeX version 2.09.
@@ -38,18 +38,20 @@ ENTRY
     urldate
     accessdate
     urlpath
+    database
     version
+    % eid isbn issn doi
   }
   { author.duplicate author.shared }
   { label }
 
-INTEGERS { output.state before.all mid.sentence after.sentence after.block after.title author.different author.last author.flast citealp.used url.used }
+INTEGERS { output.state before.all mid.phrase mid.sentence after.sentence after.block author.different author.last author.flast citealp.used url.used }
 
 STRINGS { s t u empty.title }
 
 % Rearranged such that true values require capital letters
 FUNCTION {init.consts}
-{ #-1 'after.title :=
+{ #-1 'mid.phrase :=
   #0 'mid.sentence :=
   #1 'before.all :=
   #2 'after.sentence :=
@@ -66,6 +68,13 @@ FUNCTION {init.consts}
   "" 'empty.title :=
 }
 
+% I do this a lot
+FUNCTION {duplicate}
+{
+  duplicate$
+  "duplicate should be duplicate$" warning$
+}
+
 FUNCTION {not}
 {   { #0 }
     { #1 }
@@ -87,7 +96,7 @@ FUNCTION {or}
 INTEGERS {chars i j}
 
 % text.length$ does not include braces
-% ...this function is probably unnecessary
+% This function is probably a bad idea
 FUNCTION {num.chars}
 {
   #0 'chars :=
@@ -127,7 +136,14 @@ FUNCTION {do.period}
   if$
 }
 
-% Switched to do.period and added after.title
+FUNCTION {do.space}
+{ duplicate$ duplicate$ do.period =
+    { "\ " * }
+    { " " * }
+  if$
+}
+
+% Switched to do.period and added mid.phrase
 FUNCTION {output.nonnull}
 { 's :=
   output.state mid.sentence =
@@ -139,8 +155,8 @@ FUNCTION {output.nonnull}
        }
        { output.state before.all =
            'write$
-           { output.state after.title =
-               { " " * write$ }
+           { output.state mid.phrase =
+               { do.space write$ }
                { do.period " " * write$ }
              if$
            }
@@ -193,16 +209,16 @@ FUNCTION {new.sentence}
   if$
 }
 
-%FUNCTION {no.comma}
-%{ output.state after.block =
-%    'skip$
-%    { output.state before.all =
-%      'skip$
-%      { after.title 'output.state := }
-%      if$
-%    }
-%  if$
-%}
+FUNCTION {continue.sentence}
+{ output.state after.block =
+    'skip$
+    { output.state before.all =
+       'skip$
+       { mid.phrase 'output.state := }
+      if$
+    }
+  if$
+}
 
 FUNCTION {new.block.checka}
 { empty$
@@ -303,6 +319,17 @@ FUNCTION {enquote}
   if$
 }
 
+FUNCTION {selective.emphasize}
+{ field.or.null duplicate$ sortify 's :=
+  s #1 #8 substring$ duplicate$ "rev. of " = swap$ "rev.~of " = or
+  s #1 #9 substring$ "rev.\ of " = or
+  s "home page" = or
+  s "america online" = or
+    'skip$
+    'emphasize
+  if$
+}
+
 FUNCTION {selective.enquote}
 { field.or.null duplicate$ sortify 's :=
   s #1 #8 substring$ duplicate$ "rev. of " = swap$ "rev.~of " = or
@@ -311,6 +338,7 @@ FUNCTION {selective.enquote}
   s "preface" = or
   s "forward" = or
   s "afterward" = or
+  s "home page" = or
     'skip$
     'enquote
   if$
@@ -470,18 +498,65 @@ FUNCTION {n.dashify}
   while$
 }
 
+FUNCTION {format.year}
+{ year empty$
+    { "" }
+    { year n.dashify
+      duplicate$ duplicate$ num.chars #10 =
+      swap$ #5 #2 substring$ "--" = and
+       { duplicate$ duplicate$ #1 #2 substring$ swap$ #7 #2 substring$ =
+           { duplicate$ #1 #6 substring$ swap$ #9 #2 substring$ * }
+           {}
+         if$
+       }
+       {}
+      if$
+    }
+  if$
+}
+
+FUNCTION {format.month}
+{
+  month #-1 #1 substring$ chr.to.int$ duplicate$ #47 > swap$ #58 < and
+    { 
+      month #-2 #1 substring$ chr.to.int$ duplicate$ #47 > swap$ #58 < and
+        { #2 'i := }
+       { #1 'i := }
+      if$
+      month #-2 i - #2 substring$ "\ " =
+        { month #0 i - i substring$
+         month #-2 i - #2 substring$
+         month #-3 i - global.max$ i - #2 - substring$
+         * *
+       }
+       {
+         month #-1 i - #1 substring$ duplicate$ " " = swap$ "~" = or
+           { month #0 i - i substring$
+             month #-1 i - #1 substring$
+             month #-2 i - global.max$ i - #1 - substring$
+             * *
+           }
+           { month }
+         if$
+       }
+      if$
+    }
+    { month }
+  if$
+}
+
 FUNCTION {format.date}
 { year empty$
     { month empty$
        { "" }
        { "there's a month but no year in " cite$ * warning$
-         month
+         format.month
        }
       if$
     }
     { month empty$
-       'year
-       { month "~" * year * }
+       'format.year
+       { format.month do.space format.year * }
       if$
     }
   if$
@@ -489,19 +564,14 @@ FUNCTION {format.date}
 
 %INTEGERS {xx}
 FUNCTION {format.btitle}
-{ title emphasize
-  %title num.chars int.to.str$ top$
-  %#0 'xx :=
-  %{ xx title num.chars < }
-  %{ title xx #1 + duplicate$ 'xx := #1 substring$ top$ } while$
+{ title selective.emphasize
 }
 
 FUNCTION {tie.or.space.connect}
 { duplicate$ text.length$ #3 <
-    { "~" }
-    { "\ " }
+    { "~" swap$ * * }
+    { swap$ do.space swap$ * }
   if$
-  swap$ * *
 }
 
 FUNCTION {either.or.check}
@@ -511,6 +581,17 @@ FUNCTION {either.or.check}
   if$
 }
 
+FUNCTION {abbreviate}
+{ duplicate$ sortify 's := 't :=
+  ""
+  "10th" "tenth" "9th" "ninth" "8th" "eighth" "7th" "seventh" "6th" "sixth"
+  "5th" "fifth" "4th" "fourth" "3rd" "third" "2nd" "second" "1st" "first"
+  "Rev." "revised" "Abr." "abridged"
+  {duplicate$ empty$ { pop$ #0 }{ #1 } if$ }{ s = { 't := }{ pop$ } if$ }
+  while$
+  t
+}
+
 FUNCTION {format.bvolume.or.num.series}
 { volume empty$
     { number empty$
@@ -532,7 +613,7 @@ FUNCTION {format.bvolume.or.num.series}
     { "Vol." volume tie.or.space.connect
       series empty$
        'skip$
-       { " of " * series emphasize * add.period$ }
+       { " of " * series selective.emphasize * add.period$ }
       if$
       number empty$
        'skip$
@@ -551,14 +632,16 @@ FUNCTION {format.edition}
        { "Vers.~" version *}
       if$
     }
-    { edition sortify 's := edition 't :=
-      ""
-      "10th" "tenth" "9th" "ninth" "8th" "eighth" "7th" "seventh" "6th" "sixth"
-      "5th" "fifth" "4th" "fourth" "3rd" "third" "2nd" "second" "1st" "first"
-      "Rev." "revised" "Abr." "abridged"
-      {duplicate$ empty$ { pop$ #0 }{ #1 } if$ }{ s = { 't := }{ pop$ } if$ }
-      while$
-      t "\ ed." *
+    { edition abbreviate
+      duplicate$ sortify "revised" =
+       { pop$ "Rev." }
+       'skip$
+      if$
+      duplicate$ sortify "abridged" =
+       { pop$ "Abr." }
+       'skip$
+      if$
+      do.space "ed." *
       "edition and version" version either.or.check
     }
   if$
@@ -593,10 +676,27 @@ FUNCTION {format.pages}
 % j is positive if pages contains a comma
 % (not fully implemented)
       #0 'j :=
-      pages n.dashify 't :=
-      ""
+      pages n.dashify duplicate$ 't :=
+       { duplicate$ empty$ not }
+       {
+         duplicate$ #1 #1 substring$ duplicate$
+         "{" =
+           { j #1 + 'j := }
+           'skip$
+         if$
+         "}" =
+           { j #1 - 'j := }
+           'skip$
+         if$
+         duplicate$ #1 #2 substring$ ", " =
+           { j j #0 = + 'j := }
+           'skip$
+         if$
+         #2 global.max$ substring$
+       }
+      while$
        { t empty$ not }
-       { t #1 #2 substring$ "--" =
+       { t #1 #2 substring$ "--" = j not and
            { t #3 global.max$ substring$ 't :=
              duplicate$ num.chars 'i :=
              "--" *
@@ -613,8 +713,12 @@ FUNCTION {format.pages}
                'skip$
              if$
            }
-           { t #1 #1 substring$ *
-             t #2 global.max$ substring$ 't :=
+           { t #1 #1 substring$ duplicate$ "," = swap$ "-" = or j and
+               { "+" * "" 't := }
+               { t #1 #1 substring$ *
+                 t #2 global.max$ substring$ 't :=
+               }
+             if$
            }
          if$
        }
@@ -623,35 +727,19 @@ FUNCTION {format.pages}
   if$
 }
 
-FUNCTION {format.year}
-{ year empty$
-    { "" }
-    { year n.dashify
-      duplicate$ duplicate$ num.chars #10 =
-      swap$ #5 #2 substring$ "--" = and
-       { duplicate$ duplicate$ #1 #2 substring$ swap$ #7 #2 substring$ =
-           { duplicate$ #1 #6 substring$ swap$ #8 #2 substring$ * }
-           {}
-         if$
-       }
-       {}
-      if$
-    }
-  if$
-}
-
 FUNCTION {format.vol.num.year.pages}
 { volume empty$
     { number empty$
        'skip$
-       { "there's a number but no volume in " cite$ * warning$ }
+       { number n.dashify
+         "there's a number but no volume in " cite$ * warning$ }
       if$
       format.date
     }
     { volume
       number empty$
        'skip$
-       { "." * number * }
+       { "." * number n.dashify * }
       if$
       " (" * format.date * ")" *
     }
@@ -660,31 +748,21 @@ FUNCTION {format.vol.num.year.pages}
     'skip$
     { ", " * format.edition * }
   if$
-  pages empty$
+  type field.or.null sortify duplicate$ "sec." = swap$ "section" = or
+    { chapter empty$
+         { "section type requires chapter in " cite$ warning$ }
+         { ", sec." chapter n.dashify tie.or.space.connect }
+       if$
+      }
     'skip$
-    { ": " * pages n.dashify * }
   if$
-}
-
-
-FUNCTION {format.vol.num.pages}
-{ volume field.or.null
-  number empty$
+  type field.or.null sortify "review" = chapter empty$ not and
+    { ", sec." chapter n.dashify tie.or.space.connect }
     'skip$
-    { "(" number * ")" * *
-      volume empty$
-       { "there's a number but no volume in " cite$ * warning$ }
-       'skip$
-      if$
-    }
   if$
   pages empty$
     'skip$
-    { duplicate$ empty$
-       { pop$ format.pages }
-       { ":" * pages n.dashify * }
-      if$
-    }
+    { ": " * format.pages * }
   if$
 }
 
@@ -695,14 +773,16 @@ FUNCTION {format.chapter.pages}
   or
     'format.pages
     { type empty$
-       { "Chapter" }
-       { type "t" change.case$ }
-      if$
-      chapter n.dashify tie.or.space.connect
-      pages empty$
-       'skip$
-       { ", " * format.pages * }
+       { "chapter ignored in " cite$ * warning$ }
+       { type "t" change.case$
+         chapter n.dashify tie.or.space.connect
+         pages empty$
+           'skip$
+           { ", " * }
+         if$
+       }
       if$
+      format.pages *
     }
   if$
 }
@@ -737,24 +817,40 @@ FUNCTION {format.tr.number}
   if$
 }
 
-FUNCTION {format.url}
-{ url empty$
-    { "" }
-    { urldate empty$
-       { accessdate empty$
-           { "there's a url but no urldate in " cite$ * warning$ "\today" }
-           { "accessdate in " cite$ * " depreciated; use urldate instead" *
-             warning$ accessdate }
-           if$
-       }
-       { urldate }
-      if$
-      " $<$\url{" * url * "}$>$" *
-      urlpath empty$
+FUNCTION {format.urldate}
+{ database empty$
+    'skip$
+    { database selective.emphasize output.nonnull new.block }
+  if$
+  urldate missing$
+  { accessdate empty$
+      { cite$ " has no urldate field" * warning$
+       "\theurldate{}"
+      }
+      { "accessdate in " cite$ * " is depreciated; use urldate instead" *
+       warning$ accessdate
+      }
+    if$
+  }
+  { urldate }
+  if$
+}
+FUNCTION {output.url}
+{
+  url empty$
+    { urlpath empty$ 
        'skip$
-       { do.period " Path: " * urlpath * }
+       { format.urldate output }
       if$
     }
+    { format.urldate
+      " $<$\url{" * url * "}$>$" *
+      output.nonnull
+    }
+  if$
+  urlpath empty$
+    'skip$
+    { "Path: " urlpath * output.nonnull }
   if$
 }
 
@@ -767,7 +863,7 @@ FUNCTION {format.crossref}
 
 FUNCTION {cite.title}
 { title empty$ journal empty$ not and
-    { key empty$ { journal }{ key } if$ emphasize }
+    { key empty$ { journal }{ key } if$ selective.emphasize }
     { title empty$ key empty$ and
        { "empty title and key in " cite$ * warning$ "" }
        { key empty$ {title}{key} if$
@@ -778,7 +874,7 @@ FUNCTION {cite.title}
          type$ "phdthesis" =
          type$ "proceedings" =
          or or or or or
-           { emphasize }
+           { selective.emphasize }
            { type$ "article" =
              %type$ "booklet" =
              type$ "incollection" =
@@ -824,7 +920,8 @@ FUNCTION {cite.label}
            { "{f.~}{vv~}{ll}{, jj}" format.names.custom 's := }
            { author.shared author.flast =
                { "{ff~}{vv~}{ll}{, jj}" format.names.custom 's := }
-               { "{vv~}{ll}" format.names.custom ", " * cite.title * 's := "WTF" warning$ }
+               { "{vv~}{ll}" format.names.custom ", " *
+                 cite.title * 's := "WTF" warning$ }
              if$
            }
          if$
@@ -833,7 +930,7 @@ FUNCTION {cite.label}
       s
       "(" * empty.title *
       author.duplicate { cite.title * }{} if$
-      ")" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom purify$ *
+      "){" * swap$ "{ff~}{vv~}{ll}{, jj}" format.names.custom * "}" *
     }
   if$
       %}
@@ -866,22 +963,36 @@ FUNCTION {article}
     { type empty$
        'skip$
        { type sortify "review" =
-           { "Rev.\ of " booktitle emphasize * 
+           { "Rev.\ of " booktitle selective.emphasize * 
            "booktitle" output.check new.block
            }
            { "Ignoring invalid type in " cite$ warning$ }
          if$
        }
       if$
-      journal emphasize "journal" output.check after.title 'output.state :=
+      journal selective.emphasize "journal" output.check
+      continue.sentence
       address empty$
        'skip$
        { "[" address * "]" * output
-         after.title 'output.state :=
+         continue.sentence
+       }
+      if$
+      series empty$
+       'skip$
+       { series sortify
+         duplicate$ "new" =
+           { "ns" }
+           { duplicate$ "old" =
+               { "os" }
+               { series abbreviate do.space "ser." * "l" change.case$ }
+             if$
+           }
+         if$
+         output.nonnull
+         continue.sentence
        }
       if$
-      %format.date "year" output.check
-      %edition output
       format.vol.num.year.pages output
     }
     { format.crossref output.nonnull
@@ -889,7 +1000,7 @@ FUNCTION {article}
     }
   if$
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -919,7 +1030,7 @@ FUNCTION {book}
     }
   if$
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -966,7 +1077,7 @@ FUNCTION {inbook}
     }
   if$
   new.block
-  format.url output
+  output.url
   note output
   fin.entry
 }
@@ -987,7 +1098,7 @@ FUNCTION {incollection}
   new.block
   crossref missing$
     { 
-      booktitle emphasize "booktitle" output.check
+      booktitle selective.emphasize "booktitle" output.check
       new.block
       format.editors.mid "editor" output.check
       new.block
@@ -998,7 +1109,7 @@ FUNCTION {incollection}
       format.publisher "publisher" output.check
       %address output
       format.date "year" output.check
-      new.sentence
+      new.block
       format.chapter.pages output
     }
     { format.crossref output.nonnull
@@ -1006,7 +1117,7 @@ FUNCTION {incollection}
     }
   if$
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1052,7 +1163,7 @@ FUNCTION {inproceedings}
     }
   if$
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1092,7 +1203,7 @@ FUNCTION {manual}
   if$
   format.date output
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1104,13 +1215,13 @@ FUNCTION {mastersthesis}
   new.block
   format.title "title" output.check
   new.block
-  "Diss." format.thesis.type do.period output.nonnull
-  after.title 'output.state :=
+  "Diss." format.thesis.type output.nonnull
+  new.block
   school "school" output.check
   address output
   format.date "year" output.check
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1126,7 +1237,7 @@ FUNCTION {misc}
   howpublished output
   format.date output
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1139,13 +1250,13 @@ FUNCTION {phdthesis}
   new.block
   format.btitle "title" output.check
   new.block
-  "Diss." format.thesis.type do.period output.nonnull
-  after.title 'output.state :=
+  "Diss." format.thesis.type output.nonnull
+  new.block
   school "school" output.check
   address output
   format.date "year" output.check
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1182,7 +1293,7 @@ FUNCTION {proceedings}
     }
   if$
   new.block
-  format.url output
+  output.url
   new.block
   note output
   fin.entry
@@ -1210,7 +1321,7 @@ FUNCTION {unpublished}
   new.block
   format.title "title" output.check
   new.block
-  format.url output
+  output.url
   new.block
   note "note" output.check
   format.date output
@@ -1444,9 +1555,13 @@ FUNCTION {init.vars}
   #0 'j :=
 }
 
+% Function name is not strictly accurate
 FUNCTION {forward.author.dup.check}
 {
-  url empty$ 'skip$ { url.used #1 + 'url.used := } if$
+  url empty$ urlpath empty$ urldate empty$ and and
+    'skip$
+    { url.used #1 + 'url.used := }
+  if$
   crossref empty$ 'skip$ { citealp.used #1 + 'citealp.used := } if$
   author empty$
     { editor empty$ { organization field.or.null 'a := }{ editor 'a :=} if$}
@@ -1543,12 +1658,16 @@ FUNCTION {begin.bib}
 {
   citealp.used
     { "\expandafter\ifx\csname citealp\endcsname\relax\let\citealp\cite\fi"
-      write$ newline$ }
+      write$ newline$
+    }
     'skip$
   if$
   url.used
-    { "\expandafter\ifx\csname citealp\endcsname\relax\url\let\url\relax\fi"
-      write$ newline$ }
+    { "\providecommand\url[1]{\texttt{#1}}"
+      write$ newline$
+      "\providecommand\theurldate{\today}"
+      write$ newline$
+    }
     'skip$
   if$
   preamble$ empty$