From Wikipedia, the free encyclopedia
  (Redirected from Pretty-printing)
Jump to: navigation, search


Pretty-printing mathematics[edit]

A typeset mathematical expression

Pretty-printing usually refers to displaying mathematical expressions similar to the way they would be typeset professionally. For example, in computer algebra systems such as Maxima or Mathematica the system may write output like "x ^ 2 + 3 * x" as "". Some graphing calculators, such as the Casio 9860 series, HP-49 series, TI-84 Plus, TI-89, and TI-Nspire, the TI-83 Plus with the PrettyPt add-on, or the TI-84 Plus with the same add-on or the "MathPrint"-enabled OSes, can perform pretty-printing. Additionally, a number of newer scientific calculators are equipped with dot matrix screens capable of pretty-printing such as the Casio FX-ES series (Natural Display), Sharp EL-W series (WriteView), HP SmartCalc 300s, and TI-30XB.


Pretty-printing markup and tag-based code[edit]


In MathML, whitespace characters do not reflect data, meaning, or syntax above what is required by XML syntax. In HTML, whitespace characters between tags are considered text and are parsed as text nodes into the parsed result.[1] While indentation may be generously applied to a MathML document, sufficient additional care must be taken in prettyprinting an HTML document to ensure additional text nodes are not created or destroyed in general proximity to content or content-reflective tag elements. This difference in complexity is non-trivial from the perspective of an automated pretty-print operation where no special rules or edge cases are necessary, as in the more simple MathML example. The HTML example may require a series of progressive interrelated algorithms to account for various patterns of tag elements and content that conforms to a uniform style and is consistent in application across various instances, as evidenced by the markup_beauty.js application component used to beautify HTML, XML, and related technologies for the Pretty Diff tool.

Programming code formatting and beautification[edit]


Code beautifiers exist as standalone applications and built into text editors and integrated development environments. For example, Emacs' various language modes can correctly indent blocks of code attractively.[2]


Lisp pretty-printer[edit]


Project style rules[edit]


Example of formatting and beautifying code[edit]




foo (int k)
  if (k < 1 || k > 2)
      printf ("out of range\n");
      printf ("Switching\n");
      switch (k)
        case 1:
          printf ("1\n");
        case 2:
          printf ("2\n");

It produces this output when formatting according to BSD rules:

foo(int k)
	if (k < 1 || k > 2) {
		printf("out of range\n");
	} else {
		switch (k) {
		case 1:
		case 2:

Formatted text[edit]

Formatted text can be considered a generalized form of pretty-printing.

See also[edit]


  5. ^ Jargon File, s.v. grind

External links[edit]