1 unstable release
0.1.0 | Apr 27, 2024 |
---|
#407 in Text processing
184 downloads per month
440KB
255 lines
tex-fmt
A LaTeX formatter written in Rust.
Formatting style example
Before formatting example.tex
:
\documentclass{article}
\begin{document}
\begin{itemize}
\item Lists with items
over multiple lines
\end{itemize}
\begin{align}
E = m c^2
\end{align}
\end{document}
After running tex-fmt example.tex
\documentclass{article}
\begin{document}
\begin{itemize}
\item Lists with items
over multiple lines
\end{itemize}
\begin{align}
E = m c^2
\end{align}
\end{document}
Installation
Nix
nix build "github:wgunderwood/tex-fmt"
Cargo
cargo install --git "https://github.com/wgunderwood/tex-fmt"
Aims
This project aims to provide a command-line tool for formatting LaTeX source code files with the following properties:
- Handling of the common LaTeX file types
.tex
,.bib
,.cls
, and.sty
- Very good run-time performance
- No configuration necessary
It does not currently aim to provide the following:
- Semantic parsing of LaTeX code
- Linting or correction of syntax errors
- Customization via configuration files
- Compliance with existing formatting guidelines
- Editor integration
- Spell checking
Performance
Run perf.sh
to format all test cases in the tests/
directory.
For larger files, tex-fmt is hundreds of times faster than latexindent.
Files | Lines | Size | tex-fmt | latexindent | latexindent -m |
---|---|---|---|---|---|
6 | 30k | 1M | 0.0362s | 11.6s [x322] | 15.3s [x424] |
Comparison with existing tools
-
latexindent. Perl script, many configuration options, slow on large files.
-
LaTeXTidy. Perl script, download links seem to be broken.
-
latex-pretty. Browser-based, uses latexindent as the backend.
-
latexformat.com. Browser-based.
-
texpretty. C program which works sometimes and appears to be fast. Fails with certain keywords inside brackets.
-
latex-editor. Browser-based.
-
LaTeXFmt. Vim plugin, does not apply indentation.
-
latex-formatter. Visual Studio plugin, uses latexindent as the backend.
Dependencies
~3.5–5MB
~90K SLoC