4

This question asks how to keep a code in a bbl file. Fortunately, the root cause could be found and solved without fiddling with the bbl file. Several answers pointed out that the bbl file should not be changed and that there are (usually) better ways to accomplish whatever is the goal.

However, there are situations in which modifying the bbl file is the only option. In this case, I need to balance the columns on the last page of an article using the ACM sig-alternate LaTeX class. The "official" solution, suggested by the authors of the sig-alternate style, is to modify the bbl file and insert the command \balancecolumns in the position where the column break should occur. Naturally, I would like to avoid modifying it directly and instead find a maintainable way of getting the column break.

None of the solutions I have found work in my case (I know that they work in some cases, but I now have a paper where they don't). I have tried the balance package, the flushend package, experimented with the multicol package, fiddled with the page height, ...

At this point, the most maintainable solution really does seem to be to somehow get the ACM sig-alternate class command \balancecolumns into the bbl file automatically. Is there any way I can accomplish this by editing the BibTeX file or the LaTeX file? It's fine if I have to specify myself where the break should occur, but I would not like to modify temporary files such as the bbl file. Do I have to resort to programmatically editing the file with sed or something?

4

In general material can be added to a .bbl file by using

@premble{ <command to be inserted in the bbl> }

However, @preamble adds at the begin of the .bbl.

A strategy to add some command at a specific point in the bbl is to create a hook (using toolbox \patchcmd) in \bibitem which is activated by a particular key. Here is a possible way to do it

\patchcmd{\@bibitem}
  {\item}
  {\ifstrequal{#1}{KEY}{\balance}{}\item}
  {}
  {}
\patchcmd{\@lbibitem}
  {\item}
  {\ifstrequal{#1}{KEY}{\balance}{}\item}
  {}
  {}
\makeatother

The above code essentially adds \balancecolumns just before the reference with key KEY. Notice that in plain latex \bibitem expands to \@lbibitem or \@bibitem and that we have to patch these two commands.

Here is a complete MWE

\documentclass[twocolumn]{article}

\usepackage{etoolbox}
\usepackage{balance}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
 @article{first,
   author = "A.U. Thor",
   title = "Atitle",
   journal = "AJournal",
   year = 2013,
   pages = {1-10}
 }
 @article{second,
   author = "A.U. Thor",
   title = "Btitle",
   journal = "AJournal",
   year = 2013,
   pages = {11}
 }
 @article{third,
   author = "A.U. Thor",
   title = "Ctitle",
   journal = "AJournal",
   year = 2013,
   pages = {12-}
 }
 @article{fourth,
   author = "A.U. Thor",
   title = "Dtitle",
   journal = "AJournal",
   year = 2013,
 } 
\end{filecontents}

\makeatletter
\patchcmd{\@bibitem}
  {\item}
  {\ifstrequal{#1}{third}{\balance}{}\item}
  {}
  {}
\patchcmd{\@lbibitem}
  {\item}
  {\ifstrequal{#1}{second}{\balance}{}\item}
  {}
  {}
\makeatother
\begin{document}

\nocite{*}
\bibliographystyle{plain}
\bibliography{\jobname}  
\end{document}

with the resulting output

enter image description here

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.