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.

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
share|improve this question
    
Try using xparse, \usepackage{xparse}\DeclareExpandableDocumentCommand{\bibitem}{o{}m}{</unstruct‌​ured_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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.