#latex #formatter #tex #line #file #end #document

app tex-fmt

LaTeX formatter written in Rust

2 unstable releases

new 0.2.0 May 25, 2024
0.1.0 Apr 27, 2024

#56 in Value formatting

Download history 91/week @ 2024-04-21 91/week @ 2024-04-28 2/week @ 2024-05-05

184 downloads per month

MIT license

480KB
988 lines

tex-fmt

CI crates.io license: MIT

A LaTeX formatter written in Rust.

Input Output
\documentclass{article}

\begin{document}

\begin{itemize}
\item Lists with items
over multiple lines
\end{itemize}

\begin{equation}
E = m c^2
\end{equation}

\end{document}
\documentclass{article}

\begin{document}

\begin{itemize}
  \item Lists with items
    over multiple lines
\end{itemize}

\begin{equation}
  E = m c^2
\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"

Performance

When formatting all of the test cases, tex-fmt is hundreds of times faster than latexindent.

Files Lines Size tex-fmt latexindent latexindent -m
19 34k 970kb 0.0318s 15.4s [x483] 19.8s [x622]

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 spell 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. 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

~4–6MB
~104K SLoC