rstudio / tinytex

A lightweight, cross-platform, portable, and easy-to-maintain LaTeX distribution based on TeX Live

Home Page:https://yihui.org/tinytex/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install package manually

vsheg opened this issue · comments

Hello, I've just spent a lot of time on how to install my custom package globally for tinytex (CRAN's v0.40), hope this short instruction will be indexed by Google, and whoever needs it will find it.

I'm using mac.

  1. Create texmf folder
mkdir ~/Library/texmf
  1. Add necessary directories and copy files into there, e.g.:
mkdir -p ~/Library/texmf/tex/latex/
cp my_latex_package.sty ~/Library/texmf/tex/latex/
  1. Add to TeX's "search PATH"
tlmgr conf auxtrees add ~/Library/texmf

Now, this package will be available for \usepackage{my_latex_package} globally

P.S. I guess tinytex docs should contain this, or this should be done during the tinytex::install_tinytex()

Oh nice. I just learnt something ! @yihui I let you see what is the best way to support this better. Function to help do that ? Or just adding to the doc and / or tinytex FAQ ?

I'm not sure what we should do here. I guess this won't be an FAQ since I don't think it would be frequently asked. In most cases, I think users will just install packages from CTAN. If a custom .sty is needed, users can either put it under a texmf tree, or simply put it under the same directory as the .tex file (no need to "install" it). The former is useful only when this .sty is needed for multiple .tex documents under different directories in the system.

One caveat is that when you upgrade or reinstall TinyTeX, you will have to repeat the 3rd step above.

I think this Github issue should be good enough for now for people who want to know how to add a custom package to TeX Live. I'm in the same hope as @vsheg that this will be indexed by search engines, and users will be able to find it in future. Thanks for sharing!

BTW, @cderv tinytex::r_texmf is an example of adding a texmf tree so that TeX Live will be aware of it.

The default tinytex's auxtree (see: ~/Library/TinyTeX/texmf.cnf)

TEXMFAUXTREES = /opt/homebrew/Cellar/r/4.2.0/lib/R/share/texmf

is unobvious, it depends on R's version and a package manager. Installing custom or patched versions of packages in tinytex's guts

$ mktexlsr
mktexlsr: Updating ~/Library/TinyTeX/texmf-config/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-dist/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-local/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-var/ls-R...

is not something called "a good practice" and changes do not preserve between LaTeX distributions and tinytex installations.


@yihui I still think that tinytex should search packages in ~/Library/texmf by default, because it

  1. is expected by users (especially for those who came from TeX Live);
  2. does not require any complex or tricky support;
  3. allows using "package installation" manuals from the internet;
  4. is transferable between different LaTeX distributions, it should just work.

And manual editing of the auxtree is not something everyone should know.


The case of using own custom packages is quite common, I think. Many create a standard preamble for all their documents (my case) and connect it as a package \usepackage{my_preamble}, some packages (e.g. mol2chemfig) need Python or Lua modules to work, so they must be installed manually or by using some installation script that may know nothing about tinytex's texmf tree.

The default tinytex's auxtree (see: ~/Library/TinyTeX/texmf.cnf)

TEXMFAUXTREES = /opt/homebrew/Cellar/r/4.2.0/lib/R/share/texmf

is unobvious, it depends on R's version and a package manager. Installing custom or patched versions of packages in tinytex's guts

$ mktexlsr
mktexlsr: Updating ~/Library/TinyTeX/texmf-config/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-dist/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-local/ls-R...
mktexlsr: Updating ~/Library/TinyTeX/texmf-var/ls-R...

is not something called "a good practice" and changes do not preserve between LaTeX distributions and tinytex installations.

I agree with the disadvantages you mentioned. However, my intention is not that R's texmf directory should be the default auxtree, but is one of the auxtrees that TeX Live should be aware of (for R users). Users can add as many auxtrees as they want.

@yihui I still think that tinytex should search packages in ~/Library/texmf by default

I agree. Perhaps I should not define TEXMFHOME here:

echo 'TEXMFHOME ./texmf-home' >> $PRNAME

echo TEXMFHOME ./TinyTeX/texmf-home>> tinytex.profile

and just let TeX Live search its default TEXMFHOME directory, which I believe is something like ~/Library/texmf on macOS, and ~/texmf on Linux, etc., but I can't find the canonical documentation for the default value of TEXMFHOME now.

but I can't find the canonical documentation for the default value of TEXMFHOME now.

This ? https://tug.org/texlive/doc/texlive-en/texlive-en.html#x1-250003.2.3

TEXMFHOME is the recommended location for personal macro files or packages. The default value is ~/texmf (~/Library/texmf on Macs). In contrast to TEXDIR, here a ~ is preserved in the newly-written configuration files, since it usefully refers to the home directory of the user running TeX. It expands to $HOME on Unix and %USERPROFILE% on Windows. Special redundant note: TEXMFHOME, like all trees, must be organized according to the TDS, or files may not be found.

Thanks! I just removed TinyTeX's TEXMFHOME configuration, so that it will just use TeX Live's default setting. This will be reflected in the next build of TinyTeX (which will hopefully be ready in about an hour). Or you can delete TEXMFHOME manually:

tlmgr conf texmf --delete TEXMFHOME

Then verify by

kpsewhich -var-value TEXMFHOME

Oddly, it returns ~/texmf instead of ~/Library/texmf on my macOS. I'm not sure if this is a bug, but you can definitely change it:

tlmgr conf texmf TEXMFHOME ~/Library/texmf