Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to do amsalpha style citation with BibTeX, except that I want to have manual control over the key/labels (e.g., [ABC09]). Is there an option for this?

share|improve this question
    
Welcome to TeX.SX! Can you give a small example, with a sample of a bib entry and what you really need to do? –  egreg Sep 21 '12 at 8:42
add comment

2 Answers

One of the optional fields of a BibTeX entry is key which is used for put in alphabetical order, cross-references and as label when the author or editor information is not available. Thus one can use the key field for the value of records for which one wants to manually control the label.

To this end one has to modify the amsalpha.bst, in particular the FUNCTION {output.bibitem}. (Please create a copy of amsalpha.bst and change the name to it, let us say myamsalpha.bst) This function can be modified as follows

FUNCTION {output.bibitem}
{ newline$
  "\bibitem[" write$
  key empty$
    {label write$}
    {key write$}
  if$
  "]{" write$
  cite$ write$
  "}" write$
  newline$
  ""
  before.all 'output.state :=
}

Then, you can use it as follows:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{first,
  author = "Last, First",
  title = "First Title",
  journal = "Journal Name",
  year = 2012
}
@Article{second,
  key = {ABC12},
  author = "Last, First",
  title = "Second Title",
  journal = "Journal Name",
  year = 2011
}
@Article{third,
  author = "More, First",
  title = "Third Title",
  journal = "Journal Name",
  year = 2011
}
\end{filecontents}
\begin{document}
Testing citations
\cite{first} 
\cite{second}
\cite{third}

\bibliographystyle{amsalpha}
\bibliography{\jobname}
\end{document}

enter image description here

share|improve this answer
add comment

While Guido's solution was quite helpful to me, it resulted in incorrect sorting of the bibliography. To have consistent sorting it is better to only modify the calc.label function in the custom bibtex style (e.g. myamsalpha.bst) as follows.

FUNCTION {calc.label}
{ key empty$
  { type$ "book" =
    type$ "inbook" =
    or
      'author.editor.key.label
      { type$ "proceedings" =
          'editor.key.organization.label
          { type$ "manual" =
              'author.key.organization.label
              'author.key.label
            if$
          }
        if$
      }
    if$
    duplicate$
    year field.or.null purify$ #-1 #2 substring$
    *
    'label :=
    year field.or.null purify$ #-1 #4 substring$
    *
    sortify 'sort.label :=
  }
  { key 'label :=
    key sortify 'sort.label :=
  }
  if$
}

This will yield in addition to the custom labels also the correct sorting of the labels in the bibliography. However I must admit that using this solution the user is responsible himself for avoiding duplicate keys.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.