4

Is it possible to modify the JHEP bibliography style in a simple way such that it displays bibliographical entries in alphabetical order, instead of basing on first appearence in the main text?

(Addendum) Is it possible to add in the same way a function that prints a long horizontal line ----- instead of the name of the author(s) if these are repeated, as is done e.g. by the amsplain.bst style?

jj_p
  • 627

1 Answers1

6

The bibliography style JHEP seems to be a lightly modified version of the venerable unsrt style. To enable alphabetical sorting of the entries, you should modify JHEP.bst as follows. (Aside: I'm not sure if this procedure satisfies your objective that the modifications be done "in a simple way". However, I've tried out the code, and it seems to work!)

  • Make a copy of the file JHEP.bst. Call the copy (say) JHEPsort.bst. (Don't edit the original file directly.)

  • Open the file JHEPsort.bst in a text editor. The editor you use to edit your tex files will do fine.

  • Locate the lines

    MACRO {pr} {"Phys. Rev."}
    
    READ
    
    STRINGS { longest.label }
    

    in this file. Hint: In my copy of this file, this excerpt starts on l. 1048.

  • Insert the following 145 or so lines between the line READ and the line STRINGS { longest.label }:

    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$
    }
    
    FUNCTION {sort.format.names}
    { 's :=
      #1 'nameptr :=
      ""
      s num.names$ 'numnames :=
      numnames 'namesleft :=
        { namesleft #0 > }
        { nameptr #1 >
            { "   " * }
            'skip$
          if$
          s nameptr "{vv{ } }{ll{ }}{  ff{ }}{  jj{ }}" format.name$ 't :=
          nameptr numnames = t "others" = and
            { "et al" * }
            { 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$
        { organization empty$
            { key empty$
                { "to sort, need author, organization, or key in " cite$ * warning$
                  ""
                }
                { key sortify }
              if$
            }
            { "The " #4 organization chop.word sortify }
          if$
        }
        { author sort.format.names }
      if$
    }
    
    FUNCTION {editor.organization.sort}
    { editor empty$
        { organization empty$
            { key empty$
                { "to sort, need editor, organization, or key in " cite$ * warning$
                  ""
                }
                { key sortify }
              if$
            }
            { "The " #4 organization chop.word sortify }
          if$
        }
        { editor sort.format.names }
      if$
    }
    
    FUNCTION {presort}
    { 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
      *
      #1 entry.max$ substring$
      'sort.key$ :=
    }
    
    ITERATE {presort}
    
    SORT
    

    Just in case you're curious where this code comes from: I certainly did not create it myself! Instead, I copied it from the bibliography style file plain.bst.

  • Save the file JHEPsort.bst either to the directory that contains your main tex file or to a directory that's searched by BibTeX. If you choose the second option, you will probably need to update the filename database of your TeX distribution, in a way that's appropriate for your TeX distribution.

  • Start using the new bibliography style by providing the instruction

    \bibliographystyle{JHEPsort}
    

    instead of \bibliographystyle{JHEP}. Be sure to run LateX, BibTeX, and LaTeX twice more so that all changes are fully propagated.

Happy BibTeXing!

Mico
  • 506,678
  • very nice, that's precisely what I was looking for. One last fancy gadget: is it possible to add in the same way a function that prints a long horizontal line ----- instead of the name of the author(s) if these are repeated, as is done e.g. by the amsplain.bst style? – jj_p Apr 30 '14 at 14:43
  • @jj_p - Once one starts making more than just one or two changes to an existing bst file, it's usually better to start from scratch by running the makebst utility of the custom-bib package. It presents a straightforward, menu-driven set of queries along with possible answers; the default answer is generally marked very clearly. Based on your answers it'll build a bespoke bst file. Give it a try. :-) – Mico Apr 30 '14 at 15:22
  • right, but there's still the issue that this class is particularly suited to be compatible with inspire, arXiv etc., so maybe modifying it is still worth some effort; do you think it is too involved task? – jj_p Apr 30 '14 at 16:09
  • @jj_p - How long do you want the line to be: the length of two or three em-dashes, or something else? – Mico Apr 30 '14 at 16:32
  • yes, something like to3em should do; the hard work seems more in implementing the prev.author this.author story – jj_p Apr 30 '14 at 16:42
  • Thanks to another answer of yours, I was able to introduce in a consistent way the bysame story, and achieve the above goal :) – jj_p Apr 30 '14 at 16:59
  • @jj_p - I assume you're referring to my answer to the posting dash instead of repeated author name, right? I was starting to remember vaguely having written just such an answer sometime in the past and was about to look it up when I saw your latest comment. Glad you saved me this effort! :-) – Mico Apr 30 '14 at 17:14