User installed LaTeX packages are not inherited from base project

In my class I use a custom Rmarkdown template for students to compile their rmd files to pdf in order to submit them to our LMS for grading. In the past some students typed unicode characters in their files, which then mysteriously failed to compile with latex, so I changed the engine to xelatex and used a unicode aware font. This is the YAML header form the template.

title: ""
author: ""
    df_print: tibble
    latex_engine: xelatex
    toc: true
    toc_depth: 2
    toc_float: true
    df_print: paged
    code_folding: none
    code_download: false
geometry: margin=1in
mainfont: FreeSerif

On Rstudio cloud, this will not compile because of missing unicode-math LaTeX package. I installed unicode-math in the base project following the instructions here, but when testing it, it seems that the local LaTeX environment does not get inherited from the base project to my students' projects.

Is there something I can do about that?

When using base projects, only the /cloud/project and ~/R directories are copied, in order to protect private information a user might store.

In order to use tlmgr to install a LaTeX package that would be copied, you will have to point the usertree to a non-default location, e.g., within /cloud/project, when calling init-usertree. You might then be able to configure TEXMFHOME in the project's .Renviron.

This is all a guess, but hopefully it will serve as a starting point for you to experiment.

Thanks, that sounds like a good starting point. However, when I tried it, something went wrong:

  1. Since I have already created the TEXMFHOME directory in ~, I just copied it to /cloud/project using cp -r ~/texmf .texmf in /cloud/project. The directory got copied there, and I could browse it and everything.

  2. Then I tried to create .Renviron in /cloud/project, first using usethis::edit_r_environ("project") which refused to work, complaining that the file system is read only. I then tried to create .Renviron with vim, but again, vim refused to save the file, claiming the directory is read only.

  3. That confused me, since I was just few minutes earlier able to create the .texmf directory there! I decided that maybe I got logged out somehow and now do not have the permissions, so I logged out and logged in to again. Then I tried to open my base project, but it how refuses to open, and hangs forever on "Opening project" screen. I tried to re-launch it few times, but it did not help.

The project is, if it helps.

OK, so the project is working again, and the proposed solution seems to be working as well. Here is what I did:

  1. Copy the existing texmf directory from home to /cloud/project by entering cp -r ~/texmf /cloud/project/.texmf in the terminal. If there is no ~/texmf yet, skip this.

  2. Run usethis::edit_r_environ("project") in the R console to edit the project .Renviron file.

    Add the line


    to the file.

  3. Restart R.

After that, install any new LaTeX packages using tlmgr as usual. They will automatically go to the new location. Copies of this project will then inherit all the LaTeX packages installed this way, so if you do it in your base project, all new projects will have them.

Thank you for your help!


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.