Custom font in RStudio Server?


#1

I’d love to play with the new ligature support in RStudio Server, but I don’t see an option to change editor fonts at all in 1.1.383. Is there a hidden setting for font changes?


#2

I don’t believe that the server version of RStudio allows for native font customization. There’s an old support question about that:

And I haven’t found any indication that it has changed since then. You may be able to do something with custom CSS, but I haven’t dug into that at all.


#3

Re: "You may be able to do something with custom CSS" -- I've come up with the following CSS:

pre, .ace_text-layer, .xterm-rows, tr[data-entry-id], td[__gwt_cell] {
  font-family: "Source Code Pro", monospace !important;
}

Obviously, substitute the font you want for Source Code Pro. It's not very clean, unfortunately, there's no single way to identify all of the places where monospace font is used. This is the best I've come up with so far, it affects the code editor, the console, the terminal, the code samples in the Help tab, and the Environment and History tabs.

The easiest way to inject this CSS into the RStudio page is using an addon like Stylish. If you're already using a userscript manager like Greasemonkey and would rather not install another addon, you can inject the CSS with a usercript along the following lines:

// ==UserScript==
// @version         ∞
// @name            RStudioMonoFont
// @namespace       https://github.com/dlukes
// @author          dlukes
// @description     Change RStudio Server monospace font.
// @match           *://YOUR.RSTUDIO-SERVER.URL
// @run-at          document-end
// ==/UserScript==
(function () {
  var style = `
pre, .ace_text-layer, .xterm-rows, tr[data-entry-id], td[__gwt_cell] {
  font-family: "Source Code Pro", monospace !important;
}
  `;
  var styleNode = document.createElement("style");
  styleNode.appendChild(document.createTextNode(style));
  document.body.appendChild(styleNode);
})();