2

I am trying to use the xr package in Overleaf and set a custom font in the referenced file. However, as soon as I load the fontspec package in the referenced file, the xr package does not recognize the references anymore.

To confirm this, I opened the minimal working example as given in the example on the overleaf website by clicking "Open an example in Overleaf" under final project. Then I added

\usepackage{fontspec}

under

\documentclass{article}

Of File2.tex, recompiling File2.tex twice and File1.tex twice using XeLaTeX as compiler then results in ?? instead of the reference number and a warning saying

Reference `label1' on page 1 undefined

Is there some interference between the xr package and fontspec? Or am I overlooking something?

  • 1
    Please copy the minimal example to here. (1) people generally do nt like to go off site for relevant material and (2) if the links item disappears your question is no longer usable to others in the future. – daleif Jul 2 at 15:09
2

If file2.tex needs to use fontspec, then it also needs to use xelatex or lualatex in order to compile without errors.

Even if your project is set up to use XeLaTeX or LuaLaTeX, when file2.tex is compiled as an external document, whatever's set up in the latexmkrc file is used, not the actual project's compiler setting.

To fix this, edit the latexmkrc file in the project to comment out line 11 and uncomment either XeLaTeX (line 17) or LuaLaTeX (line 20) as appropriate. For example, to compile external documents with XeLaTeX instead of pdfLaTeX:

add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );

sub makeexternaldocument {
    # if the dependency isn't one of the files that this latexmk run will consider, process it
    # without this test, we would get an infinite loop!
    if (!($root_filename eq $_[0]))
    {   # PLEASE ENABLE ONLY ONE OF THE FOLLOWING
        # DEPENDING ON THE ENGINE YOU'RE USING

        # FOR PDFLATEX
        # system( "latexmk -pdf \"$_[0]\"" );

        # FOR LATEX+DVIPDF
        # system( "latexmk \"$_[0]\"" );

        # FOR XELATEX
        system( "latexmk -xelatex \"$_[0]\"" );

        # FOR LUALATEX
        # system( "latexmk -lualatex \"$_[0]\"" );
   }
}

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.