DEV Community


Install latex with Tinytex

recording bits and pieces of the small problems I have encountered
Updated on ・4 min read


Tinytex is a relative new Latex distribution by Yihui Xie from the R community. The distribution is tiny, less than 100mb, which is a great alternative to TexLive and MikTex for basic users. I this post, I will show how to install Tinytex as a standalone package independent of R for more general latex workflow.

To install Tinytex on a Linux distribution, run the following command to download and install Tinytex, as indicated in the website:

wget -qO- "" | sh
Enter fullscreen mode Exit fullscreen mode

This will install the application in $HOME/.Tinytex and add a bunch of symlinks in $HOME/bin:

random ❱ ls ~/bin
afm2tfm      extractbb     kpsereadlink     mf-nowin  pktogf          updmap
bibtex       fmtutil       kpsestat         mft       pktype          updmap-sys
dvilualatex  fmtutil-sys   kpsewhich        mktexfmt  rungs           updmap-user
dviluatex    fmtutil-user  latex            mktexlsr  simpdftex       xdvipdfmx
dvipdfm      gftodvi       latexmk          mktexmf   teckit_compile  xelatex
dvipdfmx     gftopk        luahbtex         mktexpk   tex             xetex
dvipdft      gftype        lualatex         mktextfm  texhash
dvips        inimf         luaotfload-tool  pdfetex   texlua
ebb          initex        luatex           pdflatex  texluac
etex         kpseaccess    mf               pdftex    tlmgr
Enter fullscreen mode Exit fullscreen mode

Then, you can run any of the above programs in the terminal to see if they are in the PATH. If not, you need to add $HOME/bin to the PATH. You can add the following line:

export PATH="$PATH:$HOME/bin"
Enter fullscreen mode Exit fullscreen mode

to one of your config file:~/.profile, ~/.bashrc, etc. This will append bin folder to your PATH permanently.

Evaluate the file to update the change:

~ ❱ source ~/.profile
Enter fullscreen mode Exit fullscreen mode

Now you should be able to run the programs in bin:

~ ❱ pdflatex
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
Enter fullscreen mode Exit fullscreen mode

Test installation with pdflatex

Now you can compile pdf from tex files with pdflatex.

You can find a sample tex file from the $HOME/.Tinytex folder, the original sample by Leslie Lamport that comes in every tex distribution.

.TinyTeX ❱ find . -name "sample2e.tex"
Enter fullscreen mode Exit fullscreen mode

Copy this file to desired folder, I use folder named random:

.TinyTeX ❱ cp $(!!) ../
cp $(find . -name "sample2e.tex") ../random
Enter fullscreen mode Exit fullscreen mode

Navigate to the folder that contains the tex file we just copied, and run pdflatex, you will enter into an interactive mode that ask for filename to convert.

Enter the filename: sample2e.tex, the program will compile and output a pdf file from the tex.

random ❱ pdflatex
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2021) (preloaded format=pdflatex)
 restricted \write18 enabled.
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-05-07>
Document Class: article 2020/04/10 v1.4m Standard LaTeX document class
No file sample2e.aux.
(/home/zach/.TinyTeX/texmf-dist/tex/latex/base/omscmr.fd) [1{/home/zach/.TinyTe
X/texmf-var/fonts/map/pdftex/updmap/}] [2] [3] (./sample2e.aux) ) </h
Output written on sample2e.pdf (3 pages, 137025 bytes).
Transcript written on sample2e.log.
random ❱ ls
sample2e.aux  sample2e.log  sample2e.pdf  sample2e.tex
Enter fullscreen mode Exit fullscreen mode

Now you should be use any editor with tex integration to run and compile latex!

Integrate Tinytex with R

After set up the distribution. You can also let R use the package. To do so, you need to install tinytex package in R. The package should automatically recognize your tinytex distribution. To verify, use

#is tiny tex installed
#verify its directory
Enter fullscreen mode Exit fullscreen mode

as described here. Note that tinytex package does not install the latex distribution automatically. You need to run tinytex::install_tinytex() if you need a fresh installation.

Further steps:

  1. Link tinytex to your existing package manager so that it will recognize the various packages that is included in tinytex instead of download new ones if your future packages depend on it

Discussion (0)