RMarkdown, specify fonts in PDFs (restrictive environment)

I'm running R 4.1 on LSAF 5.4 by SAS Institute. LSAF is a locked down environment, there's no internet access, Latex is limited to the styles that can be installed using the TinyTex pre-built package (cf. Recommended LaTeX packages - #2 by cderv).

LSAF cannot deal with .Rmd files natively. A workaround is to specify the RMarkdown code in one long string in an R program. The string can be processed by

knit(text = Rmd_code,output = mdFile)

The mdFile created this way can be processed using pandoc.

pandoc(mdFile, format=c('html','docx','pdf'))

So far, so good. But I'd also like to change the font in the PDF output to sans-serif. I've tried to include a YAML header but it isn't recognized:

    latex_engine: xelatex
mainfont: Helvetica

I get no error messages but the output is also unaltered. Am I missing something?

What does work for the most part is to include some Latex in my RMarkdown code:


The \sffamily command should select sans-serif as the font but only works on the body of the text. \renewcommand{\rmdefault}{phv} works for headers only. {phv} selects the Helvetica font family (see Font typefaces - Overleaf, Online LaTeX Editor). Code junks still use the default font.

I'd prefer to be able to just specify a mainfont and have that used throughout. Can anyone help me out?

A second related question, how can I determine which fonts are available from the pre-built TinyTex package? (I don't really like Helvetica!)

I've found what was going wrong with my YAML header. I specified the "xelatex" engine in the YAML header but knitr::pandoc still used the default "pdflatex" engine. A solution was to include a pandoc option at the beginning of my markup code:

t: pdf
pdf-engine: xelatex

I can sort of change the font from the YAML header:

    pdf_engine: xelatex
mainfont: Roboto-Regular.otf
fontsize: 10pt

This works but italics, bold, are no longer used. I can use fontfamily: roboto but that is ignored. If I use mainfont: roboto, I get errors relating to mktextfm roboto. Apparently, TinyTex is attempting to install "roboto" but it's already installed. In any case, I'm working in a locked-down environment and can't access internet to install things.

What I need to know is how to relate the font names in the TinyTex installation to a valid specification for mainfont. There are many fonts in the subfolders of TinyTeX\texmf-dist\fonts, but how are they to be used in mainfont?

I have no ideal about TinyText but if you are working on your own machine you should be able to specify any font installed on your machine.

Both of these ran for me.

mainfont: Unspell
mainfont: LobsterTwo

I doubt that 'Unspell" is in the Latex font family.

But I'm not working on my own machine. I'm working in a restrictive environment that cannot access the internet. I have the TinyTeX software installed and that includes many fonts but I don't know how to specify them

Sorry, I did not understand what "restrictive environment.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.