7

This question already has an answer here:

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?

marked as duplicate by Martin Scharrer Jan 17 at 9:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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
4

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

3

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/

2

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

1

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

0

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 '18 at 21:01

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