Portable minimal distribution

Summarising the various comments as an answer, the bottom line is that a target of 5 MB is unrealistic. For example, the Windows XeTeX binary on my system is 2.7 MB, while as Ulrike says

The MiKTeX package with XeTeX binaries has a size of 14MB.

(On my Unix system, the XeTeX binary is 17.8 MB). You need of course in addition to XeTeX the xdvipdfm system (I'm not sure exactly how that is packaged up on different systems.)

As an absolute minimum, you need in addition to the XeTeX binary some structure for finding files (kpsewhich or MiKTeX's equivalent), basic fonts (Computer Modern and Latin Modern), then a basic LaTeX (the base/required/tools, plus whatever you feel is 'minimal'). That is all going to add up.

Looking at the existing small distributions, BasicTeX (Mac-only) is 92 MB and MiKTeX basic is 157 MB. You could try to build something like one of these yourself, but the most obvious way to proceed is

Get either MiKTeX portable or TeX Live portable, install it and then remove the things you don't need (in MiKTeX you can use the package manager to remove packages).

(again from Ulrike's comment).

To get the size down, you should also look to remove all of the doc tree, as this tends to be quite big. Of course, you'll be left with no documentation, but it will be smaller.


As a 13 years long LaTeX user, I managed to have my own minimal distribution extracted from TeXlive, in the way Joseph Wright described in his answer, and installed it on my personal directory on a server at work (on windows platform) so that it runs in any computer I'm connected with.

It consists of pdflatex + bibtex8 + makeindex + scite + sumatrapdf and a few standard packages (base + tools + graphics + geometry + titlesec + pgf + hyperref and dependencies).

I also tweaked fonttext.cfg, fontmath.cfg and preload.cfg to have Latin Modern as default fonts so that I have no cm and ec fonts installed... All this stands in 30MB (~1300 files) so I can confirm that a standalone pdflatex system (without the editor, pdfviewer and extra package like pgf) stands in no more than 20MB. Surely xelatex and lualatex need more space because of bigger binaries.


I have also been wondering why this TeXLive thing is taking up so much space and what all of these files and directories are all about and which ones the program actually uses on my behalf.

So I just copied pdflatex.exe out of there and added files until I could compile a simple article with some math and different fonts in it:

%%hello.tex
\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}

\title{How to Structure a LaTeX Document}
\author{Someone}
\date{\today}
\maketitle

\begin{abstract}
Your abstract goes here...
...
\end{abstract}


\section{Structure}
This section's content...

\subsection{Top Matter}
This subsection's content...

\subsubsection{Article Information}
This subsubsection's content...

\emph{hello} hello $x^2, \mathbb R, \mathcal C, \mathfrak F, \int_0^1 \sin(x) \mathrm d x$

\end{document}

Turns out you just need, in addition to pdflatex.exe:

  • some .dlls
  • the .sty files for packages you use and dependencies of the packages you use
  • Some U*.fd files to fix errors of the form LaTeX Font Warning: Font shape `U/*/m/n' undefined
  • texmf.cnf
  • <the documentclass>.cls
  • size10.clo (whatever this is)
  • .tfm (font metric) and .pfb files for all the fonts you use (or plan to use, or a few more)
  • pdftex.map which is a concatenation of all .map files for the fonts you use.

These files don't have to be in the standard latex folder structure. They can just be in the same folder as the pdflatex executable.

I have uploaded a ~10MB (unpacked) folder containing all files necessary to run pdflatex hello.tex in it and have it produce hello.pdf:

https://drive.google.com/open?id=0Bw8QfIyUuQqvTHk3RWxPSVE4M3c (it contains pdflatex.exe (from TeXLive2016), so Google Drive might tell you "contains executable code, download at your own risk")

If you try to compile something more complicated, you should be able to copy over the necessary files from your full TeXLive installation to make this minimum installation capable of compiling it too.


That said, if you are on-the-go or in a low-resource environment but have an internet connection, you might prefer to use things like

  • http://latex.informatik.uni-halle.de/latex-online/latex.php
  • https://www.codecogs.com/latex/eqneditor.php
  • https://www.overleaf.com/
  • https://papeeria.com/
  • https://www.mathjax.org/

which might provide an API to compile some LaTeX for you.