Skip to content

An extremely fast LaTeX formatter written in Rust

License

Notifications You must be signed in to change notification settings

lineCode/tex-fmt

 
 

Repository files navigation

tex-fmt tex-fmt

CI crates.io license: MIT

An extremely fast 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
  • 🔧  Minimal configuration required
  • 📟  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"

Binary download

Binaries for various platforms are available on the GitHub releases page.

Usage

tex-fmt file.tex             # format file.tex and overwrite
tex-fmt --check file.tex     # check if file.tex is correctly formatted
tex-fmt --print file.tex     # format file.tex and print to STDOUT
tex-fmt --keep file.tex      # keep lines, do not wrap
tex-fmt --help               # view help information

Disabling the formatter

Ending a source line with % tex-fmt: skip disables formatting for that line. To disable the formatter for a block, use % tex-fmt: off and % tex-fmt: on.

\documentclass{article}

\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.092s 97s [x1054] 125s [x1359]

Contribution

Please feel free to open an issue or submit a pull request, including as much information as you can. Documentation of internals can be accessed by cloning this repository and running cargo doc.

Alternatively, you can Buy Me a Coffee!

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

About

An extremely fast LaTeX formatter written in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 93.5%
  • Nix 3.9%
  • Just 2.6%