I'm trying to hack a bibliography package (amsrefs), and fall into the following problem. I'm trying to convert the amsrefs format back to .bib files. This doesn't quite work, because strings get modified; i.e. a name such as Goode, Johnny~B. gets transformed to Goode, Johnny\nobreakspace {}B. and this is what appears in the output stream when I try to \immediate\write it.
How do I force the \nobreakspace and/or the more complicated \protect \unhbox \voidb@x \penalty \@M macros to evaluate to ~?
Here is a simplified version of what I'm trying to achieve, and the problem: saving this file into 'test.tex' and compiling it produces 'test.bib', which contains the lines
%Output bibliography test.tex to test.bib
@Book{
title={Goode, Johhny\protect \unhbox \voidb@x \penalty \@M \ {}B.}
}
and not just "title={Goode, Johnny~B.}"
\documentclass{article}
\usepackage{amsrefs}
\makeatletter
\def\printtitle#1{\immediate\write\bibfile{ title={#1}}}
\BibSpec{book}{%
+{}{\immediate\write\bibfile{@Book\@charlb}}{transition}
+{}{\printtitle}{title}
+{}{\immediate\write\bibfile{\@charrb}}{transition}
}
\begin{document}
\immediate\newwrite\bibfile
\immediate\openout\bibfile=\jobname.bib
\immediate\write\bibfile{\@percentchar Output bibliography \jobname.tex to \jobname.bib}
\begin{bibdiv}
\begin{biblist}
\bib{test}{book}{
title={Goode, Johhny~B.}
}
\end{biblist}
\end{bibdiv}
\immediate\closeout\bibfile
\end{document}