Installing and Using LaTex Packages

Workspace users can use the full range of LaTeX packages when creating PDF reports. These allow the creation of more complex reports and are also necessary for using certain LaTeX templates. LaTex packages are installed in a similar way to installing R packages using the LaTex package manager.

Installing LaTex packages

When you are in an active R Console session follow the commands below to install LaTex packages.

1. Set the repository URL `system("tlmgr init-usertree") system("tlmgr --usermode option repository")`

2. To install packages, run the below code replacing the package name . `system("tlmgr --usermode install <package_name>",ignore.stderr = TRUE)</package_name>` For example: `system("tlmgr --usermode install collection-fontsrecommended",ignore.stderr = TRUE)`

The installed packages should now be added to your workspace files in the files/texmf folder. The Latex packages can be used inside a .Rnw file to generate PDF reports.

Using the LaTex compiler

LaTex packages can be used to generate PDF reports within the workspace using the following instructions.

  1. Click the "Files" menu and select the option for a New File. Enter a file name and select "R NoWeb file" (.rnw) as the format.

  2. Once the file opens, add the LaTex content as required to generate your PDF.

  3. Begin an R session or navigate to an existing session and run the following code setwd(“/home/workspace/files”) system("xelatex filename.Rnw") replacing filename with the name of your new .rnw file.

A PDF report will be generated and added to the workspace files.

Once the compiler has been used, you may find it useful to change your working directory back to the default using this command: setwd(“/home/workspace”)

Updated on April 21, 2023

Was this article helpful?