6

As editor of a journal I need to translate the bibliography, in a bbl file, into part of an xml file (for potential submission to cross-ref). It seems best done on the fly by pdfLaTeX so I can also record in the xml the main metadata (authors, title, pages, volume, etc). Currently I use a scheme for bbl files where the \bibitem does not involve brackets, e.g. \bibitem{Smith99} ... The problem is that as soon as the bbl file uses brackets (as in natbib) then my scheme fails catastrophically on \bibitem[blah]{Smith99} ... Question: how can I get pdfLaTeX to parse a bbl file, with such \bibitem[]{}, into an xml file while pdflatex is typesetting to pdf?

Currently I do the following (hacked from somewhere in latex and executed \AtBeginDocument):

\renewcommand{\bibitem}[1]{</unstructured_citation></citation>
    ^^J<citation key="#1"><unstructured_citation>}
...  
\def\j@@Input{%
  \let\jrnltempb\jrnltempa
  \immediate\read\jrnlin to\jrnltempa
  \ifeof\jrnlin
    \immediate\closein\jrnlin
  \else
    \immediate\write\jrnlout{\jrnltempb}
    \expandafter\j@@Input
  \fi}
\typeout{**** Starting to write the bibliography to the xml.}
\newread\jrnlin
\immediate\openin\jrnlin\jobname.bbl\relax
\immediate\write\jrnlout{<citation_list>
    ^^J<citation key="nil"><unstructured_citation>}
\immediate\read\jrnlin to\jrnltempa  
\immediate\read\jrnlin to\jrnltempa
\j@@Input
\immediate\write\jrnlout{</unstructured_citation></citation>
    ^^J</citation_list>}  
\immediate\closein\jrnlin
  • Try using xparse, \usepackage{xparse}\DeclareExpandableDocumentCommand{\bibitem}{o{}m}{</unstructured_citation></citation>^^J<citation key="#2" opt-arg="#1"><unstructured_citation>}. – Bruno Le Floch May 15 '13 at 11:59
  • Does this have to be done with the .bbl file? I've seen .bst files that deliberately add an XML section to the .bbl from BibTeX, which is easier as the data contains no formatting. – Joseph Wright Aug 16 '13 at 10:23
2

Parsing the .bbl file is really not the optimal approach here: the file is meant for typesetting and must come from a more structured .bib file. A more sensible approach is to modify the .bst file used by BibTeX such that it writes XML data to the .bbl in form of a 'comment'. The latter can then be easily read back under appropriate conditions. To give more information we'd need a rather more complete example.

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.