I am looking for a Python-style virtualenv or venv to create a virtual environment where I can install LaTeX packages such that the packages are available to my current LaTeX project only (but not available system-wide).

I am expecting something like the following:

  • Create a virtual-environment path, say, ./venv.
  • Set some environment variables or modify tlmgr install commands such that new packages are installed into ./venv with the proper directory structure.
  • Set some environment variables or modify pdflatex commands such that the new documents I compile use packages from the ./venv directory along with the packages in the system-wide paths that came with Tex Live distribution.
  • I do not however want to hardcode any ./venv paths in the LaTeX documents (the .tex files). The source code in the .tex file should be agnostic of whether it is being compiled with a virtual environment or not.
  • 1
    @HenriMenke I believe we can create multiple user-trees like this: tlmgr init-usertree --usertree ~/tex1; tlmgr init-usertree --usertree ~/tex2. Aug 29, 2018 at 3:56

1 Answer 1


You can use TeX Live's user mode for that purpose. As you have already mentioned in the comments, you can create a new user tree (allowing multiple trees) using

$ tlmgr init-usertree --usertree ~/test-tree

To install a package in this tree you have to pass the user tree and the option --usermode

$ tlmgr install --usertree ~/test-tree --usermode <package>

To run LaTeX you have to give it a hint where to look for user packages, by setting the TEXMFHOME variable. You can either do this separately for each run

$ TEXMFHOME=~/test-tree pdflatex test.tex

or globally for the current shell by exporting the name (use unset to exit the “virtual environment”)

$ export TEXMFHOME=~/test-tree
$ pdflatex test.tex
  • 2
    A nice thing about the TEXMFHOME variable is that it works with tlmgr too. So we can do something like this too: export TEXMFHOME=~/tree; tlmgr init-usertree; tlmgr --usermode install csquotes; pdflatex foo.tex; unset TEXMFHOME Aug 29, 2018 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.