How to Write and Compile LaTeX on Android, Offline
By Laxmi SolutionsUpdated 4 min read
You can write a LaTeX document on an Android phone and compile it to a real PDF without a laptop, a browser or a network connection. This guide shows how, using Lemma, which runs a full XeTeX engine on the device, and covers the few things that work differently from a desktop TeX installation.
Why compile on the phone
Online LaTeX editors work in a mobile browser, but they need a steady connection for every compile, and their desktop layouts are cramped on a small screen. A compiler on the device removes both problems: a compile takes seconds whether you are on a train, a plane or a campus with patchy Wi-Fi, and your source never leaves the phone.
Lemma uses Tectonic, a modern, self-contained TeX engine built on XeTeX. It produces the same PDF a desktop XeLaTeX would, with Unicode input and system or custom fonts.
What you need
- An Android phone, tablet or Chromebook running Android 8.0 or newer with a 64-bit processor.
- Lemma from Google Play. It is free to write and compile; there is no sign-up.
- A connection the first time only: the offline compiler (about 13 MB) downloads once from Google Play, and each TeX package downloads the first time a document uses it.
Write and compile your first document
- Open Lemma and tap the + button, then choose a blank document or one of the templates.
- Type your document. The row above the keyboard has backslash, braces,
$,^,_and&, so you rarely switch keyboard pages. - Tap Compile. The PDF appears next to the source: below it on a phone, beside it on a tablet or in landscape.
- Tap any spot in the PDF to jump to the line that produced it. Share or export the PDF from the menu.
A small document to try:
\documentclass{article}
\usepackage{amsmath}
\title{Notes on the Quadratic Formula}
\author{Your Name}
\begin{document}
\maketitle
The solutions of $ax^2 + bx + c = 0$ with $a \neq 0$ are
\begin{equation}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\end{equation}
\end{document}In Settings → Compiler you can compile on every save or only when you tap Compile. Compiling on save gives you a near-live preview while you write.
How packages download, then work offline
A desktop TeX Live installation ships several gigabytes of packages up front. Tectonic instead fetches only the files a document actually uses, from a fixed, versioned bundle, the first time they are needed. During that first compile Lemma shows which package is downloading and how many files have arrived, for example "Downloading packages · amsmath.sty (12)".
Every file is cached on the device. The next compile of that document, or of any document using the same packages, runs entirely offline. Because the bundle is versioned, a document compiles the same way next month as it does today.
Typing LaTeX on a touch keyboard
- Autocomplete suggests commands and environments as you type, so you rarely spell out a long command name.
- The Insert screen lists hundreds of math symbols and common packages, so you can tap a symbol instead of remembering its name. Our LaTeX math symbols cheat sheet has the most used ones.
- Add your own quick-insert snippets next to the symbol row for commands you type often.
- Snap math (Lemma Pro) turns a photo or a handwritten formula into LaTeX; see handwriting to LaTeX.
- Find and replace, an outline of your sections, line numbers and a minimap help in long files.
Fixing compile errors
When a compile fails, Lemma lists each error and warning with its line number. Tap one to jump to that line. The most common causes on a phone are the same as anywhere: a missing closing brace, a $ left open, or an environment that is begun but never ended.
What works differently from a desktop
Lemma compiles with XeLaTeX, not pdfLaTeX. Most documents compile unchanged, and a few desktop tools don't exist on Android:
- Bibliographies: BibTeX works. Biber does not, so for biblatex use
backend=bibtex. Lemma offers this fix when it sees Biber in a document. - Indexes: makeindex is not available, so
\printindexstays empty. - Shell escape is off, for security and because the programs it would run (for example Pygments for minted) aren't on the phone. Use the listings package for code.
- Fonts: XeLaTeX loads fonts by name with fontspec. Add your own .ttf or .otf files in Settings → Fonts and use them in any project with
\setmainfont{Font Name}.
Bringing a project from Overleaf? See how to open Overleaf projects on Android.
Keep your work safe
Projects live in the app's private storage, or as ordinary files in a folder you choose, so they survive a reinstall. For history and backups, connect a project to a Git repository (GitHub, GitLab or any host) or to Google Drive from Share & sync. Nothing is uploaded unless you set that up.