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 '14 at 14:36
  • @JosephWright: I am looking for a tool that tidies up. – eins6180 Oct 10 '14 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. – Steven B. Segletes Sep 15 '15 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 '15 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. – Steven B. Segletes Sep 15 '15 at 14:13

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

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

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.

https://c.albert-thompson.com/latex-pretty/

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:

http://www.ctan.org/pkg/ltxdoc

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

http://www.ctan.org/pkg/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).

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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