Latexmk is a wonderful tool to get rid of the annoyances linked to compiling LaTeX files yourself (multiple executions of the compiler are needed, biber needs to be run at the correct times in between, and the like). These days latexmk provides a useful -xelatex flag that enables the use of XeLaTeX to compile documents into PDF files (as opposed to, for example, pdflatex). I however did not feel like having to add that flag every time I run latexmk, so wanted to add it to my latexmkrc file. With the flag I mentally associated only needing to set one variable in the configuration, but nothing online seemed to point towards it being this simple and many seemed to be providing something they conjured themselves.

Instead, I decided to just look at latexmk’s source which is simply some perl code. The only relevant lines involving the flag were as follows.

  elsif (/^-xelatex$/)      { 
      $pdflatex = "xelatex %O %S";
      $pdf_mode = 1;
      $dvi_mode = $postscript_mode = 0; 
  }

What that does is set some specific variables when the -xelatex flag is encountered. Since the configuration file is just perl code itself, that meant I simply had to add those variables to my latexmkrc file to have XeLaTeX by default in the manner most closely resembling what the -xelatex flag does. In conclusion, add the following lines to your latexmkrc file and you are good to go!

$pdflatex = "xelatex %O %S";
$pdf_mode = 1;
$dvi_mode = $postscript_mode = 0;