Function: bibtex-generate-autokey

bibtex-generate-autokey is a byte-compiled function defined in bibtex.el.gz.

Signature

(bibtex-generate-autokey)

Documentation

Generate automatically a key for a BibTeX entry.

Use the author/editor, the year and the title field. The algorithm works as follows.

The name part:
 1. Use the author or editor field to generate the name part of the key.
    Expand BibTeX strings if bibtex-autokey-expand-strings is non-nil.
 2. Change the content of the name field according to
    bibtex-autokey-name-change-strings (see there for further detail).
 3. Use the first bibtex-autokey-names names in the name field. If there
    are up to bibtex-autokey-names + bibtex-autokey-names-stretch names,
    use all names.
 4. Use only the last names to form the name part. From these last names,
    take at least bibtex-autokey-name-length characters (truncate only
    after a consonant or at a word end).
 5. Convert all last names using the function
    bibtex-autokey-name-case-convert-function.
 6. Build the name part of the key by concatenating all abbreviated last
    names with the string bibtex-autokey-name-separator between any two.
    If there are more names in the name field than names used in the name
    part, append the string bibtex-autokey-additional-names.

The year part:
 1. Build the year part of the key by truncating the content of the year
    component of the date or year field to the rightmost
    bibtex-autokey-year-length digits (useful values are 2 and 4).
 2. If both the year and date fields are absent, but the entry has a
    valid crossref field and bibtex-autokey-use-crossref is
    non-nil, use the date or year field of the cross-referenced entry
    instead.

The title part
 1. Change the content of the title field according to
    bibtex-autokey-titleword-change-strings (see there for further detail).
 2. Truncate the title before the first match of
    bibtex-autokey-title-terminators and delete those words which appear
    in bibtex-autokey-titleword-ignore. Build the title part using the
    first bibtex-autokey-titlewords words from this truncated title.
    If the truncated title ends after up to bibtex-autokey-titlewords +
    bibtex-autokey-titlewords-stretch words, use all words from the
    truncated title.
 3. For every title word that appears in bibtex-autokey-titleword-abbrevs
    use the corresponding abbreviation (see documentation of this variable
    for further detail).
 4. From every title word not generated by an abbreviation, take at least
    bibtex-autokey-titleword-length characters (truncate only after
    a consonant or at a word end).
 5. Convert all title words using the function
    bibtex-autokey-titleword-case-convert-function.
 6. Build the title part by concatenating all abbreviated title words with
    the string bibtex-autokey-titleword-separator between any two.

Concatenate the key:
 1. Concatenate bibtex-autokey-prefix-string, the name part, the year
    part and the title part. If the name part and the year part are both
    non-empty insert bibtex-autokey-name-year-separator between the two.
    If the title part and the year (or name) part are non-empty, insert
    bibtex-autokey-year-title-separator between the two.
 2. bibtex-autokey-before-presentation-function must be
    a function taking one argument. Call this function with the generated
    key as the argument. Use the return value of this function (a string)
    as the key.
 3. If bibtex-autokey-edit-before-use is non-nil, present the key in the
    minibuffer to the user for editing. Insert the key given by the user.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-generate-autokey ()
  "Generate automatically a key for a BibTeX entry.
Use the author/editor, the year and the title field.
The algorithm works as follows.

The name part:
 1. Use the author or editor field to generate the name part of the key.
    Expand BibTeX strings if `bibtex-autokey-expand-strings' is non-nil.
 2. Change the content of the name field according to
    `bibtex-autokey-name-change-strings' (see there for further detail).
 3. Use the first `bibtex-autokey-names' names in the name field.  If there
    are up to `bibtex-autokey-names' + `bibtex-autokey-names-stretch' names,
    use all names.
 4. Use only the last names to form the name part.  From these last names,
    take at least `bibtex-autokey-name-length' characters (truncate only
    after a consonant or at a word end).
 5. Convert all last names using the function
    `bibtex-autokey-name-case-convert-function'.
 6. Build the name part of the key by concatenating all abbreviated last
    names with the string `bibtex-autokey-name-separator' between any two.
    If there are more names in the name field than names used in the name
    part, append the string `bibtex-autokey-additional-names'.

The year part:
 1. Build the year part of the key by truncating the content of the year
    component of the date or year field to the rightmost
    `bibtex-autokey-year-length' digits (useful values are 2 and 4).
 2. If both the year and date fields are absent, but the entry has a
    valid crossref field and `bibtex-autokey-use-crossref' is
    non-nil, use the date or year field of the cross-referenced entry
    instead.

The title part
 1. Change the content of the title field according to
    `bibtex-autokey-titleword-change-strings' (see there for further detail).
 2. Truncate the title before the first match of
    `bibtex-autokey-title-terminators' and delete those words which appear
    in `bibtex-autokey-titleword-ignore'.  Build the title part using the
    first `bibtex-autokey-titlewords' words from this truncated title.
    If the truncated title ends after up to `bibtex-autokey-titlewords' +
    `bibtex-autokey-titlewords-stretch' words, use all words from the
    truncated title.
 3. For every title word that appears in `bibtex-autokey-titleword-abbrevs'
    use the corresponding abbreviation (see documentation of this variable
    for further detail).
 4. From every title word not generated by an abbreviation, take at least
    `bibtex-autokey-titleword-length' characters (truncate only after
    a consonant or at a word end).
 5. Convert all title words using the function
    `bibtex-autokey-titleword-case-convert-function'.
 6. Build the title part by concatenating all abbreviated title words with
    the string `bibtex-autokey-titleword-separator' between any two.

Concatenate the key:
 1. Concatenate `bibtex-autokey-prefix-string', the name part, the year
    part and the title part.  If the name part and the year part are both
    non-empty insert `bibtex-autokey-name-year-separator' between the two.
    If the title part and the year (or name) part are non-empty, insert
    `bibtex-autokey-year-title-separator' between the two.
 2. `bibtex-autokey-before-presentation-function' must be
    a function taking one argument.  Call this function with the generated
    key as the argument.  Use the return value of this function (a string)
    as the key.
 3. If `bibtex-autokey-edit-before-use' is non-nil, present the key in the
    minibuffer to the user for editing.  Insert the key given by the user."
  (let* ((names (bibtex-autokey-get-names))
         (year (bibtex-autokey-get-year))
         (title (bibtex-autokey-get-title))
         (autokey (concat bibtex-autokey-prefix-string
                          names
                          (unless (or (equal names "")
                                      (equal year ""))
                            bibtex-autokey-name-year-separator)
                          year
                          (unless (or (and (equal names "")
                                           (equal year ""))
                                      (equal title ""))
                            bibtex-autokey-year-title-separator)
                          title)))
    (if bibtex-autokey-before-presentation-function
        (funcall bibtex-autokey-before-presentation-function autokey)
      autokey)))