14 unstable releases (3 breaking)

new 0.4.7 Nov 15, 2024
0.4.4 Sep 29, 2024
0.3.0 Jul 31, 2024

#39 in Command line utilities

Download history 121/week @ 2024-07-31 115/week @ 2024-08-14 11/week @ 2024-08-21 333/week @ 2024-08-28 158/week @ 2024-09-04 259/week @ 2024-09-11 137/week @ 2024-09-18 292/week @ 2024-09-25 275/week @ 2024-10-02 266/week @ 2024-10-09 238/week @ 2024-10-16 141/week @ 2024-10-23 165/week @ 2024-10-30 89/week @ 2024-11-06 183/week @ 2024-11-13

624 downloads per month

MIT license

51KB
1K SLoC

tex-fmt tex-fmt

CI crates.io Packaging status 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 the stable release with

cargo install tex-fmt

Install from GitHub with

cargo install --git "https://github.com/wgunderwood/tex-fmt"

Nix

Install from nixpkgs into a temporary shell with

nix-shell -p tex-fmt

Build from source using flakes with

nix build "github:wgunderwood/tex-fmt"

Add to your NixOS installation with

environment.systemPackages = [
  pkgs.tex-fmt
];

Arch Linux

Install from the Arch User Repository. For example, using the yay AUR helper:

yay -S tex-fmt

Homebrew

Install using Homebrew with

brew install tex-fmt

Binary download

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

Visual Studio Code

Integration with VS Code is provided by the LaTeX Workshop extension. You will need to first install tex-fmt through one of the above methods.

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      # do not wrap long lines
tex-fmt --stdin              # read from STDIN and print to STDOUT
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
51 94k 3.5M 0.055s 106s [x1927] 127s [x2309]

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
  • No spelling or grammar checking

Existing tools

Options

The following command-line options are offered by tex-fmt.

Option Alias Default Description
--check -c Check formatting, do not modify files.
--print -p Print to STDOUT, do not modify files.
--keep -k Keep lines, do not wrap.
--verbose -v Show info log messages.
--quiet -q Hide warning messages.
--trace -t Show trace log messages.
--stdin -s Process STDIN as a single file, output formatted text to STDOUT.
--tab 2 Number of spaces to use as tab size.
--usetabs Use tabs instead of spaces for indentation.
--wrap 80 Line length for wrapping.
--help -h Print help.
--version -V Print version.

Dependencies

~4–15MB
~138K SLoC