R/fontspec.R

Defines functions fontspecPackage fontspecPreamble

Documented in fontspecPackage

fontspecPreamble <- function(font=NULL) {
    preamble <- "\\usepackage{fontspec}"
    if (!is.null(font)) {
        if (dirname(font) == ".") {
            setfont <- paste0("\\setmainfont{", font, "}")
        } else {
            setfont <- paste0("\\setmainfont{", basename(font), "}",
                              ## Must add trailing slash
                              "[Path=", paste0(dirname(font), "/"), "]")
        }
        preamble <- c(preamble, setfont)
    }
    preamble
}

fontspecPackage <- function(font=NULL, name=font) {
    if (is.null(font)) {
        LaTeXpackage(name="fontspec", preamble=fontspecPreamble())
    } else {
        LaTeXpackage(name=name, preamble=fontspecPreamble(font))
    }
}

Try the xdvir package in your browser

Any scripts or data that you put into this service are public.

xdvir documentation built on Aug. 8, 2025, 7:12 p.m.