Pretty-printing
Pretty-printing is making text easier to read by applying formatting rules. This can apply to source code, markup, or math. Common techniques include indentation, spacing, and highlighting to show structure and improve readability. In code, tools that format and tidy up code are called code formatters or beautifiers.
Pretty-printing also refers to displaying mathematical expressions in a way similar to professional typesetting. Some math-capable systems and graphing calculators show expressions in a more readable, math-like form.
Markup languages present their own challenges. Indentation can reveal the hierarchy of tags and content, but the rules vary by language. In MathML, spaces don’t carry meaning beyond XML syntax. In HTML, spaces between tags become text that the browser treats as content, so pretty-printing HTML must be careful not to create or remove text nodes inadvertently. Automated tools for HTML and XML often use complex rules to keep the content and structure consistent.
Programmers are usually taught a formatting style to make code easier to read. Styles differ in how they indent, where spaces go around keywords and punctuation, and where braces appear. There are automated tools called beautifiers, code formatters, or indenters that convert code from one style to another. Some are standalone programs; others are built into text editors or integrated development environments. For example, editors like Emacs can be configured to format code according to a chosen language mode.
An early example of pretty-printing was Bill Gosper’s GRINDEF (around 1967), which formatted Lisp programs by formatting their structure rather than their content. The term grind has been used in Lisp communities to mean pretty-printing.
Many free software projects publish style guidelines, with GNU and BSD being the best known. They differ mainly in how braces are placed: GNU style puts each opening brace on its own line and aligns closing braces at the same level, while BSD style places the opening brace at the end of the preceding line and may place a closing brace before an else. Indentation size and the handling of whitespace also vary. These rules guide how code should look when properly formatted.
This page was last edited on 2 February 2026, at 20:08 (CET).