input TeX package name and optional package functions to create usepackage call

build_usepackage(pkg, options = NULL, uselibrary = NULL, chk.inst = FALSE)

Arguments

pkg

character, name of TeX package

options

character, name(s) of options to use in the package

uselibrary

character, part of document preamble to specify a uselibrary call related to package

chk.inst

logical, invokes a check to see if pkg is currently installed on system (default FALSE)

Value

character

Details

if options and uselibrary are NULL (default) then only the call for the package is returned. See the TeX wikibook for more information https://en.wikibooks.org/wiki/LaTeX/Document_Structure#Packages on the usepackage command. If chk.inst finds that the package is not installed on system function returns NULL.

Examples

build_usepackage(pkg = 'xcolor')
#> [1] "\\usepackage{xcolor}"
build_usepackage(pkg = 'xcolor',options = 'usenames')
#> [1] "\\usepackage[usenames]{xcolor}"

#build many at once using mapply

geom.opts=c('paperwidth=35cm','paperheight=35cm','left=2.5cm','top=2.5cm')
use.opts="\\usetikzlibrary{mindmap,backgrounds}"

unlist(mapply(build_usepackage,
pkg =        list('times','geometry','tikz'),
options=     list(NULL   ,geom.opts ,NULL),
uselibrary = list(NULL   ,NULL      ,use.opts)
))
#> [1] "\\usepackage{times}"                                                          
#> [2] "\\usepackage[paperwidth=35cm,paperheight=35cm,left=2.5cm,top=2.5cm]{geometry}"
#> [3] "\\usepackage{tikz}"                                                           
#> [4] "\\usetikzlibrary{mindmap,backgrounds}"