2017-12-08
The alpha
BibTeX style produces citation labels of the form [Ken90]
or [XYZ94]
. While it usually does the right thing, sometimes it doesn’t get the label right (e.g. the label is too long when the authors have multiple / hyphenated last names). Here is how you can provide a custom label with the alpha
style.
The simplest method would be to download my style file.
(This also hyperlinks DOI/URLs correctly as described here.)
Save the file in the same directory as your tex
file and use it by putting the following in your tex
file:
\bibliographystyle{halpha-abbrv} \bibliography{refs}
Now if you want to cite your entries with a custom label (e.g. A17
instead of the default Aut17
), then provide the label you want in the label
field.
For example:
@Article{ foo, label = {A17}, author = {Author, A}, title = {Example entry}, journal = {ArXiv e-prints}, archiveprefix = {arXiv}, eprint = {1707.03780}, primaryclass = {physics.flu-dyn}, doi = {10.1010/doi-that-will-become-a-hyperlink}, url = {http://your.custom.url}, year = 2017, }
This entry will be cited as [A17]
.
If you are using a different style file, and need to get a similar effect, then you will have to edit the calc.label
function of your style file.
Here are the changes I made:
diff --git a/halpha-abbrv.bst b/halpha-abbrv.bst index a960aa9..4408167 100644 --- a/halpha-abbrv.bst +++ b/halpha-abbrv.bst @@ -17,6 +17,7 @@ ENTRY { address author booktitle + label chapter edition editor @@ -41,7 +42,7 @@ ENTRY year } {} - { label extra.label sort.label } + { cite.label extra.label sort.label } INTEGERS { output.state before.all mid.sentence after.sentence after.block } @@ -93,7 +94,7 @@ FUNCTION {output.check} FUNCTION {output.bibitem} { newline$ "\bibitem[" write$ - label write$ + cite.label write$ "]{" write$ cite$ write$ "}" write$ @@ -1125,24 +1126,28 @@ FUNCTION {editor.key.organization.label} } FUNCTION {calc.label} -{ 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$ - } +{ label 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 duplicate$ } if$ - duplicate$ - year field.or.null purify$ #-1 #2 substring$ - * - 'label := + 'cite.label := year field.or.null purify$ #-1 #4 substring$ * sortify 'sort.label := @@ -1311,10 +1316,10 @@ FUNCTION {reverse.pass} { "a" 'extra.label := } 'skip$ if$ - label extra.label * 'label := - label width$ longest.label.width > - { label 'longest.label := - label width$ 'longest.label.width := + cite.label extra.label * 'cite.label := + cite.label width$ longest.label.width > + { cite.label 'longest.label := + cite.label width$ 'longest.label.width := } 'skip$ if$
You will have to do something similar to your style file.
Note: There is a minor bug with sorting when you provide a custom citation label. Custom labels are sorted according to the whole label and the four digit year. The other labels are sorted according to the author initials and the four digit year. So if your custom label includes a year already, there could theoretically be a small change in the sort order.
Anonymous (2018-01-29 05:59:38 EST)
Thanks for your great work. As far as I can tell, the referenced BST file 20171114-bibtex-doi/halpha-abbrv.bst does not contain the necessary changes.
Gautam Iyer (2018-01-29 15:03:46 EST)
Oops. You’re right! I uploaded a new version now. Thanks for pointing it out.
Anonymous (2018-10-10 06:05:12 EDT)
Thanks for the great work man! I used this on the german version of alpha, geralpha, and it worked like a charm. Had been stuck on the problem of unusual reference labeling that my research institute requires for a while now, and this solved the problem in a few minutes.
Anonymous (2019-10-30 07:00:45 EDT)
The style is very nice. One gripe: I have labels such as RFC1
and RFC2
, which I’d expect to appear in that order. However, the order is reversed when the latter is cited before the former. (Also, \bibliographystyle{habbrv}
should be \bibliographystyle{halpha-abbrv}
, or halpha-abbrv.bst
should be renamed.)
Anonymous (2019-10-30 07:05:41 EDT)
Wide labels creep into the text (similarly to stackexchange), this can be manually fixed (as shown on tex.stackexchange) using
\let\stdthebibliography\thebibliography \let\stdendthebibliography\endthebibliography \renewenvironment*{thebibliography}[1]{% \stdthebibliography{WideLabel99}} {\stdendthebibliography}
repaying WideLabel99
with a suitably wide label.
Gautam Iyer (2019-11-01 11:21:30 EDT)
The style is very nice. One gripe: I have labels such as
RFC1
andRFC2
, which I’d expect to appear in that order. However, the order is reversed when the latter is cited before the former.
Yikes, true. I don’t know how to fix BibTeX sort issues unfortunately. I’ve had trouble with it in the past.
(Also,
\bibliographystyle{habbrv}
should be\bibliographystyle{halpha-abbrv}
, orhalpha-abbrv.bst
should be renamed.)
Indeed, thanks. I fixed it.
GI
Anonymous (2019-12-15 17:07:52 EST)
Your diff changed my… style!!! iam editing a more than 1500 entries bibliography in a French style of my own (obliged to customize aren’t we all) and what else can I say that i haven’t said in the object - thanks to you, labels are labelled, luv it ! For the sorting matter, since i prefer an author date type, i commented the sort label, and as we say in French, roule ma poule! Your obliged, V@
Love Lindholm (2021-09-15 11:32:18 EDT)
Hello!
Thank you for your BibTeX style!
I have an issue with indentation: If my custom label is above a certain limit, the text of the BibTeX entry corresponding to that label starts with an indentation, i.e., it is not aligned with the start of the text for entries with shorter labels.
Is this something you have noticed? I am not TeX-savvy enough to modify your bst-file.
Kind regards Love
Gautam Iyer (2021-09-15 12:51:04 EDT)
So at the beginning of the .bib
file produced by BibTeX theres a \begin{thebibliography}{XXX12}
. Change this to \begin{thebibliography}{LONGESTLABEL}
and you should be good.
Love (2021-09-16 05:36:39 EDT)
That works, thank you. However, it would be more satisfying not to have to do this manually :-) Could your bst-file be modified to take into account the lengths of the added labels?
Gautam Iyer (2021-09-17 21:23:33 EDT)
Indeed I agree that’s better; I took a quick look at the file and it looks like it should already be doing that. But it’s not… I’ll see if I can chase down the error soon
Love (2021-09-29 08:10:54 EDT)
Thank. Yes, it seemed as if the bst-file was doing that. But I don’t know the language well enough to work on it.