0

I created a command containing a list of bib files separated by a comma and a space. Then, I give this command to \bibliography, which produce no bibliography.

If I create the same list but only separated by comma (without space), the bibliography is produced.

Here is a MWE:

\documentclass{article}
    \newcommand{\PathBaseBib}{./biblioA.bib, ./biblioB.bib} % this is not working
    %\newcommand{\PathBaseBib}{./biblioA.bib,./biblioB.bib} % this (without space) is working
    \usepackage{natbib}
        \bibliographystyle{plain}

\begin{document}
    \cite{Knuth81} \cite{Lamport94}

    \bibliography{\PathBaseBib}
\end{document}

So I would like to understand why this simple space make fail the command \bibliogrpahy. And for esthetic reasons, I wonder if it is possible to correct this and so feed \bibliography with a command containing a list with spaces.

2
  • You shouldn't have to specify the extension .bib in the argument of \bibliography. What happens if you run \newcommand{\PathBaseBib}{biblioA,biblioB}?
    – Mico
    Feb 1 at 17:52
  • From my tests, both are working / not working with spaces. But I admit that I never know when using or not use extensions. So \newcommand{\PathBaseBib}{biblioA,biblioB} will work since there is no space but \newcommand{\PathBaseBib}{biblioA, biblioB} will not.
    – R. N
    Feb 1 at 17:59

1 Answer 1

2

Since \bibdata, which is written in the aux file, doesn't want spaces in its argument because of how BibTeX reads its input, the standard \bibliography command does \zap@space, but this fails if the argument is a macro.

You can fix this as follows:

\documentclass{article}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\bibliography}{\zap@space #1}{\expandafter\zap@space\expanded{#1}}{}{}
\makeatother

\newcommand{\PathBaseBib}{./biblioA, ./biblioB} % this is not working

\bibliographystyle{plain}

\begin{document}

\cite{Knuth81} \cite{Lamport94}

\bibliography{\PathBaseBib}

\end{document}

This will be written in the .aux file:

\relax 
\bibstyle{plain}
\citation{Knuth81}
\citation{Lamport94}
\bibdata{./biblioA,./biblioB}
\gdef \@abspage@last{1}

and you see that the space has been removed.

Beware that adding .bib to the files is not allowed generally. Only MiKTeX allows it, but it shouldn't.

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.