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.

Friends, I'm using a clever idea from Joseph, David and egreg in order to get the bibliography content displayed in both document and log (Henrique and I are trying to create a semi-automatic analyzer for biblatex styles). So far, this is the code I'm using:

\begin{filecontents}{\jobname.bib}
@BOOK{foo:2012a,
  title = {My Title One},
  publisher = {My Publisher One},
  year = {2012},
  editor = {My Editor One},
  author = {Author One}
}

@BOOK{foo:2012b,
  title = {My Title Two},
  publisher = {My Publisher Two},
  year = {2012},
  editor = {My Editor Two},
  author = {Author Two}
}

@BOOK{foo:2012c,
  title = {My Title Three},
  publisher = {My Publisher Three},
  year = {2012},
  editor = {My Editor Three},
  author = {Author Three}
}
\end{filecontents}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[backend=biber,
            bibstyle=numeric-comp,
            sorting=none]{biblatex}

\addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

\newsavebox\bibbox
\savebox\bibbox{\parbox{\textwidth}{\printbibliography}}
\showboxbreadth\maxdimen\showboxdepth\maxdimen\errorstopmode
\wlog{BEGIN BIBLIOGRAPHY}
\showbox\bibbox
\wlog{END BIBLIOGRAPHY}
\printbibliography

\end{document}

It works like a charm, including the .log display:

BEGIN BIBLIOGRAPHY
> \box26=
\hbox(65.92384+60.92383)x345.0
.\mathon
.\vbox(65.92384+60.92383)x345.0
..\penalty -300
..\glue 15.06577 plus 4.3045 minus 0.86089
..\glue(\parskip) 0.0
..\hbox(9.93758+0.0)x345.0, glue set 271.08008fil
...\hbox(0.0+0.0)x0.0
....\glue 0.0
...\T1/cmr/bx/n/14.4 R
...\T1/cmr/bx/n/14.4 e
...\T1/cmr/bx/n/14.4 f
...\T1/cmr/bx/n/14.4 e
...\T1/cmr/bx/n/14.4 r
...\T1/cmr/bx/n/14.4 e
...\T1/cmr/bx/n/14.4 n
...\T1/cmr/bx/n/14.4 c
...\T1/cmr/bx/n/14.4 e
...\T1/cmr/bx/n/14.4 s

[...]

I was trying to patch \printbibliography in order to "hide" these macros and make it easy for us to debug other documents. My plan was to create a debug package and include it in the main document, say mydebug.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mydebug}[2013/01/09 Debugging biblatex styles]

\let\origprintbibliography\printbibliography
\renewcommand\printbibliography[1][]{
\newsavebox\bibbox
\savebox\bibbox{\parbox{\textwidth}{\oldprintbibliography[#1]}}
\showboxbreadth\maxdimen\showboxdepth\maxdimen\errorstopmode
\wlog{BEGIN BIBLIOGRAPHY}
\showbox\bibbox
\wlog{END BIBLIOGRAPHY}
\oldprintbibliography[#1]
}

But sadly, I'm failing at patching \printbibliography. Could someone enlight my path? :)

share|improve this question
add comment

1 Answer

up vote 11 down vote accepted

It's the usual problem: you need letltxmacro, because \printbibliography has an optional argument, see When to use \LetLtxMacro?. Here's my pick:

\usepackage{letltxmacro}
\LetLtxMacro\biblatexprintbibliography\printbibliography
\newsavebox\bibbox

\renewcommand\printbibliography[1][]{
  \chardef\currentmode=\interactionmode % save the current interaction mode
  \batchmode % set batch mode so we won't be interrupted
  \begingroup % the changes to the parameters are local
    \showboxbreadth\maxdimen
    \showboxdepth\maxdimen
    \savebox\bibbox{\parbox{\textwidth}{\biblatexprintbibliography[#1]}}
    \wlog{BEGIN BIBLIOGRAPHY}
    \showbox\bibbox
    \wlog{END BIBLIOGRAPHY}
  \endgroup
  \interactionmode=\currentmode % restore the interaction mode
  \biblatexprintbibliography[#1]
}

The changes to the interaction mode are always global, that's why one needs to restore it explicitly.


A different way, simply patching \blx@printbibliography:

\usepackage{xpatch}
\makeatletter
\def\biblio@inlog#1{%
  \begingroup
  \let\biblio@inlog\@gobble
  \chardef\current@mode\interactionmode
  \showboxdepth=\maxdimen
  \showboxbreadth=\maxdimen
  \sbox\z@{\vbox{\printbibliography[#1]}}
  \batchmode
  \wlog{BEGIN BIBLIOGRAPHY}
  \showbox\z@
  \wlog{END BIBLIOGRAPHY}
  \interactionmode=\current@mode
  \endgroup}
\xapptocmd{\blx@printbibliography}{\biblio@inlog{#1}}{}{}
\makeatother

The \biblio@inlog command redefines itself when expanded, so it will do nothing when the box to be shown is built.

share|improve this answer
2  
won't bother posting mine then :-) –  David Carlisle Jan 9 '13 at 16:02
    
Absolutely fantastic. Thank you very much, my friend. :) –  Paulo Cereda Jan 9 '13 at 16:29
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.