# Problem with bibtool when extracting bibliography information from an aux file in LaTeX/BibTeX

It seems that the latest version of bibtool (2.67) has a problem reading .aux files.

MWE (from here):

1. a file named exampl_01.tex:

\documentclass{article}

\begin{document}

Random citation \cite{DUMMY:1} embedded in text.

\newpage

\bibliography{lesson7a1}
\bibliographystyle{plain}

\end{document}


2. a file named lesson7a1.bib:

@BOOK{DUMMY:1,
AUTHOR="John Doe",
TITLE="The Book without Title",
PUBLISHER="Dummy Publisher",
YEAR="2100",
}


Upon LaTeXing the above, we get (among others) the file exampl_01.aux, which has the content

\relax
\citation{DUMMY:1}
\bibdata{lesson7a1}
\bibcite{DUMMY:1}{1}
\bibstyle{plain}


Then we run bibtool as follows

bibtool  -x exampl_01.aux -o used_references.bib


We get the output

*** BibTool WARNING: File bibstyle not found.


The file used_references.bib is produced, but is empty.

Note that the manual (pp. 10-11, 1.2.4. Extracting Entries for a Document) gives the following sample command: bibtool -x document.aux -o document.bib. Thus, it seems the above should have worked, but it doesn't.

If we simply erase the line \bibstyle{plain} from the .aux file and rerun bibtool, we get the error message

*** BibTool WARNING: File bibcite not found.


The file used_references.bib is again empty.
Finally, if we also erase the \bibcite{DUMMY:1}{1} line from the the .aux file and rerun bibtool, we get no error messages and the file used_references.bib contains what we expect, namely,

@Book{        dummy:1,
author    = "John Doe",
title     = "The Book without Title",
publisher = "Dummy Publisher",
year      = "2100"
}


I see this behavior both under kubuntu 18.04 and under cygwin. In the bibtool documentation, I see no mention of this.

I used to be able to do this without any errors.

Is this a bug in the newest version of bibtool? (Which is actually not that new: executing bibtool -help gives 2017 as the most recent year.) Am I doing something wrong?

There is a hack that has worked for me so far: use grep to extract just the relevant lines from the .aux file (namely those that begin either with \citation or with \bibdata), and run bibtool on that file. Here's one way to do it:

grep -E '\\citation|\\bibdata' exampl_01.aux  > cleaned-up_aux_file.aux
bibtool  -x cleaned-up_aux_file.aux -o used_citations_01.bib
rm cleaned-up_aux_file.aux


The problem is that I don't really know the details of how either BibTeX or bibtool work 'under the hood', and so I don't know if this hack really solves the problem in all circumstances, or if I have just been lucky so far.

Questions:

1. Is the described behavior a bug?

2. Is there a better workaround than the hack I described?

3. Are there any potential problems that my hack could create?