Indentation (typesetting)

Short description: Empty space at the beginning of a line to signal the start of a new paragraph

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.

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.

## Contents

* 1 Indentation in typesetting
* 2 Indentation in programming
* 3 References

## 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 only the first line of each paragraph.
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 remaining lines of each paragraph while leaving the first line of each paragraph 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

Main article: Indentation style

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, MoonScript, and Ya programming languages rely on indentation in this way.

Opinions about where to indent, whether to use spaces or tabs, and how many spaces to use are often hotly debated among programmers, leading some to describe indentation disputes 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.

This table may lend undue weight to a single company's coding practices. Please help improve it by rewriting it in a balanced fashion that contextualizes different points of view. (March 2016) (Learn how and when to remove this template message)

|

Language | Indentation | Note

|
|

Bash | varies | Fritz Mehner's Style Guide[2] suggests 2, 4, or 8 spaces and uses 2 in all examples. Google uses 2 spaces.[3]
C | varies | The Linux kernel uses 1 tab.[4][5] NASA uses 4 spaces.[6] Clinton Staley advocates 3 spaces.[7]
C++ | varies | WebKit recommends 4 spaces.[8] Google uses 2 spaces.[9]
C# | 4 spaces | Per Microsoft's C# Coding Conventions.[10]
CSS | varies | Drupal, GitHub, and Google use 2 spaces.[11][12][13][14] WordPress uses tabs.[15]
Dart |  | `dart format` uses 2 spaces.
Delphi | 2 spaces | Per Delphi Style Guide.[16]
F# | 4 spaces | As per the F# style guide.[17]
Go | 1 tab | Per "Effective Go".[18]
Haskell | varies | Google uses 2 spaces.[19]
HTML | varies | Google uses 2 spaces.[13] HTML Tidy defaults to 2 spaces.[20]
Java | varies | Oracle uses 4 spaces.[21] Android uses 4 spaces.[22] Most Eclipse IDE components use tabs.
JavaScript | varies | Douglas Crockford advocates 4 spaces.[23] GitHub and Google uses 2 spaces.[24][25] jQuery uses tabs.[26] Firefox's built-in jsbeautifier defaults to 2 spaces. The built-in prettyprinter in Google Chrome and Internet Explorer uses 4 spaces.
Julia | 4 spaces  | Per Julia style guide.[27]
Kotlin | 4 spaces  | Per Kotlin style guide.[28]
Lua | 2 spaces | Per Lua Style Guide.[29]
Perl | varies | "perlstyle: Perl style guide" says Larry Wall prefers but does not mandate 4 spaces.[30]
PHP | varies | Drupal use 2 spaces.[31] PEAR and Zend use 4 spaces.[32][33] CodeIgniter and WordPress uses tabs.[34][35] PSR-2 specifies 4 spaces.[36]
PowerShell | varies | 4 spaces in The Unofficial PowerShell Best Practices and Style Guide.[37]
Python | 4 spaces | Per PEP-8.[38] (1 tab is also sometimes used, but 4 spaces is preferred.)
Ruby | 2 spaces | Per Ruby Style Guide.[39]
Rust | 4 spaces | Per Rust Style Guide.[40]
Scala | 2 spaces | Per Scala style guide.[41]
Swift | varies | Google uses 2 spaces.[42]
Tcl | 4 spaces | Per Tcl style guide.[43]
Visual Basic | 4 spaces | Per Microsoft's Visual Basic Coding Conventions.[44]
XML | varies | Google uses 2 spaces.[45]

## References

1. ↑ "Tabs versus Spaces: An Eternal Holy War". 2007-01-05. http://www.jwz.org/doc/tabs-vs-spaces.html.
2. ↑ "Bash Style Guide and Coding Standard". https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf.
3. ↑ "Archived copy". https://google-styleguide.googlecode.com/svn/trunk/shell.xml.
4. ↑ "Archived copy". https://www.kernel.org/doc/Documentation/CodingStyle.
5. ↑ "Linux kernel coding style". https://www.kernel.org/doc/html/latest/process/coding-style.html.
6. ↑ "C STYLE GUIDE". August 1994. https://ntrs.nasa.gov/citations/19950022400.
7. ↑ Staley, Clinton (2006). "C Program Style Rules". https://users.csc.calpoly.edu/~cstaley/General/CStyle.htm.
8. ↑ "Code Style Guidelines". 2015-11-07. https://webkit.org/code-style-guidelines/.
9. ↑ [1]
10. ↑ Bill Wagner. "C# Coding Conventions (C# Programming Guide)". http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx.
11. ↑ "CSS formatting guidelines". 14 January 2013. https://drupal.org/node/1887862.
12. ↑ "CSS · Styleguide · GitHub". https://github.com/styleguide/css.
13. ↑ 13.0 13.1 "Google HTML/CSS Style Guide". Google GitHub. Indentation. http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml#Indentation. "Indent by 2 spaces at a time." This is an HTML-rendered copy of the official version, which is maintained in XML format
14. ↑ "styleguide: Style guides for Google-originated open-source projects". 3 September 2017. https://github.com/google/styleguide.
15. ↑ "WordPress › CSS Coding Standards « Make WordPress Core". 17 July 2012. https://make.wordpress.org/core/handbook/best-practices/coding-standards/css/#structure.
16. ↑ "Delphi's Object Pascal Style Guide - White Space Usage" (in en-us). https://docwiki.embarcadero.com/RADStudio/Alexandria/en/White_Space_Usage#Indentation.
17. ↑ "F# code formatting guidelines" (in en-us). https://docs.microsoft.com/en-us/dotnet/fsharp/style-guide/formatting.
18. ↑ "Effective Go – The Go Programming Language". http://golang.org/doc/effective_go.html.
19. ↑ "HaskellStyleGuide – ganeti – Style Guide for the Haskell code – Cluster-based virtualization management software – Google Project Hosting". 2014-01-08. https://code.google.com/p/ganeti/wiki/HaskellStyleGuide#Indentation.
20. ↑ "HTML Tidy Configuration Options Quick Reference". 2008-06-18. http://tidy.sourceforge.net/docs/quickref.html#indent-spaces.
21. ↑ "Code Conventions for the Java Programming Language: 4. Indentation". http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#262.
22. ↑ "Code Style Guidelines for Contributors | Android Developers". http://source.android.com/source/code-style.html#use-spaces-for-indentation.
23. ↑ "Code Conventions for the JavaScript Programming Language". 2006-11-13. http://javascript.crockford.com/code.html.
24. ↑ "JavaScript 路 Styleguide". https://github.com/styleguide/javascript.
25. ↑ "JaveScript Style Rules". http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting.
26. ↑ jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". http://contribute.jquery.org/style-guide/js/.
27. ↑ "Style Guide · The Julia Language". https://docs.julialang.org/en/v1.6/manual/style-guide/#Indentation.
28. ↑ "Coding Conventions – Kotlin Programming Language". https://kotlinlang.org/docs/reference/coding-conventions.html.
29. ↑ "lua-users wiki: Lua Style Guide". http://lua-users.org/wiki/LuaStyleGuide.
30. ↑ Allen, Jon (JJ), ed. "perlstyle: Perl style guide". Perl 5 Version 32.1 Documentation. Perl Foundation. http://perldoc.perl.org/perlstyle.html.
31. ↑ "Coding standards". https://drupal.org/coding-standards#indenting.
32. ↑ "Manual :: Indenting and Line Length". http://pear.php.net/manual/en/standards.indenting.php.
33. ↑ "PHP Coding Standard (draft) – Contributors – Zend Framework Wiki". http://framework.zend.com/wiki/display/ZFDEV/PHP+Coding+Standard+(draft).
34. ↑ "Style Guide : CodeIgniter User Guide". http://ellislab.com/codeigniter/user-guide/general/styleguide.html#code_indenting.
35. ↑ "WordPress › PHP Coding Standards « Make WordPress Core". 23 July 2012. http://make.wordpress.org/core/handbook/coding-standards/php/#indentation.
36. ↑ "PHP : Coding Style Guide". http://www.php-fig.org/psr/2/.
37. ↑ "Code Layout and Formatting – PowerShell Practice and Style". https://poshcode.gitbook.io/powershell-practice-and-style/style-guide/code-layout-and-formatting.
38. ↑ "PEP 8 – Style Guide for Python Code". https://www.python.org/dev/peps/pep-0008/#indentation.
39. ↑ Batsov, Bozhidar (3 September 2017). "ruby-style-guide: A community-driven Ruby coding style guide". https://github.com/bbatsov/ruby-style-guide.
40. ↑ "rust: A safe, concurrent, practical language". 3 September 2017. https://github.com/rust-lang/rust.
41. ↑ "Indentation – Scala Documentation". http://docs.scala-lang.org/style/indentation.html.
42. ↑ "Swift Style Guide". https://google.github.io/swift/.
43. ↑ Ray Johnson. "Tcl Style Guide". http://www.tcl.tk/doc/styleGuide.pdf.
44. ↑ "Structured Coding Conventions". http://msdn.microsoft.com/en-us/library/aa733583(v=vs.60).aspx.
45. ↑ "Google XML Document Format Style Guide". Google. https://google.github.io/styleguide/xmlstyle.html.

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Indentation (typesetting). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Indentation_(typesetting)&oldid=231349"