Indentation (typesetting)

Last updated

In the written form of many languages, an indentation or indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate "paragraphs" or other logical blocks in the program.

Contents

For example, the following lines are indented, using between one and six spaces:

 This paragraph is indented by 1 space.

   This paragraph is indented by 3 spaces.

      This paragraph is indented by 6 spaces.

In computer programming, the neologisms outdent, unindent and dedent are used to describe the reversal of the indentation process, realigning text with the page margin (or with previous, lesser, levels of indentation).

In right-to-left languages (e.g. Hebrew and Arabic), indentation is used just the same, but from the right margin of the paper, where the line begins.

Indentation in typesetting

There are three main types of indentation, illustrated below in relation to borders representing the page dimensions.

A first-line indentation indents the first line.
A first-line indentation of 2  em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
A hanging indentation indents the rest of the text while leaving the first line in place.
A hanging indentation of 2 em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
A block indentation indents the entire block of text.
A block indentation of 2 em on the left:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Indentation from both sides is commonly used for block quotations, here shown with 2 em on the left and right (which may amount to more on the right for certain lines, depending on word wrapping, if the text does not have justified alignment):
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
A justified-text example of a block quotation that has been block-indented from both sides by 3 em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Indentation in programming

In computer programming languages, indentation is used to format program source code to improve readability. Indentation is generally only of use to programmers; compilers and interpreters rarely care how much whitespace is present in between programming statements. However, certain programming languages rely on the use of indentation to demarcate programming structure, often using a variation of the off-side rule. The Haskell, Occam, Python, and Ya programming languages rely on indentation in this way.

Debates over where to indent, whether to use spaces or tabs, and how many spaces to use are often hotly debated among programmers, leading some to classify indentation as akin to a religious war. [1] In 2006 a third method of indentation was proposed, called elastic tabstops.

In addition to general indentation of statements, different bracket indentation styles are commonly used.

LanguageIndentationNote
Bash variesFritz Mehner's Style Guide [2] suggests 2, 4, or 8 spaces and uses 2 in all examples. Google uses 2 spaces. [3]
C variesThe Linux kernel uses 1 tab. [4] NASA uses 4 spaces. [5]
C++ variesGoogle uses 2 spaces. [6]
C# 4 spacesPer Microsoft's C# Coding Conventions. [7]
CSS varies Drupal, GitHub, and Google use 2 spaces. [8] [9] [10] [11] WordPress uses tabs. [12]
Delphi 2 spacesDefault in RAD Studio.[ citation needed ]
F# 4 spacesAs per the F# style guide. [13]
Go 1 tabPer "Effective Go". [14]
Haskell variesGoogle uses 2 spaces. [15]
HTML variesGoogle uses 2 spaces. [10] HTML Tidy defaults to 2 spaces. [16]
Java varies Oracle uses 4 spaces. [17] Android uses 4 spaces. [18] Most Eclipse IDE components use tabs.
JavaScript varies Douglas Crockford advocates 4 spaces. [19] GitHub and Google uses 2 spaces. [20] [21] jQuery uses tabs. [22] Firefox's built-in jsbeautifier defaults to 2 spaces. The built-in prettyprinter in Google Chrome and Internet Explorer uses 4 spaces.
Julia 4 spacesPer Julia style guide. [23]
Kotlin 4 spacesPer Kotlin style guide. [24]
Lua 2 spacesPer Lua Style Guide. [25]
Perl varies"perlstyle: Perl style guide" says Larry Wall prefers but does not mandate 4 spaces. [26]
PHP varies Drupal use 2 spaces. [27] PEAR and Zend use 4 spaces. [28] [29] CodeIgniter and WordPress uses tabs. [30] [31] PSR-2 specifies 4 spaces. [32]
Python 4 spacesPer PEP-8. [33] (1 tab is also sometimes used, but 4 spaces is preferred.)
Ruby 2 spacesPer Ruby Style Guide. [34]
Rust 4 spacesPer Rust Style Guide. [35]
Scala 2 spacesPer Scala style guide. [36]
Tcl 4 spacesPer Tcl style guide. [37]
Visual Basic 4 spacesPer Microsoft's Visual Basic Coding Conventions. [38]

Related Research Articles

Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a specific task. Programming involves tasks such as: analysis, generating algorithms, profiling algorithms' accuracy and resource consumption, and the implementation of algorithms in a chosen programming language. The source code of a program is written in one or more languages that are intelligible to programmers, rather than machine code, which is directly executed by the central processing unit. The purpose of programming is to find a sequence of instructions that will automate the performance of a task on a computer, often for solving a given problem. Proficient programming thus often requires expertise in several different subjects, including knowledge of the application domain, specialized algorithms, and formal logic.

Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.

<i>Scriptio continua</i>

Scriptio continua, also known as scriptura continua or scripta continua, is a style of writing without spaces, or other marks between the words or sentences. The form also lacks punctuation, diacritics, or distinguished letter case. In the West, the oldest Greek and Latin inscriptions used word dividers to separate words in sentences; however, Classical Greek and late Classical Latin both employed scriptio continua as the norm.

<i>Lorem ipsum</i> Placeholder text used in publishing and graphic design

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. It is also used to temporarily replace text in a process called greeking, which allows designers to consider the form of a webpage or publication, without the meaning of the text influencing the design.

KDevelop

KDevelop is a free and open-source integrated development environment (IDE) for Unix-like computer operating systems and Windows. It provides editing, navigation and debugging features for several programming languages, and integration with build automation and version-control systems, using a plugin-based architecture.

In computer science, a NOP, no-op, or NOOP is an assembly language instruction, programming language statement, or computer protocol command that does nothing.

TextPad is a text editor for the Microsoft Windows family of operating systems. It is produced by Helios Software Solutions. It is currently in its eighth major version.

A lightweight markup language (LML), also termed a simple or humane markup language, is a markup language with simple, unobtrusive syntax. It is designed to be easy to write using any generic text editor and easy to read in its raw form. Lightweight markup languages are used in applications where it may be necessary to read the raw document as well as the final rendered output.

In word processing and digital typesetting, a non-breaking space,  , also called NBSP, required space, hard space, or fixed space, is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space.

In computing, a here document is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file. The term is also used for a form of multiline string literals that use similar syntax, preserving line breaks and other whitespace in the text.

In computer programming, whitespace is any character or series of characters that represent horizontal or vertical space in typography. When rendered, a whitespace character does not correspond to a visible mark, but typically does occupy an area on a page. For example, the common whitespace symbol U+0020 SPACE represents a blank space punctuation character in text, used as a word divider in Western scripts.

<i>Scientia potentia est</i> Latin aphorism often claimed to mean organized "knowledge is power"

The phrase "scientia potentia est" is a Latin aphorism meaning "knowledge is power". It is commonly attributed to Sir Francis Bacon, although there is no known occurrence of this precise phrase in Bacon's English or Latin writings. However, the expression "ipsa scientia potestas est" occurs in Bacon's Meditationes Sacrae (1597). The exact phrase "scientia potentia est" was written for the first time in the 1668 version of the work Leviathan by Thomas Hobbes, who was a secretary to Bacon as a young man.

Initial

In a written or published work, an initial or drop cap is a letter at the beginning of a word, a chapter, or a paragraph that is larger than the rest of the text. The word is derived from the Latin initialis, which means standing at the beginning. An initial is often several lines in height and in older boscene are known as "inhabited" initials. Certain important initials, such as the Beatus initial or "B" of Beatus vir... at the opening of Psalm 1 at the start of a vulgate Latin. These specific initials, in an illuminated manuscript, were also called initiums

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages.

Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices, and methods for each aspect of a program written in that language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles, programming rules of thumb, architectural best practices, etc. These are guidelines for software structural quality. Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Coding conventions are only applicable to the human maintainers and peer reviewers of a software project. Conventions may be formalized in a documented set of rules that an entire team or company follows, or may be as informal as the habitual coding practices of an individual. Coding conventions are not enforced by compilers.

The fmt command in Unix, Plan 9, Inferno, and Unix-like operating systems is used to format natural language text for humans to read.

The zero-width space (), abbreviated ZWSP, is a non-printing character used in computerized typesetting to indicate word boundaries to text processing systems when using scripts that do not use explicit spacing, or after characters that are not followed by a visible space but after which there may nevertheless be a line break. It is also used with languages without visible space between words, for example Japanese. Normally, it is not a visible separation, but it may expand in passages that are fully justified.

A line is a unit of language into which a poem or play is divided. The use of a line operates on principles which are distinct from and not necessarily coincident with grammatical structures, such as the sentence or single clauses in sentences. Although the word for a single poetic line is verse, that term now tends to be used to signify poetic form more generally. A line break is the termination of the line of a poem and the beginning of a new line.

fold is a Unix command used for making a file with long lines more readable on a limited width computer terminal by performing a line wrap.

CoffeeScript is a programming language that compiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to enhance JavaScript's brevity and readability. Specific additional features include list comprehension and destructuring assignment.

References

  1. "Tabs versus Spaces: An Eternal Holy War". Jwz.org. 2007-01-05. Retrieved 2014-01-18.
  2. "Bash Style Guide and Coding Standard" (PDF). Lug.fh-swf.de.
  3. "Archived copy". Archived from the original on 2014-06-26. Retrieved 2014-06-23.CS1 maint: archived copy as title (link)
  4. "Archived copy". Archived from the original on 2015-02-14. Retrieved 2015-02-15.CS1 maint: archived copy as title (link)
  5. "C STYLE GUIDE" (PDF). Homepages.inf.ed.ac.uk. August 1994. Retrieved 3 September 2017.
  6. Archived 2014-10-06 at the Wayback Machine
  7. Bill Wagner. "C# Coding Conventions (C# Programming Guide)". Msdn.microsoft.com. Retrieved 3 September 2017.
  8. "CSS formatting guidelines". Drupal.org. Retrieved 2014-01-18.
  9. "CSS · Styleguide · GitHub". Github.com. Retrieved 2014-01-18.
  10. 1 2 "Google HTML/CSS Style Guide". Google GitHub. Indentation. Archived from the original on 2016-03-13. Retrieved 2016-03-13. Indent by 2 spaces at a time. This is an HTML-rendered copy of the official version, which is maintained in XML format
  11. "styleguide: Style guides for Google-originated open-source projects". Github.com. 3 September 2017. Retrieved 3 September 2017.
  12. "WordPress › CSS Coding Standards « Make WordPress Core". Make.wordpress.org. Retrieved 2018-07-20.
  13. "F# code formatting guidelines". docs.microsoft.com. Retrieved 14 October 2020.
  14. "Effective Go - The Go Programming Language". golang.org. Retrieved 3 September 2017.
  15. "HaskellStyleGuide - ganeti - Style Guide for the Haskell code - Cluster-based virtualization management software - Google Project Hosting". Code.google.com. 2014-01-08. Archived from the original on June 27, 2013. Retrieved 2014-01-18.
  16. "HTML Tidy Configuration Options Quick Reference". Tidy.sourceforge.net. 2008-06-18. Retrieved 2014-01-18.
  17. "Code Conventions for the Java Programming Language: 4. Indentation". Oracle.com. Retrieved 2014-01-18.
  18. "Code Style Guidelines for Contributors | Android Developers". Source.android.com. Retrieved 2014-01-18.
  19. "Code Conventions for the JavaScript Programming Language". Javascript.crockford.com. 2006-11-13. Retrieved 2014-01-18.
  20. "JavaScript 路 Styleguide". Github.com. Archived from the original on 2013-08-15. Retrieved 2014-01-18.
  21. "JaveScript Style Rules". Google-styleguide.googlecode.com. Archived from the original on 2014-02-16. Retrieved 2014-02-18.
  22. jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". Contribute.jquery.org. Retrieved 2014-01-18.
  23. "Style Guide · The Julia Language". docs.julialang.org.
  24. "Coding Conventions - Kotlin Programming Language". Kotlin.
  25. "lua-users wiki: Lua Style Guide". lua-users.org. Retrieved 3 September 2017.
  26. Allen, Jon (JJ) (ed.). "perlstyle: Perl style guide". Perl 5 Version 32.1 Documentation. Perl Foundation. Retrieved 2021-04-19.
  27. "Coding standards". Drupal.org. Retrieved 2014-01-18.
  28. "Manual :: Indenting and Line Length". Pear.php.net. Retrieved 2014-01-18.
  29. "PHP Coding Standard (draft) - Contributors - Zend Framework Wiki". Framework.zend.com. Archived from the original on 2008-01-03. Retrieved 2014-01-18.
  30. "Style Guide : CodeIgniter User Guide". Ellislab.com. Retrieved 2014-01-18.
  31. "WordPress › PHP Coding Standards « Make WordPress Core". Make.wordpress.org. Retrieved 2014-01-18.
  32. "PHP : Coding Style Guide". Php-fig.org. Archived from the original on 2014-03-15. Retrieved 2014-02-18.
  33. "PEP 8 -- Style Guide for Python Code". Python.org. Retrieved 3 September 2017.
  34. Batsov, Bozhidar (3 September 2017). "ruby-style-guide: A community-driven Ruby coding style guide". Github.com. Retrieved 3 September 2017.
  35. "rust: A safe, concurrent, practical language". Github.com. 3 September 2017. Retrieved 3 September 2017.
  36. "Indentation - Scala Documentation". docs.scala-lang.org. Retrieved 3 September 2017.
  37. Ray Johnson. "Tcl Style Guide" (PDF). Tcl.tk. Retrieved 3 September 2017.
  38. "Structured Coding Conventions". msdn.microsoft.com. Retrieved 3 September 2017.