tex-fmt
An extremely fast LaTeX formatter written in Rust.
\begin{document}
\begin{equation}\end{equation}
\end{document}
\begin{document}
\begin{equation}\end{equation}
\end{document}
- ⚡ Extremely fast run-time performance
- 🔧 No configuration necessary
- 📟 Command-line interface
- 📜 Handles LaTeX file types
.tex,.bib,.cls, and.sty - 🦀 Written entirely in safe Rust
Installation
Cargo
# install stable release
cargo install tex-fmt
# install from github
cargo install --git "https://github.com/wgunderwood/tex-fmt"
Nix
nix build "github:wgunderwood/tex-fmt"
Usage
tex-fmt file.tex # format file.tex and overwrite
tex-fmt -c file.tex # check if file.tex is correctly formatted
tex-fmt -p file.tex # format file.tex and print to STDOUT
tex-fmt -k file.tex # keep lines, do not wrap
tex-fmt -h # view help information
Disabling the formatter
Ending a source line with % tex-fmt: skip disables the formatter for that line.
To disable the formatter for a block, use % tex-fmt: off and % tex-fmt: on.
\begin{document}
This line is skipped % tex-fmt: skip
% tex-fmt: off
These lines are also
not formatted or wrapped
% tex-fmt: on
\end{document}
Verbatim environments including verbatim, Verbatim, lstlisting
and minted are automatically skipped.
Performance
When formatting all of the test cases, tex-fmt is over a thousand times faster than latexindent.
| Files | Lines | Size | tex-fmt | latexindent | latexindent -m |
|---|---|---|---|---|---|
| 49 | 94k | 3.5M | 0.096s | 97s [x1001] | 125s [x1288] |
Contribution
Please feel free to open an issue or submit a pull request, including as much information as you can.
Limitations
- Semantic parsing of LaTeX code not conducted
- No linting or correction of syntax errors
- Customization via configuration files not supported
- Compliance with existing formatting guidelines not guaranteed
- Editor integration not currently provided
- No spelling or grammar checking
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
-
latex-editor. Browser-based
-
LaTeXFmt. Vim plugin, does not apply indentation
-
latex-formatter. Visual Studio plugin, uses latexindent as the backend