6

This question is actually a follow-up to another question of mine, Patching \printbibliography for displaying content to both document and log. The code works marvellously, and I'm able to analyze the text formatting for every entry. The tricky part is how to separate where an entry ends and the other one starts:

...

...\T1/cmr/m/n/10 2
...\T1/cmr/m/n/10 0
...\T1/cmr/m/n/10 1
...\T1/cmr/m/n/10 2
...\T1/cmr/m/n/10 .
...\penalty 10000
...\glue(\parfillskip) 0.0 plus 1.0fil
...\glue(\rightskip) 0.0
..\penalty -51
..\glue 4.0 plus 2.0 minus 1.0
..\glue(\parskip) 0.0
..\glue(\baselineskip) 4.50183
..\hbox(7.49817+2.49939)x324.44702, glue set 0.4662, shifted 20.55298
...\hbox(7.49817+2.49939)x0.0
....\glue 0.0
....\glue -10.55298
....\glue -10.0
....\hbox(7.49817+2.49939)x10.55298
.....\glue 0.0 plus 1.0fil minus 1.0fil
.....\T1/cmr/m/n/10 [
.....\T1/cmr/m/n/10 2
.....\T1/cmr/m/n/10 ]
....\glue 10.0
...\penalty 0
...\T1/cmr/m/n/10 A
...\T1/cmr/m/n/10 u
...\T1/cmr/m/n/10 t

...

Since I know beforehand that my bibliography style uses [1], [2] and so forth, I can easily spot where the new item starts. But I was thinking if I could append a keyword to every item, so I can use it as a closing markup.

In the chatroom, Marco Daniel brilliantly suggested me to go with:

\renewbibmacro*{finentry}{\finentry <keyword here>}

This will append <keyword> to every bibliography item. So far, it's an interesting approach. But there's something I'd like to avoid: the keyword will also be printed in both document and .log file.

Sadly, \wlog doesn't work here because the box content is saved for a later use. The macro will be called when the entries are added to the .aux file and not during the box trace.

My test file:

\documentclass{article}

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

\addbibresource{biblatex-examples.bib} 

\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

\begin{document}

\cite{companion} \cite{ctan} 

\printbibliography

\end{document}

Does anybody have a suggestion if I can add any keyword or mark that indicates the end of a bibliography item in the .log output, but not in the document? I suspect this is not possible or the box saving process must be drastically altered.

1 Answer 1

7

There's not much to do: \wlog and \showbox come from two different places during processing and you can't interrupt the output of \showbox with other messages.

Instead of adding a marker for the end, you can look for a marker at the beginning of an entry; from the log you see that the label appears with the following pattern

.....\T1/cmr/m/n/10 [

because it's typeset at a deeper level of boxing. So a way can be to add something invisible to the box, for instance \textcompwordmark, which would produce a line of the form

.....\T1/cmr/m/n/10 ^^W

because the \textcompwordmark invisible and zero width glyph lives in slot 0x17 of the font table and 0x57 is W.

Just find a way to add \textcompwordmark to the typesetting of the label. This won't add to the box dimensions as the following example shows.

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\showboxdepth=\maxdimen
\showboxbreadth=\maxdimen
\sbox0{[1]}
\showbox0
\sbox0{\textcompwordmark[1]}
\showbox0
\stop

with the relevant part of the .log file

> \box0=
\hbox(7.49817+2.49939)x10.55298
.\T1/cmr/m/n/10 [
.\T1/cmr/m/n/10 1
.\T1/cmr/m/n/10 ]

! OK.
l.8 \showbox0

?
> \box0=
\hbox(7.49817+2.49939)x10.55298
.\T1/cmr/m/n/10 ^^W
.\T1/cmr/m/n/10 [
.\T1/cmr/m/n/10 1
.\T1/cmr/m/n/10 ]

! OK.
l.10 \showbox0

Since your document uses the standard bibliography environment, the one defined with \defbibenvironment{bibliography}, a simple patch will change it so that the bibliography labels are preceded by \textcompwordmark:

%%% After loading biblatex
\makeatletter
\patchcmd{\blx@env@bibliography}{\hss}{\hss\textcompwordmark}{}{}
\makeatother

Here's what I get in the log file (truncated)

[...]
....\hbox(7.49817+2.49939)x10.55298
.....\glue 0.0 plus 1.0fil minus 1.0fil
.....\T1/cmr/m/n/10 ^^W
.....\T1/cmr/m/n/10 [
.....\T1/cmr/m/n/10 1
.....\T1/cmr/m/n/10 ]
[...]

An easy regex search will find the start of bibliography items.

Thanks to Marco Daniel, this seems a better way to add the invisible glyph:

\DeclareFieldFormat{labelnumberwidth}{\textcompwordmark\mkbibbrackets{#1}}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .