1

I have a main document called main.tex involving multiple refsection environments. I have some figures that are compiled separately and are to be placed in some of these refsections. Let us say Fig1.tex creates Fig1.pdf that should appear in the first refsection of main.tex.

I am trying to use xcite to import citations from the main.tex to Fig1.tex. But while compiling Fig1.tex none of my citations are recognised. I understand that this is because in Fig1.tex I have no way to specify which refsection to use to xcite.

Are there any suggestions to resolve this issue?

0
2

As far as I can see xcite is not compatible with biblatex (which isn't really surprising given that biblatex reimplements the entire citation and bibliography handling completely). There are clever ways to get a biblatex–BibTeX bridge going with xcite as shown by egreg in Combine internal and external bibliography references. But as far as I am aware there is no biblatexbiblatex functionality for xcite.

In principle you can apply my solution to How to import / print a bibliography created from a separate / external document?. Essentially, that code just loads all the bibliography and citation information from the parent document (main.tex or maindoc.tex) and makes it available to the child (Fig1.tex or coverletter.tex). The child itself can only consume the information, it can not engage in influencing it.

There are a few caveats to the solution presented there

  1. Both the parent and the child document must load biblatex with the same options (some options could be varied, but those that have an impact on the .bbl can't be).
  2. You can only cite entries in the child document that were cited (or \nocited) in the parent document.
  3. Furthermore, the citations in the child document will be treated as non-existent in the parent document, i.e. they do not influence the sort order in sorting=none contexts, they don't increment any citation counters, they don't interact with 'ibid.' trackers.
  4. The citations in the child document can only be taken from reference contexts in which they appear in the parent document.

For refsections you need to manually tell the child document which refsection to use. Fortunately, that is quite simple: You just have to set a counter called refsection (e.g. \setcounter{refsection}{3} in the example below). In order to be able to do that properly, you need to find out the correct refsection from the parent document. The command \therefsection can help you there (if you don't want to count the relevant commands on your own).

main.tex

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric, backend=biber]{biblatex}

\addbibresource{biblatex-examples.bib}

\begin{document}
\newrefsection
This is refsetcion~\therefsection

\cite{sigfridsson,vizedom:related}
\printbibliography

\newrefsection
This is refsetcion~\therefsection

\cite{sigfridsson,worman}
\printbibliography

\newrefsection
This is refsetcion~\therefsection

\cite{sigfridsson,geer}
\printbibliography
\end{document}

external.tex with \importbibfrom{<parent base name>} and \setcounter{refsection}{<relevant refsection>}

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}
\usepackage[style=numeric, backend=biber]{biblatex}

\makeatletter
\newcommand*{\importbibfrom}[1]{%
  \def\blx@bblfile{%
    \blx@secinit
    \begingroup
    \blx@bblstart
    \InputIfFileExists{#1.bbl}
      {\blx@info@noline{... file '#1.bbl' found}%
       \global\toggletrue{blx@bbldone}}
      {\blx@info@noline{... file '#1.bbl' not found}%
       \typeout{No file #1.bbl.}}%
    \blx@bblend
    \endgroup
    % global sorting as this is called at BeginDocument
    \csnumgdef{blx@labelnumber@\the\c@refsection}{0}}}

\global\let\blx@rerun@biber\relax
\makeatother

\importbibfrom{main}

\setcounter{refsection}{3}

\begin{document}
\cite{sigfridsson}
\end{document}

Run the usual compilation cycle on main.tex

pdflatex main
biber main
pdflatex main
pdflatex main

Then run only LaTeX on external.tex

pdflatex external
pdflatex external

NB Note that this solution will not work if you have defernumbers enabled. That is because defernumbers needs the .aux file to process the label numbers properly. The solution above only reads the .bbl and not the .aux.

To make defernumbers work we can redirect the relevant bit of the .aux file from the parent to a different file (.naux) and read that in the child document. (Another solution would be to read the entire .aux file of the parent and only execute the relevant label number commands and skipping over the rest. That would be similar to what xcite does and would moreover not require additional code in the parent file - it would, however, require that I understand how this method/xcite works in more detail, so I went with what you can see below.)

Add

\makeatletter
\newwrite\blxconi@numaux@out

\AtEndDocument{%
  \begingroup
  \immediate\openout\blxconi@numaux@out\jobname.naux\relax
  \iftoggle{blx@defernumbers}
    {\iftoggle{blx@runbiber}
      {}
      {\def\do#1{\blx@auxwrite\blxconi@numaux@out{}{#1}}
       \dolistloop\blx@localnumaux}}
    {}%
  \immediate\closeout\blxconi@numaux@out
  \endgroup}
\makeatother

to the parent document and use

\makeatletter
\newcommand*{\blxconi@readdefernums}[1]{%
  \begingroup
  \makeatletter
  \@input{#1.naux}%
  \makeatother
  \endgroup}

\newcommand*{\importbibfrom}[1]{%
  \def\blx@bblfile{%
    \blx@secinit
    \begingroup
    \blx@bblstart
    \InputIfFileExists{#1.bbl}
      {\blx@info@noline{... file '#1.bbl' found}%
       \global\toggletrue{blx@bbldone}}
      {\blx@info@noline{... file '#1.bbl' not found}%
       \typeout{No file #1.bbl.}}%
    \blx@bblend
    \endgroup
    % global sorting as this is called at BeginDocument
    \csnumgdef{blx@labelnumber@\the\c@refsection}{0}}%
  \blxconi@readdefernums{#1}}

\global\let\blx@rerun@biber\relax
\makeatother

instead of the definition from above for the child document.

1

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.