rpackagelatexr-markdownxelatex

getting started with custom templates RMarkdown vitae


In order to start working with customizing templates for use with the R package "vitae" I did what I thought was the simplest first step: I knit a document with the "awesomecv" template, and then copied that .tex template to my working directory. This had the advantage of generating the supplementary files to ideally be used by the new template in the local directory. I made a small modification to the template, just changing the color to "awesome-emerald" as shown by my copy here

I changed the output section of the YAML in the .Rmd file in the repository to...

output:
  vitae::cv_document:
    template: awesome-cv_mod.tex

The rest of the file is otherwise the same as what is in the repository. However, I now get the following error:

! Fatal Package fontspec Error: The fontspec package requires either XeTeX or
(fontspec)                      LuaTeX.
(fontspec)                      
(fontspec)                      You must change your typesetting engine to,
(fontspec)                      e.g., "xelatex" or "lualatex" instead of
(fontspec)                      "latex" or "pdflatex".

I changed my engine in the .Rproj file and it shows up correctly as XeLaTeX in the Sweave tab of Project options... but this doesn't get rid of the error. It doesn't make sense to me why that would be required anyway, since it works fine out of the box for this template otherwise. Does anyone have insight into what's going on here? Is this error message true, or indicative that I am missing something in the process? I am running Ubuntu 22


Solution

  • Unfortunately, I'm afraid that the Awesome CV template may only work on lua/xelatex because of it's reliance on the fontspec package. I'll explain how I came to that determination:

    1. The Documentation for the awesomecv() function implies that pdflatex is a valid option for the latex_engine = argument. However, it errors (as you point out) when it is set to to "pdflatex".

    2. Investigating the readme for the awesomeCV, the usage section only shows the option to run with xelatex.

    3. An issue open in the vitae repo points out the inability to use the "default engine" (pdflatex) for awesomeCV, and the maintainer directs them to set the latex_engine = xelatex.

    Based on that evidence, I'm inclined to say that this isn't an error in the coding that you've done or the coding of the vitae package, but rather, the documentation for the awesomecv() function is incorrect in saying that "pdflatex" can be used as the latex_engine.

    All that considered, I know you said that you are adverse to changing your LaTeX engine, but that may be the only way to proceed with this template.

    If you wish to continue with xelatex, try the following:

    Change your YAML header to the following for you CV .Rmd:

    ---
    name: Jessica
    surname: Gorzo
    position: "Data Scientist"
    pronouns: she/her
    address: "Cellular Tracking Technologies"
    www: avianecologist.com
    twitter: setophaga
    github: dendroica
    linkedin: gorzo
    date: "`r format(Sys.time(), '%B %Y')`"
    output:
      vitae::cv_document:
        latex_engine: "xelatex" # It is important to specify this
        template: awesome-cv_mod.tex
    csl: apa-single-spaced_mod.csl
    ---
    

    That should get you your modified coloring:

    enter image description here

    EDIT for More Clarity on Process

    1. Download the bib, CV rmd, template tex, and csl files from GH and put all into the same folder

    2. Open CV rmd, Render once with options as is to make sure I get correct PDF with default options

    3. Change YAML options to those show above, selecting the tex template and xelatex engine

    4. Render once more - get the correct colored output and all options