5

Doesn't it require knowing the current font?

Edit: It seems I'm being hopelessly unclear. Let's try again. Suppose I'm writing a paper and I'm using BibTeX. I therefore have a file called bib.bib, which contains a bunch of useful bibliography entries. Suppose further that my paper cites only two other papers, one by Me, Myself, and I, and another by Us and Them. Suppose further that I'm using the alpha style, so these two papers are referenced as [MMI98] and [UT15], or whatever. When I run BibTeX, it will generate a .bbl file, which will contain something like \begin{thebibliography}{MMI98}. How does it know that 'MMI98' is longer than 'UT15'?

  • And in the .bbl file, it writes a thebibliography environment, which takes a mandatory argument: the widest label. And BibTeX seems to always get it right. How? – Mark Apr 13 '16 at 3:33
  • The environment thebibliography is defined in the class file (e.g., in article.cls). It is essentially a list environment, which asks for you to input the 'widest label'. When TeX (the program, which LaTeX uses) gets to typesetting that portion, it knows the fonts being used. BibTeX has nothing to do with it normally. And it can be done 'wrongly': try saying there's only one item in your bibliography, but then include 100 or 1000 items. it won't look the way you want it. – jon Apr 13 '16 at 3:39
  • 1
    Oh, I see. Well BibTeX does calculate that, but it measures it on the basis of Computer Modern at 10pt (cmr10) to determine which label should be the longest. But what is actually measured and typeset is that same longest string but as it is measured in the current font (e.g., the \bibfont in some cases). So I guess if you have a font whose character widths are wildly out of sync with Computer Roman, you could end up with incorrect label sizes. Of course, most academic documents are not typeset in wildly uneven fonts.... – jon Apr 13 '16 at 4:33
  • 2
    No: putting \tt before the bibliography is not going to do anything at all (unless you have done other things to how the bibliography is constructed). Because BibTeX does no typesetting (really!!) you can't fool it in that way. If you want to learn more about BibTeX, see Tame the BeaST (try texdoc ttb at the command line; or go to CTAN) and read chapter four. Also, thebibliography environment usually has its own font commands, so you cannot change the bibliography by writing \tt right before it. (And you should not use \tt in a LaTeX document: the command is \ttfamily.) – jon Apr 13 '16 at 5:02
  • 1
    @jon -- answer please. – barbara beeton Apr 13 '16 at 13:50
4

An assumption is required to answer this particular question:

  • class is article.cls -- the class (usually) defines the thebibliography environment

The question states that the alpha style is being used, one of the default styles. In the example below, I have loaded natbib, which 'preserves' that basic style. However, loading natbib helps show (1) how BibTeX really doesn't care about what fonts you happen to be using in your document at the point at which the bibliography is added to the output, and (2) that some bibliography-related packages (e.g., natbib or biblatex) allow you to control font-related stuff independently.

Then imagine this document:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}

@article{aa,
  author =     {Me and Myself and I},
  title =      {My Article},
  journal =    {My Journal},
  year =       {2016},
  number =     1,
  volume =     1,
  pages =      {1-20},
}

@article{bb,
  author =     {Us and Them},
  title =      {Our Article},
  journal =    {Our Journal},
  year =       {1996},
  number =     2,
  volume =     2,
  pages =      {1-20},
}

\end{filecontents*}
\usepackage[T1]{fontenc}
\usepackage{natbib}
%\renewcommand{\bibfont}{\sffamily\itshape}

\begin{document}
\nocite{*}

%\ttfamily
\bibliographystyle{alpha}
\bibliography{\jobname}
\end{document}

If we run latex then bibtex, the following .bbl is produced:

\begin{thebibliography}{MMI16}

\bibitem[MMI16]{aa}
Me, Myself, and I.
\newblock My article.
\newblock {\em My Journal}, 1(1):1--20, 2016.

\bibitem[UT96]{bb}
Us and Them.
\newblock Our article.
\newblock {\em Our Journal}, 2(2):1--20, 1996.

\end{thebibliography}

The question is (I believe): how did BibTeX figure out that the widest label is MMI16 and not UT96?

An old but still valuable resource for BibTeX is Tame the BeaST: The B to X of BibTeX. In chapter four, the joys of Reverse Polish Notation are described so that you can understand and hack .bst files. On page 35, we read about the width$ function, which explains that this function,

returns the length of string S, in hundredths of a point, when written using font cmr10 of June 1987. You probably don’t mind the details... This function is used for comparing widths of labels, the longest label being passed as the argument of the thebibliography environment;

Thus, if your document uses a particularly strange font, which has unusual widths for its characters (e.g., the i takes up more space than the m), there is a danger that BibTeX -- because it knows nothing and cares nothing about what fonts your document actually uses -- will pick the wrong label as the longest. However as most fonts suitable for academic or professional use share similar characteristics regarding the width of the characters (e.g., the i is always smaller than the m), this is probably not dangerous.

Finally, regarding adding a \ttfamily before your bibliography (you can uncomment the line in the file above), this changes the main font of the document to whatever \ttfamily is set to. This can certainly change the font your bibliography appears in (but not its heading). But this has nothing to do with BibTeX and everything to do with your documentclass and any packages you have loaded. For example, with natbib, you can redefine \bibfont if you like, which would then make the use of \ttfamily irrelevant (try uncommenting that line in the above file).

  • Not sure why you're bringing natbib into this, alpha is one of the four standard styles available without any extra packages. I'm pretty sure the article class just typesets the bibliography in whatever the "prevailing" font is at the time that it starts. (Although like you said, not the heading.) But anyway, thanks both for your answer and for its source. This tame the beast thing seems to have all sorts of nice gems. – Mark Apr 13 '16 at 17:10
  • 1
    @Mark -- True. I assumed you were using it because it is very commonly used (this is why it is helpful to post code with most questions: so people like me don't make incorrect assumptions). However, I also wanted to make the point that putting a command like \ttfamily in your document does not necessarily affect the bibliography in any way whatsoever (which wouldn't be true in the 'bare' version you were asking about). Anyway, should I edit the answer? – jon Apr 13 '16 at 17:20
  • Re: edit answer: strictly optional, but it won't hurt. Re: posting code: I think I finally learned today at a gut level why the rallying cry around here is "MWE". – Mark Apr 13 '16 at 17:28
  • 1
    @Mark -- OK, changed the preamble a bit. (As for the MWE, the more you use them, the more you see why they are necessary to get or give good answers!) – jon Apr 13 '16 at 17:38
  • than you once more! – Mark Apr 14 '16 at 3:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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