I am looking for a tool that reformats my LaTeX source code so that it becomes nice and readable. For programming languages like C, C++, etc. such pretty printers exist.

Are there any pretty printers for LaTeX source?

  • 1
    Do you mean you want to typeset your source or do you want it in some way 'tidying up' first? The two tasks are distinct.
    – Joseph Wright
    Oct 10, 2014 at 14:36
  • @JosephWright: I am looking for a tool that tidies up.
    – eins6180
    Oct 10, 2014 at 14:50
  • Could you elaborate on how/what you would like to tidy up. Typically code is formatted in fixed-width font,using a verbatim like approach. You might want line numbers, some sort of coloring, or the ability to overlay comments on the code, or any number of things. Help us out here. Sep 15, 2015 at 13:51
  • 1
    @StevenB.Segletes: Sure, let me give you some context. Whenever I write a long document, I write a paragraph, then delete part of it, add a formula, write another paragraph, change that again, and so on. Slowy I converge towards the final version. At that stage my LaTeX source (meaning the all the text and commands I entered in my .tex file) looks often horrific. Then I would like to have a prettifier tool available that reformats my LaTeX source in my .tex file to make it more readable.
    – eins6180
    Sep 15, 2015 at 13:59
  • Thank you for the clarification (I initially misunderstood). This would be, most likely, a very elaborate editor function, I think. One way I generate source that works well for me is to: 1) start each new sentence on a new line; 2) hang-indent multi-line sentences starting at the 2nd line of the sentence. That habit alone often gets me 80% of the way to tidied up .tex file. Sep 15, 2015 at 14:13

5 Answers 5


Although it has ben mentioned in some other posts, latexindent was missing here.

latexindent is a

PERL script to indent code within environments, and align delimited environments in .tex files.

It can be used from command line or through arara

A before-and-after example stolen from its documentation:

enter image description here


I created a website that reformats the latex code to make indents correct.

It is a simple site that you put in your latex code and will do pretty print similar to Visual Studio. The nice thing about the site is that it also includes a copy button so you don't have to select all text when you get formatted code.



First of all, there is a LaTeX package to prettyprint LaTeX sources. You don't need to download it, it is in the base distribution, namely ltxdoc – Class for documented LaTeX macro files:


There is an emacs mode supporting ltxdoc markup of a file that may help you, it is called swiftex:


Also the AUC-TeX mode from emacs is a big help in keeping your LaTeX source code tidy (but is does not document the code itself).

  • In my humble opinion, swiftex was already outdated, when you posted this answer. Today (2022) it is even more outdated. Its last update was in 2000. It won't work with newer Emacs versions. The code often refers a non existing Info file. Therefore, sad to say so, nowadays I would not suggest it anymore :-(
    – Jan
    Mar 5 at 9:07

There is Nelson Beebe's tex-pretty: http://www.math.utah.edu/~beebe/software/tex-tools.html


How about a2ps? Assuming your LaTeX input file contains Latin1 characters only, you can do

a2ps -q -Eplain -R --encoding=latin1 --columns=1 -l 85 -o out.pdf in.tex

or something similar.

  • 1
    Welcome to TeX.SE! And the result of that command is? Is it available in MiKTeX, TeX Live and MacTeX? Please explain a little bit better ...
    – Mensch
    Dec 5, 2018 at 21:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.