Skip to content

About

Desktop LaTeX editor and PDF ⇄ LaTeX ⇄ Word converter that rebuilds math formulas from PDFs. Offline, PyQt5.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Latexinter

English · Español

tests license: AGPL v3

A desktop LaTeX environment that also converts between PDF, LaTeX and Word, including the hard part: recovering the math formulas from a PDF. Everything runs on your machine. There's no browser and nothing gets uploaded.

The interface is in Spanish, and the document templates come with a Spanish preamble.

Editor: source, outline, problems panel and the synced PDF

Features

Editor

  • Command and environment autocompletion, plus snippets (\figura, \tabla, \ecuacion, \align, \matriz…). \begin{…} inserts its own \end{…}.
  • Syntax highlighting that tells commands, environments, math and comments apart, and marks multi-line formulas from start to end.
  • Find and replace with regular expressions.
  • Templates: article, report, Beamer slides, thesis, letter, CV and exam.
  • Files are saved the way they were: an old Latin-1 or Windows-1252 .tex keeps its encoding and line endings. Saving is atomic, so a file is never left half-written.
  • Crash recovery: unsaved changes are backed up every few seconds. If Latexinter closes unexpectedly, it offers to restore them on the next start.

Compiling

  • F5 compiles. Compile as you type recompiles two seconds after you stop typing. Shift+F5 stops a compile and kills pdflatex, so it isn't left running in the background.
  • pdflatex, xelatex or lualatex. Runs bibtex/biber and extra passes when needed.
  • Errors from the .log (plus chktex style warnings) show up in a panel. Click one to jump to the line.
  • SyncTeX both ways: F7 jumps from the cursor to the PDF, and double-clicking the PDF jumps back to the source.
  • The PDF keeps its scroll position between compiles.

Converter

From To How
PDF Word Directly, in one step: the formulas rebuilt from the PDF become equations you can edit in Word
PDF LaTeX pymupdf4llm extracts the structure, then Latexinter rebuilds the formulas from the page layout
LaTeX PDF pdflatex, with the passes needed for the table of contents and references
LaTeX Word pandoc, with equations you can edit in Word and a clean A4 template
Word LaTeX pandoc, including images and OMML equations
Word PDF Word or LibreOffice if you have them, otherwise through LaTeX
  • Batches: drop several documents and convert them one after another. If one fails, the rest carry on.
  • Compare: the original and the result side by side, scrolling together. Word results are shown too, if Word or LibreOffice is installed.
  • Choose pages by typing a range or picking them from thumbnails.
  • Conversions can be cancelled, and they never overwrite a file you already have.

Converter: a PDF turned into Word, next to the original

Appearance: light and dark themes, or follow the system (Ver → Apariencia).

Recovering formulas from a PDF

A PDF doesn't store formulas, only glyphs at positions. A plain text extractor returns x2 for both "x times 2" and "x squared". Latexinter reads the geometry and the fonts to work out what was lost:

  • Superscripts and subscripts (pdfmath.py) compare each fragment's font size and baseline with the rest of the line and nest them by size, so e⁻ˣ² becomes e^{-x^{2}}.
  • Big operators: TeX's math fonts store the integral sign in the slot of Z and the summation sign in the slot of X. Latexinter translates them back. Inside a paragraph, the extractor usually drops the sign altogether and scatters its limits, so Latexinter rebuilds the whole formula around it from the glyphs on its line.
  • Display equations: pymupdf4llm's layout model marks where each one is, the same "find the region, then read it" approach as MinerU or PP-Structure. Latexinter reads each region as a whole. It finds the fraction bars among the page's drawings and stacks what's above and below into \frac{…}{…}. When a PDF has no bars (Ghostscript output, for instance), it infers the fraction from what sits above and below the line, the way layout-based recognizers like Infty and MaxTract do. It also hangs limits on ∑ and lim (\substack when there are two rows), rebuilds roots from the √ and its bar, and puts accents like ˆ back on their letter.
  • Font alphabets: a letter in a blackboard font becomes \mathbb{E}, one in a calligraphic font \mathcal{S}. Computer Modern, STIX and newtx fonts are recognized.
  • Unicode symbols (mathfix.py): instead of if $\alpha$ $\leq$ $\beta$, it detects the whole math run and writes if $\alpha \leq \beta$.
  • OCR (optional): with --ocr, each equation is also read as an image by Pix2Text-MFR (MIT). It runs on onnxruntime, which Latexinter already ships, so it needs no PyTorch; the 120 MB model downloads on first use. Its reading is only kept when it uses the same glyphs the PDF has: the layout reconstruction knows the exact characters, the OCR is better at arranging them but sometimes makes one up. It must also be valid LaTeX: a reading with a \left and no \right, or cut off halfway through an aligned, is dropped so it can't break the compile. pix2tex and Texify still work if they're installed.

The sample's equations come back as \int_{-\infty}^{\infty}e^{-x^{2}}dx=\sqrt{\pi} and f(x)=\sum_{n=0}^{\infty}\frac{f^{(n)}(a)}{n!}(x-a)^{n}, without OCR.

It also cleans up the usual PDF debris:

  • Running headers and stray page numbers.
  • A dotted table of contents, replaced with \tableofcontents.
  • The LaTeX logo broken into letters.
  • Heading levels, worked out from the section numbers.
  • Code listings, which the extractor mashes into one paragraph. They come back as code blocks with their indentation and without the line numbers.

On the benchmark's papers, the .tex it writes compiles with pdflatex without errors. Characters the PDF doesn't map to Unicode can't be recovered: they're kept in the source and print as □, so they're easy to find and fix.

Install

Windows: download Latexinter-…-instalador.exe from the latest release and run it. It doesn't need admin rights, and it installs MiKTeX and pandoc for you if they're missing. The installer isn't signed yet, so Windows may show "Windows protected your PC": click More info → Run anyway.

From source: you need Python 3.12+, two external programs and a few packages:

winget install --id JohnMacFarlane.Pandoc
winget install --id MiKTeX.MiKTeX
pip install -r requirements.txt
python cli.py deps        # checks that everything is in place
python app.py

Formula OCR (--ocr) works out of the box: the first time, it downloads the Pix2Text-MFR model (120 MB) into %LOCALAPPDATA%\Latexinter\modelos.

Command line

python cli.py pdf2docx paper.pdf --pages 1-6
python cli.py pdf2tex  paper.pdf --pages 1-6 --ocr
python cli.py tex2pdf  thesis.tex --engine xelatex
python cli.py tex2docx thesis.tex --toc
python cli.py docx2tex report.docx
python cli.py docx2pdf report.docx
python cli.py pdf2docx a.pdf b.pdf c.pdf    # several files at once

Measuring formula recovery

python -m bench.run          # without OCR
python -m bench.run --ocr    # with formula OCR

This downloads the arXiv papers listed in bench/papers.txt (the PDF and the original .tex) into bench/cache/, which isn't committed. It converts each PDF, compares every formula with the original and compiles the result. For each paper and each kind of formula (scripts, fractions, sums…) it reports how many came out identical, how similar they are and how many errors pdflatex gives, and it compares the totals with bench/referencia.json. --referencia saves the run as the new reference.

Building the installer

You need Python 3.12 and Inno Setup 6 (winget install JRSoftware.InnoSetup):

powershell -ExecutionPolicy Bypass -File installer\build.ps1

This produces dist\Latexinter-<version>-instalador.exe, about 90 MB. It installs without admin rights and, if MiKTeX or pandoc are missing, offers to install them with winget. The version comes from __version__ in ui/__init__.py.

Tests

pip install pytest
python -m pytest tests -q

The text and formula cleanup tests only need Python. The end-to-end test (ejemplos/ejemplo.pdf → LaTeX) is skipped automatically when pymupdf4llm and pandoc aren't installed.

Project layout

app.py, cli.py      desktop app and command line
ui/                 PyQt5 interface: editor, PDF viewer, panels, converter
converters/         the conversions, plus the formula reconstruction (pdfmath, mathfix, mathocr)
tests/              pytest
ejemplos/           sample .tex, .pdf and .docx to try the converter
bench/              formula recovery benchmark on arXiv papers
installer/          Windows installer (PyInstaller + Inno Setup)

License

GNU AGPL v3.

Licenses of the dependencies:

  • PyQt5 is GPL v3.
  • PyMuPDF and pymupdf4llm are AGPL v3.
  • The Pix2Text-MFR model and pix2tex are MIT.
  • Since version 1.27, pymupdf4llm also installs pymupdf-layout, which is PolyForm Noncommercial: free to use, but not for commercial purposes without a license from Artifex.

About

Desktop LaTeX editor and PDF ⇄ LaTeX ⇄ Word converter that rebuilds math formulas from PDFs. Offline, PyQt5.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages