Package 'tinytex' reference manual (2024)

Title:Helper Functions to Install and Maintain TeX Live, and CompileLaTeX Documents Description:Helper functions to install and maintain the 'LaTeX' distribution named 'TinyTeX' (<https://yihui.org/tinytex/>), a lightweight, cross-platform, portable, and easy-to-maintain version of 'TeX Live'. This package also contains helper functions to compile 'LaTeX' documents, and install missing 'LaTeX' packages automatically. Authors:Yihui Xie [aut, cre, cph] Package 'tinytex' reference manual (1), Posit Software, PBC [cph, fnd], Christophe Dervieux [ctb] Package 'tinytex' reference manual (2), Devon Ryan [ctb] Package 'tinytex' reference manual (3), Ethan Heinzen [ctb], Fernando Cagua [ctb] Maintainer:Yihui Xie <[emailprotected]> License:MIT + file LICENSE Version:0.51.1 Built:2024-06-29 02:36:33 UTC Source:https://github.com/rstudio/tinytex
Check if certain LaTeX packages are installed

Description

If a package has been installed in TinyTeX or TeX Live, the commandtlmgr info PKG should return PKG where PKG is thepackage name.

Usage

check_installed(pkgs)

Arguments

pkgs

A character vector of LaTeX package names.

Value

A logical vector indicating if packages specified in pkgs areinstalled.

Note

This function only works with LaTeX distributions based on TeX Live,such as TinyTeX.

Examples

tinytex::check_installed('framed')
Copy TinyTeX to another location and use it in another system

Description

The function copy_tinytex() copies the existing TinyTeX installationto another directory (e.g., a portable device like a USB stick). The functionuse_tinytex() runs tlmgr path add to add the copy of TinyTeXin an existing folder to the PATH variable of the current system, sothat you can use utilities such as tlmgr and pdflatex,etc.

Usage

copy_tinytex( from = tinytex_root(), to = select_dir("Select Destination Directory"), move = FALSE)use_tinytex(from = select_dir("Select TinyTeX Directory"))

Arguments

from

The root directory of the TinyTeX installation. Forcopy_tinytex(), the default value tinytex_root() should be areasonable guess if you installed TinyTeX via install_tinytex(). Foruse_tinytex(), if from is not provided, a dialog for choosingthe directory interactively will pop up.

to

The destination directory where you want to make a copy of TinyTeX.Like from in use_tinytex(), a dialog will pop up if tois not provided in copy_tinytex().

move

Whether to use the new copy and delete the original copy ofTinyTeX after copying it.

Note

You can only copy TinyTeX and use it in the same system, e.g., theWindows version of TinyTeX only works on Windows.

Install/Uninstall TinyTeX

Description

The function install_tinytex() downloads and installs TinyTeX, acustom LaTeX distribution based on TeX Live. The functionuninstall_tinytex() removes TinyTeX; reinstall_tinytex()reinstalls TinyTeX as well as previously installed LaTeX packages by default;tinytex_root() returns the root directory of TinyTeX if found.

Usage

install_tinytex( force = FALSE, dir = "auto", version = "daily", bundle = "TinyTeX-1", repository = "auto", extra_packages = if (is_tinytex()) tl_pkgs(), add_path = TRUE)uninstall_tinytex(force = FALSE, dir = tinytex_root())reinstall_tinytex(packages = TRUE, dir = tinytex_root(), ...)tinytex_root(error = TRUE)

Arguments

force

Whether to force to install or uninstall TinyTeX. Forinstall_tinytex(), force = FALSE will stop this function frominstalling TinyTeX if another LaTeX distribution is detected, or thedirectory specified via the dir argument exists.

dir

The directory to install (should not exist unless force =TRUE) or uninstall TinyTeX.

version

The version of TinyTeX, e.g., "2020.09" (see allavailable versions at https://github.com/rstudio/tinytex-releases, orvia xfun::github_releases('rstudio/tinytex-releases')). By default,it installs the latest daily build of TinyTeX. If version ='latest', it installs the latest monthly Github release of TinyTeX.

bundle

The bundle name of TinyTeX (which determines the collection ofLaTeX packages to install). Seehttps://github.com/rstudio/tinytex-releases#releases for all possiblebundles and their meanings.

repository

The CTAN repository to set. By default, it is therepository automatically chosen by https://mirror.ctan.org (which isusually the fastest one to your location). You can find availablerepositories at https://ctan.org/mirrors), e.g.,'http://mirrors.tuna.tsinghua.edu.cn/CTAN/', or'https://mirror.las.iastate.edu/tex-archive/'. In theory, thisargument should end with the path ‘/systems/texlive/tlnet’, and if itdoes not, the path will be automatically appended. You can get a full listof CTAN mirrors via tinytex:::ctan_mirrors().

extra_packages

A character vector of extra LaTeX packages to beinstalled. By default, a vector of all currently installed LaTeX packagesif an existing installation of TinyTeX is found. If you want a freshinstallation, you may use extra_packages = NULL.

add_path

Whether to run the command tlmgr path add to addthe bin path of TeX Live to the system environment variable PATH.

packages

Whether to reinstall all currently installed packages.

...

Other arguments to be passed to install_tinytex() (notethat the extra_packages argument will be set to tl_pkgs() ifpackages = TRUE).

error

Whether to signal an error if TinyTeX is not found.

Note

If you really want to disable the installation, you may set theenvironment variable TINYTEX_PREVENT_INSTALL to true. Theninstall_tinytex() will fail immediately. This can be useful tosysadmins who want to prevent the accidental installation of TinyTeX.

Installing TinyTeX requires perl (on Linux, perl-base is insufficient).

References

See the TinyTeX documentation (https://yihui.org/tinytex/)for the default installation directories on different platforms.

Check if the LaTeX installation is TinyTeX

Description

First find the root directory of the installation viatinytex_root(). Then check if the directory name is"tinytex" (case-insensitive). If not, further check if the first lineof the file ‘texmf-dist/web2c/fmtutil.cnf’ under the directory contains"TinyTeX" or ".TinyTeX". If the binary version of TinyTeX wasinstalled, ‘fmtutil.cnf’ should contain a line like ‘⁠Generated by*/TinyTeX/bin/x86_64-darwin/tlmgr on Thu Sep 17 07:13:28 2020⁠’.

Usage

is_tinytex()

Value

A logical value indicating if the LaTeX installation is TinyTeX.

Examples

tinytex::is_tinytex()
Compile a LaTeX document

Description

The function latexmk() emulates the system command latexmk(https://ctan.org/pkg/latexmk) to compile a LaTeX document. Thefunctions pdflatex(), xelatex(), and lualatex() arewrappers of latexmk(engine =, emulation = TRUE).

Usage

latexmk( file, engine = c("pdflatex", "xelatex", "lualatex", "latex", "tectonic"), bib_engine = c("bibtex", "biber"), engine_args = NULL, emulation = TRUE, min_times = 1, max_times = 10, install_packages = emulation && tlmgr_writable(), pdf_file = gsub("tex$", "pdf", file), clean = TRUE)pdflatex(...)xelatex(...)lualatex(...)

Arguments

file

A LaTeX file path.

engine

A LaTeX engine (can be set in the global optiontinytex.engine, e.g., options(tinytex.engine = 'xelatex')).

bib_engine

A bibliography engine (can be set in the global optiontinytex.bib_engine).

engine_args

Command-line arguments to be passed to engine (canbe set in the global option tinytex.engine_args, e.g.,options(tinytex.engine_args = '-shell-escape').

emulation

Whether to emulate the executable latexmk using R.Note that this is unused when engine == 'tectonic'.

min_times, max_times

The minimum and maximum number of times to rerunthe LaTeX engine when using emulation. You can set the global optionstinytex.compile.min_times or tinytex.compile.max_times, e.g.,options(tinytex.compile.max_times = 3).

install_packages

Whether to automatically install missing LaTeXpackages found by parse_packages() from the LaTeX log. Thisargument is only for the emulation mode and TeX Live. Its value can also beset via the global option tinytex.install_packages, e.g.,options(tinytex.install_packages = FALSE).

pdf_file

Path to the PDF output file. By default, it is under the samedirectory as the input file and also has the same base name. Whenengine == 'latex', this will be a DVI file.

clean

Whether to clean up auxiliary files after compilation (can beset in the global option tinytex.clean, which defaults toTRUE).

...

Arguments to be passed to latexmk() (other thanengine and emulation).

Details

The latexmk emulation works like this: run the LaTeX engine once(e.g., pdflatex), run makeindex to make the index ifnecessary (the ‘*.idx’ file exists), run the bibliography enginebibtex or biber to make the bibliography if necessary(the ‘*.aux’ or ‘*.bcf’ file exists), and finally run the LaTeXengine a number of times (the maximum is 10 by default) to resolve allcross-references.

By default, LaTeX warnings will be converted to R warnings. To suppress thesewarnings, set options(tinytex.latexmk.warning = FALSE).

If emulation = FALSE, you need to make sure the executablelatexmk is available in your system, otherwise latexmk()will fall back to emulation = TRUE. You can set the global optionoptions(tinytex.latexmk.emulation = FALSE) to always avoid emulation(i.e., always use the executable latexmk).

The default command to generate the index (if necessary) ismakeindex. To change it to a different command (e.g.,zhmakeindex), you may set the global optiontinytex.makeindex. To pass additional command-line arguments to thecommand, you may set the global option tinytex.makeindex.args (e.g.,options(tinytex.makeindex = 'zhmakeindex', tinytex.makeindex.args =c('-z', 'pinyin'))).

If you are using the LaTeX distribution TinyTeX, but its path is not in thePATH variable of your operating system, you may set the global optiontinytex.tlmgr.path to the full path of the executable tlmgr,so that latexmk() knows where to find executables likepdflatex. For example, if you are using Windows and your TinyTeX ison an external drive ‘Z:/’ under the folder ‘TinyTeX’, you may setoptions(tinytex.tlmgr.path = "Z:/TinyTeX/bin/windows/tlmgr.bat").Usually you should not need to set this option because TinyTeX can add itselfto the PATH variable during installation or viause_tinytex(). In case both methods fail, you can use thismanual approach.

Value

A character string of the path of the output file (i.e., the value ofthe pdf_file argument).

Parse the LaTeX log and install missing LaTeX packages if possible

Description

This is a helper function that combines parse_packages() andtlmgr_install().

Usage

parse_install(...)

Arguments

...

Arguments passed to parse_packages().

Find missing LaTeX packages from a LaTeX log file

Description

Analyze the error messages in a LaTeX log file to figure out the names ofmissing LaTeX packages that caused the errors. These packages can beinstalled via tlmgr_install(). Searching for missing packagesis based on tlmgr_search().

Usage

parse_packages( log, text = read_lines(log), files = detect_files(text), quiet = rep(FALSE, 3))

Arguments

log

Path to the LaTeX log file (typically named ‘*.log’).

text

A character vector of the error log (read from the file providedby the log argument by default).

files

A character vector of names of the missing files (automaticallydetected from the log by default).

quiet

Whether to suppress messages when finding packages. It should bea logical vector of length 3: the first element indicates whether tosuppress the message when no missing LaTeX packages could be detected fromthe log, the second element indicate whether to suppress the message whensearching for packages via tlmgr_search(), and the third elementindicates whether to warn if no packages could be found viatlmgr_search().

Value

A character vector of LaTeX package names.

Add/remove R's texmf tree to/from TeX Live

Description

R ships a custom texmf tree containing a few LaTeX style and class files,which are required when compiling R packages manuals (‘Rd.sty’) orSweave documents (‘Sweave.sty’). This tree can be found under thedirectory file.path(R.home('share'), 'texmf'). This function can beused to add/remove R's texmf tree to/from TeX Live viatlmgr_conf('auxtrees').

Usage

r_texmf(action = c("add", "remove"), ...)

Arguments

action

Add/remove R's texmf tree to/from TeX Live.

...

Arguments passed to tlmgr().

References

See the tlmgr manual for detailed information abouttlmgr conf auxtrees. Check outhttps://tex.stackexchange.com/q/77720/9128 if you don't know whattexmf means.

Examples

# running the code below will modify your texmf tree; please do not run# unless you know what it means# r_texmf('remove')# r_texmf('add')# all files under R's texmf treelist.files(file.path(R.home('share'), 'texmf'), recursive = TRUE, full.names = TRUE)
List the names of installed TeX Live packages

Description

Calls tlmgr info --list --data name to obtain the names of all(installed) TeX Live packages. Platform-specific strings in package names areremoved, e.g., "tex" is returned for the packagetex.x86_64-darwin.

Usage

tl_pkgs(only_installed = TRUE)

Arguments

only_installed

Whether to list installed packages only.

Value

A character vector of package names.

Sizes of LaTeX packages in TeX Live

Description

Use the command tlmgr info --list to obtain the sizes of LaTeXpackages.

Usage

tl_sizes(show_total = TRUE, pkgs = NULL, only_installed = TRUE, field = "size")

Arguments

show_total

Whether to show the total size.

pkgs

A character vector of package names (by default, all packages).

only_installed

Whether to list installed packages only.

field

A character vector of field names in the package information.See https://www.tug.org/texlive/doc/tlmgr.html#info for more info.

Value

By default, a data frame of three columns: package is thepackage names, size is the sizes in bytes, and size_h is thehuman-readable version of sizes. If different field names are provided inthe field argument, the returned data frame will contain thesecolumns.

Run the TeX Live Manager

Description

Execute the tlmgr command to search for LaTeX packages, installpackages, update packages, and so on.

Usage

tlmgr(args = character(), usermode = FALSE, ..., .quiet = FALSE)tlmgr_search(what, file = TRUE, all = FALSE, global = TRUE, word = FALSE, ...)tlmgr_install( pkgs = character(), usermode = FALSE, path = !usermode && os != "windows", ...)tlmgr_remove(pkgs = character(), usermode = FALSE)tlmgr_version(format = c("raw", "string", "list"))tlmgr_update( all = TRUE, self = TRUE, more_args = character(), usermode = FALSE, run_fmtutil = TRUE, delete_tlpdb = getOption("tinytex.delete_tlpdb", FALSE), ...)tlmgr_path(action = c("add", "remove"))tlmgr_conf(more_args = character(), ...)tlmgr_repo(url = NULL, ...)

Arguments

args

A character vector of arguments to be passed to the commandtlmgr.

usermode

(For expert users only) Whether to use TeX Live'suser mode. IfTRUE, you must have run tlmgr('init-usertree') once before.This option allows you to manage a user-level texmf tree, e.g., install aLaTeX package to your home directory instead of the system directory, towhich you do not have write permission. This option should not be needed onpersonal computers, and has some limitations, so please read thetlmgr manual very carefully before using it.

...

For tlmgr(), additional arguments to be passed tosystem2() (e.g., stdout = TRUE to capture stdout). Forother functions, arguments to be passed to tlmgr().

.quiet

Whether to hide the actual command before executing it.

what

A search keyword as a (Perl) regular expression.

file

Whether to treat what as a filename (pattern).

all

For tlmgr_search(), whether to search in everything,including package names, descriptions, and filenames. Fortlmgr_update(), whether to update all installed packages.

global

Whether to search the online TeX Live Database or locally.

word

Whether to restrict the search of package names and descriptionsto match only full words.

pkgs

A character vector of LaTeX package names.

path

Whether to run tlmgr_path('add') after installing packages(path = TRUE is a conservative default: it is only necessary to dothis after a binary package is installed, such as the metafontpackage, which contains the executable mf, but it does not hurteven if no binary packages were installed).

format

The data format to be returned: raw means the raw outputof the command tlmgr --version, string means a characterstring of the format ‘⁠TeX Live YEAR (TinyTeX) with tlmgr DATE⁠’, andlist means a list of the form list(texlive = YEAR, tlmgr =DATE, tinytex = TRUE/FALSE).

self

Whether to update the TeX Live Manager itself.

more_args

A character vector of more arguments to be passed to thecommand tlmgr update or tlmgr conf.

run_fmtutil

Whether to run fmtutil-sys --all to (re)createformat and hyphenation files after updating tlmgr.

delete_tlpdb

Whether to delete the ‘texlive.tlpdb.HASH’ files(where ⁠HASH⁠ is an MD5 hash) under the ‘tlpkg’ directory of theroot directory of TeX Live after updating.

action

On Unix, add/remove symlinks of binaries to/from the system'sPATH. On Windows, add/remove the path to the TeXLive binarydirectory to/from the system environment variable PATH.

url

The URL of the CTAN mirror. If NULL, show the currentrepository, otherwise set the repository. See the repositoryargument of install_tinytex() for examples.

Details

The tlmgr() function is a wrapper of system2('tlmgr'). Allother tlmgr_*() functions are based on tlmgr for specifictasks. For example, tlmgr_install() runs the command tlmgrinstall to install LaTeX packages, and tlmgr_update runs the commandtlmgr update, etc. Note that tlmgr_repo runs tlmgroptions repository to query or set the CTAN repository. Please consult thetlmgr manual for full details.

References

The tlmgr manual:https://www.tug.org/texlive/doc/tlmgr.html

Examples

# search for a package that contains titling.stytlmgr_search('titling.sty')# to match titling.sty exactly, add a slash before the keyword, e.g.tlmgr_search('/titling.sty')# use a regular expression if you want to be more precise, e.g.tlmgr_search('/titling\\.sty$')# list all installed LaTeX packagestlmgr(c('info', '--list', '--only-installed', '--data', 'name'))
Package 'tinytex' reference manual (2024)

References

Top Articles
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6058

Rating: 4.8 / 5 (78 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.