One of the things I personally find annoying about LaTeX is the syntax, and BibTeX is even worse, frankly, but it's not that insanely complicated once you adjust to the stack-oriented character of the language. You may find it useful to keep pen and paper nearby so you can keep track of what's on the stack as you trace the code.
If you haven't read it, obviously you should read btxhak.dvi, the guide to hacking BibTeX style files. It takes a while---I know---to get a sense for how the language works, and how these style files work, but it will start to make sense after a while. You should also export to LaTeX, compile the file manually, and look at what is being written to the .bbl file, when various bibliography styles are used. The labels used in the bibliography, and in the text, are set by the \bibitem command that the style file writes to the .bbl file. In many style files, this seems to be written by the output.bibitem function, which is called at the beginning of each of the functions, article, book, etc, that are called for the appropriate sorts of items. Here it is from plain.bst: FUNCTION {output.bibitem} { newline$ "\bibitem{" write$ cite$ write$ "}" write$ newline$ "" before.all 'output.state := } This ends up writing something like: \bibitem{Descartes:Rules} to your .bbl file. Compare this function, from alpha.bst: FUNCTION {output.bibitem} { newline$ "\bibitem[" write$ label write$ "]{" write$ cite$ write$ "}" write$ newline$ "" before.all 'output.state := } This writes something like: \bibitem[Des82]{Descartes:Rules} to the .bbl file, with the result that the label "Des82" is used both in the text and the bibliography. Since there is no such argument to \bibitem in the previous case, the default is used: The cite key is simply a number. The variable "label" is what holds the value of the cite key in alpha.bst. Where was it set? You will note that it is mentioned in the ENTRY declaration, both in plain.bst and in alpha.bst, as a "string variable" that is associated with each item in the bibliography. This is NOT an item set in the .bib file itself---unlike author, title, etc---but rather a new variable that has been declared to be associated with each item and that can be manipulated in the .bst file. In plain.bst, the label variable is set in the function longest.label.pass: FUNCTION {longest.label.pass} { number.label int.to.str$ 'label := % number.label was initialized to 1 in initialize.longest.label % its string form is here being assigned to label number.label #1 + 'number.label := %this increments number.label label width$ longest.label.width > { label 'longest.label := label width$ 'longest.label.width := } 'skip$ if$ } (I've added comments.) This function is called for each item in the bibliography with: ITERATE(longest.label.pass) which is itself called after the list has been sorted and such. If you look at alpha.bst, you will see that label is set for each item in calc.label, which is itself called in the function presort, called with ITERATE(presort). Hint: If you want to know where a variable named "var" is set, search for: 'var, since an assignment to var will look like: 'var :=, the assigned value being whatever is on the top of the stack. (If you see whatever 'var ;=, then the occurrence of "whatever" is just pushing a value onto the stack.) So the label variable exists in plain.bst, but it is not used there. But we can use it. For example, suppose we change the definition of output.bibitem in plain.bst to the following: FUNCTION {output.bibitem} { newline$ "\bibitem[FROG" write$ label write$ "]{" write$ cite$ write$ "}" write$ newline$ "" before.all 'output.state := } Then we get cite keys like: FROG3, FROG25, etc. Your request is more complicated, because we want something different for different types of entries. But that's OK, because we have the entry type in the type$ variable, and we can just check that. The easiest thing to do would seem to be to define a new function that will print the prefix we want depending upon the entry type. This function will handle articles, incollections, and books: FUNCTION {output.prefix} { type$ "incollection" = type$ "article" = + %hack for "or" { "Art" } { type$ "book" = { "Book" } { "Other" } if$ } if$ } If you need to add other types, that's obviously easy to do. (There's no elsif here, so we have to use nested ifs. Exercise: Code up a switch or case statement!) We then redefine output.bibitem as follows: FUNCTION {output.bibitem} { newline$ "\bibitem[" write$ output.prefix write$ label write$ "]{" write$ cite$ write$ "}" write$ newline$ "" before.all 'output.state := } That should do what you need, more or less. Richard Ares wrote: > As I wrote in a previous post, I would like the references of my PhD > thesis > to be arranged as follows: > >> References >> >> Articles >> [Art1] article1 >> [Art2] article2 >> etc >> Books >> [Book1] book1 >> [Book2] book2 >> etc >> etc >> ... > > LyX 1.4.1 supports "sectioned bibliography", so it is possible to > split the > Bibliography chapter in sections. > > In order to have the citation as [Art1] and [Book1] etc, I need to hack a > bst file, as suggested by Jürgen. I had a look to plain.bst and it > doesn't > sound so easy! > > In the end I would just like to add a prefix (Book, Art etc) to the > reference numbering and to use a separate bst file for each entry (Books, > Articles etc), so that the numbering starts with each "section". > > Is there a resource where I can find how bst files work? or is there > someone > who can help me? > > Thanks for support, > Diego >