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.
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.
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:
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.
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.
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 rstudio.cloud 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.
OK, so the project is working again, and the proposed solution seems to be working as well. Here is what I did:
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.
Run usethis::edit_r_environ("project") in the R console to edit the project .Renviron file.
Add the line
TEXMFHOME=/cloud/project/.texmf
to the file.
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.