How to Write a Thesis in LaTeX with Mitra: Setup and Fixes
It’s the night before a supervisor meeting. You fix one typo in chapter 4, hit compile, wait a full minute, and get Undefined control sequence somewhere in a 9,000-line file. Most LaTeX thesis pain looks like this, and almost all of it comes from setup, not from LaTeX itself.
To write a thesis in LaTeX, start from your university’s official template if one exists, keep a short main file for the preamble and front matter, and put each chapter in its own file pulled in with \include. Manage references in a .bib file with biblatex and biber, keep figures in a figures/ folder as PDF or PNG, and compile with latexmk so citations and cross-references resolve in one command. Overleaf and a local TeX Live install both work. For a long thesis, a local setup in Mitra is the easiest of all: it compiles on your laptop with no time limit, writes your .bib from the papers you cite, and hands any failed build to a co-writer that fixes it.
Still deciding whether LaTeX is right for you at all? Read LaTeX vs Word for a thesis first. If you’ve decided, here’s the setup that holds up at 200 pages.
Find your university’s LaTeX thesis template
Thesis rules are fussy: margins, line spacing, the order of the declaration and abstract, exactly what the title page says. A good template handles all that so you can just write.
Look in three places, in this order. First, your graduate school or library website; search for “LaTeX template” next to “thesis formatting”. Second, the Overleaf template gallery, searching your university’s name. Be a little suspicious here, because many of those were uploaded by students years ago, so check the date against the current written rules. Third, and often best, ask the most recent graduate in your lab. Their template has already survived a format check.
If nothing exists, use the standard report class (chapters, one-sided by default) or book (two-sided by default), and set the rules yourself with geometry for margins and setspace for line spacing. CTAN has general thesis classes such as classicthesis too, but your university’s rules beat any design.
Whatever you start from, compile it untouched before you add a word. If the blank template fails, fix that first. Debugging a broken template with 40 pages of your own text inside it is miserable.
Project structure for a LaTeX thesis
A thesis is far too long for one file. This layout works for most people:
thesis/
main.tex
preamble.tex
references.bib
frontmatter/
titlepage.tex
abstract.tex
acknowledgements.tex
chapters/
ch1-introduction.tex
ch2-literature.tex
ch3-methods.tex
ch4-results.tex
ch5-discussion.tex
appendices/
appA-derivations.tex
figures/
ch3/
ch4/
And main.tex stays short:
\documentclass[12pt,a4paper,oneside]{report}
\input{preamble}
\includeonly{chapters/ch4-results} % comment out for full builds
\begin{document}
\input{frontmatter/titlepage}
\pagenumbering{roman}
\input{frontmatter/abstract}
\tableofcontents
\listoffigures
\listoftables
\cleardoublepage
\pagenumbering{arabic}
\include{chapters/ch1-introduction}
\include{chapters/ch2-literature}
\include{chapters/ch3-methods}
\include{chapters/ch4-results}
\include{chapters/ch5-discussion}
\printbibliography[heading=bibintoc]
\appendix
\include{appendices/appA-derivations}
\end{document}
Why \include rather than \input for chapters? Each included file gets its own .aux file, and \includeonly lets you compile just the chapter you’re working on while page numbers, figure numbers and cross-references to the other chapters stay correct. When the full build takes a minute, getting one chapter back in a few seconds changes how you work. Keep \input for small pieces like a long table, since \include always starts a new page.
A few habits that pay for themselves within a month:
- Prefix every label:
\label{fig:membrane-sem},\label{tab:ozone-doses},\label{sec:fouling-model}. Loadcleverefand write\cref{fig:membrane-sem}, and LaTeX adds the word “Figure” for you. - Load
hyperrefnear the end of the preamble, withcleverefafter it. A surprising share of package conflicts in theses come down to this order. - One sentence per line in the source. Diffs in git and Overleaf’s history become readable.
- Use
booktabsfor tables andsiunitxfor numbers with units.
Back the whole folder up somewhere off your laptop from day one; how to organize PhD files and backups covers a backup routine that would survive a stolen laptop.
Overleaf, local TeX Live or Mitra
It comes down to convenience, how long your builds take, and whether you can work on a train.
| Overleaf (free) | Local TeX Live + editor | Mitra | |
|---|---|---|---|
| Setup | None, runs in the browser | Install a few GB, pick an editor | Install Mitra; uses your TeX Live or installs TinyTeX on first compile |
| Offline work | Edit for 2 minutes, no compiling | Yes | Yes |
| Long builds | 10-second compile timeout | Limited only by your computer | Limited only by your computer |
| Failed builds | Read the log yourself, or use limited AI uses | Read the log yourself | Co-writer reads the log, fixes and recompiles |
| Bibliography | Manual .bib (reference manager links on paid plans) |
Manual .bib |
refs.bib written from the papers you cite |
| Version history | Built in | Use git | History panel with restore, plus git if you like |
Overleaf figures are from its plans, plan limits and offline pages, as of November 2026. Git and GitHub integration are paid features there too.
Going local means installing TeX Live (Windows and Linux), MacTeX (TeX Live packaged for the Mac) or MiKTeX (Windows), plus an editor: VS Code with the LaTeX Workshop extension, TeXstudio, or TeXShop on macOS. Put the project under git and push to a private repository, and you get history and an off-site backup in one go.
Going local in Mitra takes one step: in Write, choose New LaTeX project and pick the thesis template, or Open LaTeX folder / .zip for a project you already have, including an Overleaf download. You get a file tree, an outline, a Problems panel and a PDF preview with SyncTeX both ways (⌘-click a line to see it in the PDF). Since Mitra 0.3.5 you can also switch the view per project between Editor and PDF, Editor only, or PDF only. Moving an Overleaf project offline walks through the switch with a real failed build.
Want to set your thesis up this way? Download Mitra free and open your template in it.
Bibliography in a LaTeX thesis
For a new thesis, biblatex with the biber backend is the more flexible option:
\usepackage[backend=biber, style=authoryear, maxcitenames=2]{biblatex}
\addbibresource{references.bib}
Swap style=authoryear for numeric, ieee or apa (the last two need the biblatex-ieee and biblatex-apa packages, which TeX Live includes). Cite with \textcite{nguyen2021ceramic} to get “Nguyen et al. (2021)” in the sentence, and \parencite{...} for a parenthetical citation. If your template is built around a .bst file or a journal style you must match exactly, use natbib with BibTeX instead.
The .bib file is where theses quietly rot. Duplicate keys. Missing DOIs. “DFT” printed as “dft” because the title lost its capitals. Protect capitals with braces, title = {{DFT} study of ...}, and export entries from a reference manager instead of copying them from Google Scholar by hand.
Mitra takes the job off your hands. \cite autocompletes from your library (Insert citation is ⌘⇧C), and Mitra generates refs.bib from the sources you cite, with stable keys such as smith2023lean, while keeping any entries you wrote yourself. Cite online finds a paper you don’t have yet, adds it to your library and cites it in one go. How to manage a BibTeX library covers key naming, cleaning, and keeping one .bib in sync with Zotero.
Figures in a LaTeX thesis
\begin{figure}[tbp]
\centering
\includegraphics[width=0.8\linewidth]{figures/ch3/flux-decline.pdf}
\caption{Normalised flux over 30 days at three ozone doses.}
\label{fig:flux-decline}
\end{figure}
Export plots from Python, R or MATLAB as PDF, so they stay sharp at any zoom and the text stays searchable; use PNG for photos and micrographs. Size figures with \linewidth rather than centimetres, so they adjust if the margins change. Use subcaption for panels (a), (b), (c), and add \graphicspath{{figures/}} to the preamble if you like shorter paths.
Then let the figures float. [tbp] lets LaTeX place them at the top, the bottom or on a float page. Forcing [h!] everywhere is exactly how you get those half-empty pages your examiner will notice. For making the figures themselves look good, see how to make figures for research papers.
Common LaTeX compile errors and how to fix them
Read the first error in the log, not the last. The later ones are usually fallout.
| Error | Usual cause | Fix |
|---|---|---|
Undefined control sequence |
Typo in a command, or a package not loaded | Check the line number; add the \usepackage |
Missing $ inserted |
_ or ^ outside math mode |
Escape as \_, or wrap in $...$ |
File 'x.pdf' not found |
Wrong path or case of the file name | Match case exactly; Linux and Overleaf are case-sensitive |
| Citations show as [?] or bold keys | Bibliography not processed | Run biber (or BibTeX), then LaTeX again; latexmk does this |
| References show as ?? | Needs another pass | Compile again |
Too many unprocessed floats |
Many figures with no text between | Add \clearpage, or loosen placement options |
Overfull \hbox warning |
A line sticks into the margin | Rephrase, or allow a break in long URLs with the xurl package |
In Mitra you rarely need this table. A failed compile goes straight to the co-writer, which reads the log, fixes the file, switches the engine (pdfLaTeX, XeLaTeX or LuaLaTeX) if the log asks, installs a missing package after you click Approve, and compiles again. Each change arrives as a diff with Undo. Our LaTeX error fix post walks through a real run: eight errors traced back to one missing package.
When nothing makes sense, delete the auxiliary files (.aux, .bbl, .bcf, .toc) and recompile. On Overleaf, that’s “Clear cached files” under the logs. And if a baffling error shows up right after a big paste, comment out half the new text and compile, then a quarter, until you’ve cornered the line. It’s dull, but it always works.
LaTeX only handles how the thesis looks. For what goes in each chapter, and in what order to write them, the main guide on how to write a PhD thesis covers planning, drafting and working with your supervisor.
Write the chapters themselves with Mitra
Once the setup holds, the hard part is the writing. Mitra’s LaTeX editor has the same co-writer as its Word-style editor and Microsoft Word:
- It drafts only from your library. Ask for “a related-work paragraph from these five sources” and every
\citepoints to a paper you hold. Edits arrive as suggestions you accept or reject, in your.texsource. - Next sentence as you write. Rest the cursor in body text and Mitra suggests the next sentence in grey, with checked citations. Tab takes it, Esc dismisses it, and a switch on the LaTeX toolbar turns it off.
- Whole-thesis passes. “Proofread every chapter” is worked through section by section, and @-mentions point the co-writer at a section, a paper or a note.
- Formatting on request. “Remove the italics from every heading” becomes edits to the
.texsource, as one undoable step. - History. Every change, yours or the AI’s with its model, is logged, and any version can be restored.
- A citation check. It flags citations to papers you never opened and sentences their source doesn’t support, before your examiner finds them.
Your papers stay on your computer. Mitra finds the PDFs you already have, imports a Zotero, EndNote, Mendeley, BibTeX or RIS library, and answers questions about a paper or a whole folder with a citation chip that opens the exact page, which is handy when you’re checking a number before it goes into the results chapter.
The co-writer runs on the AI you already have: ChatGPT Plus or Pro, Claude Code, Codex, Cursor, or a model running offline on your computer (in beta). Without any AI, the editor, compiling and SyncTeX still work. How Mitra compares with other AI tools for a PhD thesis covers the rest of the workflow.
Set up your thesis once and stop fighting the build. Download Mitra free for Mac, Windows or Linux.
Questions people ask
Where can I find a LaTeX thesis template for my university?
Start with your graduate school website, then search the Overleaf template gallery for your university name, then ask your department or lab, since many groups pass a template down. If nothing official exists, use the standard report or book class and set margins, spacing and front matter to match the written formatting rules.
What is the difference between \include and \input in LaTeX?
\input pastes a file in exactly where it appears. \include starts a new page, writes a separate .aux file for that chapter, and works with \includeonly, which lets you compile just the chapter you are editing while keeping page and figure numbers from the others. Use \include for chapters and \input for smaller pieces like tables.
Should I write my thesis on Overleaf or locally?
Overleaf is easy to start with, but its free plan has a 10-second compile timeout and only 2 minutes of offline editing (as of November 2026). A thesis is better written locally. Mitra opens an Overleaf .zip, compiles it with TeX Live on your computer with no time limit, works offline, and its co-writer fixes failed builds.
Should I use BibTeX or biblatex for a thesis?
For a new thesis, biblatex with biber is usually the more flexible choice: it handles Unicode, many citation styles and per-chapter bibliographies. Use natbib and BibTeX if your template or a journal requires a .bst style. Both read the same .bib file, and Mitra writes that file for you from the papers you cite.
Can an AI fix my LaTeX errors?
In Mitra, yes. When a compile fails, the log goes to the co-writer, which reads it, fixes the file, the engine or a missing package (installing only after you approve) and compiles again. Every change shows as a diff you can undo.