Whitespace Collapsing
   HOME

TheInfoList



OR:

A whitespace character is a character
data element In metadata, the term data element is an atomic unit of data that has precise meaning or precise semantics. A data element has: # An identification such as a data element name # A clear data element definition # One or more representation term ...
that represents white space when
text Text may refer to: Written word * Text (literary theory) In literary theory, a text is any object that can be "read", whether this object is a work of literature, a street sign, an arrangement of buildings on a city block, or styles of clothi ...
is rendered for display by a
computer A computer is a machine that can be Computer programming, programmed to automatically Execution (computing), carry out sequences of arithmetic or logical operations (''computation''). Modern digital electronic computers can perform generic set ...
. For example, a ''
space Space is a three-dimensional continuum containing positions and directions. In classical physics, physical space is often conceived in three linear dimensions. Modern physicists usually consider it, with time, to be part of a boundless ...
'' character (,
ASCII ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable character, printable and 33 control character, control c ...
32) represents blank space such as a
word divider In punctuation, a word divider is a form of glyph which separates written words. In languages which use the Latin, Cyrillic, and Arabic alphabets, as well as other scripts of Europe and West Asia, the word divider is a blank space, or ''whitesp ...
in a Western script. A
printable character In ISO/IEC 646 (commonly known as ASCII) and related standards including ISO 8859 and Unicode, a graphic character, also known as printing character (or printable character), is any character intended to be written, printed, or otherwise display ...
results in output when rendered, but a whitespace character does not. Instead, whitespace characters define the layout of text to a limited degree, interrupting the normal sequence of rendering characters next to each other. The output of subsequent characters is typically shifted to the right (or to the left for
right-to-left script A writing system comprises a set of symbols, called a ''script'', as well as the rules by which the script represents a particular language. The earliest writing appeared during the late 4th millennium BC. Throughout history, each independen ...
) or to the start of the next line. The effect of multiple sequential whitespace characters is cumulative such that the next printable character is rendered at a location based on the accumulated effect of preceding whitespace characters. The origin of the term ''whitespace'' is rooted in the common practice of rendering text on white
paper Paper is a thin sheet material produced by mechanically or chemically processing cellulose fibres derived from wood, Textile, rags, poaceae, grasses, Feces#Other uses, herbivore dung, or other vegetable sources in water. Once the water is dra ...
. Normally, a whitespace character is ''not'' rendered as white. It affects rendering, but it is not itself rendered.


Overview

A space character typically inserts horizontal space that is about as wide as a letter. For a
monospaced font A monospaced font, also called a fixed-pitch, fixed-width, or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space. This contrasts with Typeface#Proportion, variable-width fonts, where t ...
the width is the width of a letter, and for a variable-width font the width is font-specific. Some fonts support multiple space characters that have different widths. A tab character typically inserts horizontal space that is based on tab stops which vary by application. A
newline A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
character sequence typically moves the render output location to the beginning of the next line. If one follows text, it does not actually result in whitespace. But, two sequential newline sequences between text blocks results in a blank line between the blocks. The height of the blank line varies by application. Using whitespace characters to layout text is a convention. Applications sometimes render whitespace characters as visible markup so that a user can see what is normally not visible. Typically, a user types a space character by pressing , a tab character by pressing and newline by pressing .


Unicode

The table below lists the twenty-five characters defined as whitespace ("WSpace=Y", "WS") characters in the
Unicode Unicode or ''The Unicode Standard'' or TUS is a character encoding standard maintained by the Unicode Consortium designed to support the use of text in all of the world's writing systems that can be digitized. Version 16.0 defines 154,998 Char ...
Character Database. Seventeen use a definition of whitespace consistent with the algorithm for bidirectional writing ("Bidirectional Character Type=WS") and are known as "Bidi-WS" characters. The remaining characters may also be used, but are not of this "Bidi" type. ''Note: Depending on the browser and fonts used to view the following table, not all spaces may be displayed properly.''


Substitute images

Unicode also provides some visible characters that can be used to represent various whitespace characters, in contexts where a visible symbol must be displayed: ; Exact space * The Cambridge Z88 provided a special "exact space" (code point 160 aka 0xA0) (invokable by key shortcut ), displayed as "…" by the operating system's display driver. It was therefore also known as "dot space" in conjunction with BBC BASIC. *Under code point 224 (0xE0) the computer also provided a special three-character-cells-wide SPACE symbol "SPC" (analogous to Unicode's single-cell-wide U+2420).


Non-space blanks

* The Braille Patterns Unicode block contains , a
Braille Braille ( , ) is a Tactile alphabet, tactile writing system used by blindness, blind or visually impaired people. It can be read either on embossed paper or by using refreshable braille displays that connect to computers and smartphone device ...
pattern with no dots raised. Some fonts display the character as a fixed-width blank, however the Unicode standard explicitly states that it does not act as a space.Unicode chart U+2800
braille patterns
* Unicode's coverage of the
Korean alphabet The Korean alphabet is the modern writing system for the Korean language. In North Korea, the alphabet is known as (), and in South Korea, it is known as (). The letters for the five basic consonants reflect the shape of the speech organs ...
includes several code points which represent the absence of a written letter, and thus do not display a glyph: ** Unicode includes a Hangul Filler character in the Hangul Compatibility Jamo block (). This is classified as a letter, but displayed as an empty space, like a Hangul block containing no jamo. It is used in KS X 1001 Hangul combining sequences to introduce them or denote the absence of a letter in a position, but not in Unicode's combining jamo system. ** Unicode's combining jamo system uses similar Hangul Choseong Filler and Hangul Jungseong Filler characters to denote the absence of a letter in initial or medial position within a syllable block, which are included in the Hangul Jamo block (, ). ** Additionally, a Halfwidth Hangul Filler is included in the
Halfwidth and Fullwidth Forms In CJK characters, CJK (Chinese, Japanese, and Korean) computing, graphic characters are traditionally classed into fullwidth and halfwidth characters. Unlike monospaced fonts, a halfwidth character occupies half the width of a fullwidth characte ...
(), which is used when mapping from encodings which include characters from both Johab (or Wansung) and N-byte Hangul (or its
EBCDIC Extended Binary Coded Decimal Interchange Code (EBCDIC; ) is an eight- bit character encoding used mainly on IBM mainframe and IBM midrange computer operating systems. It descended from the code used with punched cards and the corresponding si ...
counterpart), such as IBM-933, which includes both Johab and EBCDIC fillers.


Whitespace and digital typography


On-screen display

Text editor A text editor is a type of computer program that edits plain text. An example of such program is "notepad" software (e.g. Windows Notepad). Text editors are provided with operating systems and software development packages, and can be used to c ...
s,
word processor A word processor (WP) is a device or computer program that provides for input, editing, formatting, and output of text, often with some additional features. Early word processors were stand-alone devices dedicated to the function, but current word ...
s, and desktop publishing software differ in how they represent whitespace on the screen, and how they represent spaces at the ends of lines longer than the screen or column width. In some cases, spaces are shown simply as blank space; in other cases they may be represented by an
interpunct An interpunct , also known as an interpoint, middle dot, middot, centered dot or centred dot, is a punctuation mark consisting of a vertically centered dot used for interword separation in Classical Latin. ( Word-separating spaces did not appe ...
or other symbols. Many different characters (described below) could be used to produce spaces, and non-character functions (such as margins and tab settings) can also affect whitespace. Many of the Unicode space characters were created for compatibility with classic print typography. Even if digital typography has algorithmic kerning and justification, those space characters can be used to supplement the electronic formatting when needed.


Variable-width general-purpose space

In computer
character encoding Character encoding is the process of assigning numbers to graphical character (computing), characters, especially the written characters of human language, allowing them to be stored, transmitted, and transformed using computers. The numerical v ...
s, there is a normal general-purpose space (Unicode character U+0020) whose width will vary according to the design of the typeface. Typical values range from 1/5 em to 1/3 em (in digital typography an em is equal to the nominal size of the font, so for a 10-point font the space will probably be between 2 and 3.3 points). Sophisticated fonts may have differently sized spaces for bold, italic, and small-caps faces, and often compositors will manually adjust the width of the space depending on the size and prominence of the text. In addition to this general-purpose space, it is possible to encode a space of a specific width. See the table below for a complete list.


Hair spaces around dashes

Em dash The dash is a punctuation mark consisting of a long horizontal line. It is similar in appearance to the hyphen but is longer and sometimes higher from the baseline. The most common versions are the endash , generally longer than the hyphen ...
es used as parenthetical dividers, and en dashes when used as word joiners, are usually set continuous with the text. However, such a dash can optionally be surrounded with a hair space, U+200A, or thin space, U+2009. The hair space can be written in HTML by using the
numeric character reference A numeric character reference (NCR) is a common markup construct used in SGML and SGML-derived markup languages such as HTML and XML. It consists of a short sequence of characters that, in turn, represents a single character. Since WebSgml, XM ...
s   or  , or the named entity  . The thin space is named entity   and numeric references   or  . These spaces are much thinner than a normal space (except in a monospaced (non-proportional) font), with the hair space in particular being the thinnest of horizontal whitespace characters.


Computing applications


Programming languages

In most
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
, whitespace characters can be used to separate tokens. For a free-form language, whitespace characters are ignored by code processors (i.e.
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
). Even when language syntax requires white space, often multiple whitespace characters are treated the same as a single. In an
off-side rule The off-side rule describes syntax of a computer programming language that defines the bounds of a code block via indentation. The term was coined by Peter Landin, possibly as a pun on the offside law in association football. An off-side ...
language,
indentation __FORCETOC__ In the written form of many languages, indentation describes empty space ( white space) used before or around text to signify an important aspect of the text such as: * Beginning of a paragraph * Hierarchy subordinate concept * Qu ...
white space is syntactically significant. In the
satirical Satire is a genre of the visual arts, visual, literature, literary, and performing arts, usually in the form of fiction and less frequently Nonfiction, non-fiction, in which vices, follies, abuses, and shortcomings are held up to ridicule, ...
and contrarian language called Whitespace, whitespace characters are the only significant characters and normal text is ignored. Good use of white space in
source code In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer. Since a computer, at base, only ...
can group related logic and make the code easier to understand. Excessive use of whitespace, including at the end of a line where it provides no rendering behavior, is considered a nuisance. Most languages only recognize whitespace characters that have an ASCII code. They disallow most or all of the Unicode codes listed above. The
C language C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities o ...
defines whitespace characters to be "space, horizontal tab, new-line, vertical tab, and form-feed". The
HTTP HTTP (Hypertext Transfer Protocol) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, wher ...
network protocol requires different types of whitespace to be used in different parts of the protocol, such as: only the space character in the status line, CRLF at the end of a line, and "linear whitespace" in header values.


Command-line parsing

Typical command-line parsers use the space character to
delimit A delimiter is a sequence of one or more Character (computing), characters for specifying the boundary between separate, independent regions in plain text, Expression (mathematics), mathematical expressions or other Data stream, data streams. An ...
arguments An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
. A value with an embedded space character is problematic since it causes the value to parse as multiple arguments. Typically, a parser allows for escaping the normal argument parsing by enclosing the text in quotes. Consider that one wants to list the files in directory named "foo bar". This command instead lists the files matching either "foo" or "bar": ls foo bar This command correctly specifies a single argument: ls "foo bar"


Markup languages

Some
markup language A markup language is a Encoding, text-encoding system which specifies the structure and formatting of a document and potentially the relationships among its parts. Markup can control the display of a document or enrich its content to facilitate au ...
s, such as
SGML The Standard Generalized Markup Language (SGML; International Organization for Standardization, ISO 8879:1986) is a standard for defining generalized markup languages for documents. ISO 8879 Annex A.1 states that generalized markup is "based on t ...
, preserve whitespace as written. Web markup languages such as
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
and
HTML Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
treat whitespace characters specially, including space characters, for programmers' convenience. One or more space characters read by conforming display-time processors of those markup languages are collapsed to 0 or 1 space, depending on their semantic context. For example, double (or more) spaces within text are collapsed to a single space, and spaces which appear on either side of the "=" that separates an attribute name from its value have no effect on the interpretation of the document. Element end tags can contain trailing spaces, and empty-element tags in XML can contain spaces before the "/>". In these languages, unnecessary whitespace increases the file size, and so may slow network transfers. On the other hand, unnecessary whitespace can also inconspicuously mark code, similar to, but less obvious than comments in code. This can be desirable to prove an infringement of license or copyright that was committed by copying and pasting. In XML attribute values, sequences of whitespace characters are treated as a single space when the document is read by a parser. Whitespace in XML element content is not changed in this way by the parser, but an application receiving information from the parser may choose to apply similar rules to element content. An XML document author can use the xml:space="preserve" attribute on an element to instruct the parser to discourage the downstream application from altering whitespace in that element's content. In most
HTML element An HTML element is a type of HTML (HyperText Markup Language) document component, one of several types of HTML nodes (there are also text nodes, comment nodes and others). The first used version of HTML was written by Tim Berners-Lee in 199 ...
s, a sequence of whitespace characters is treated as a single ''inter-word separator'', which may manifest as a single space character when rendering text in a language that normally inserts such space between words. Conforming HTML renderers are required to apply a more literal treatment of whitespace within a few prescribed elements, such as the pre tag and any element for which CSS has been used to apply pre-like whitespace processing. In such elements, space characters will not be "collapsed" into inter-word separators. In both XML and HTML, the
non-breaking space In word processing and digital typesetting, a non-breaking space (), also called NBSP, required space, hard space, or fixed space ...
character, along with other non-"standard" spaces, is not treated as collapsible "whitespace", so it is not subject to the rules above.


File names

Such usage is similar to multiword file names written for operating systems and applications that are confused by embedded space codes—such file names instead use an
underscore An underscore or underline is a line drawn under a segment of text. In proofreading, underscoring is a convention that says "set this text in italic type", traditionally used on manuscript or typescript as an instruction to the printer. Its ...
(_) as a word separator, as_in_this_phrase. Another such symbol was . This was used in the early years of computer programming when writing on coding forms.
Keypunch A keypunch is a device for precisely punching holes into stiff paper cards at specific locations as determined by keys struck by a human operator. Other devices included here for that same function include the gang punch, the pantograph punch, ...
operators immediately recognized the symbol as an "explicit space". It was used in
BCDIC BCD (''binary-coded decimal''), also called alphanumeric BCD, alphameric BCD, BCD Interchange Code, or BCDIC, is a family of representations of numerals, uppercase Latin letters, and some special and control characters as six-bit character code ...
,
EBCDIC Extended Binary Coded Decimal Interchange Code (EBCDIC; ) is an eight- bit character encoding used mainly on IBM mainframe and IBM midrange computer operating systems. It descended from the code used with punched cards and the corresponding si ...
, and
ASCII-1963 ASCII ( ), an acronym for American Standard Code for Information Interchange, is a character encoding standard for representing a particular set of 95 (English language focused) printable and 33 control characters a total of 128 code points. ...
.


See also

* Carriage return *
Em (typography) An em (from ''Quad (typography), em quadrat'') is a Typographic unit, unit in the field of typography, equal to the currently specified Point (typography), point size. It corresponds to the Body height (typography), body height of the typeface. F ...
*
En (typography) An en (from English '' en quadrat'') is a typographic unit, half of the width of an em. By definition, it is equivalent to half of the body height of the typeface (e.g., in 16- point type it is 8 points). The en is sometimes referred to as th ...
* Form feed *
Indent style In computer programming, indentation style is a convention or style, governing the indentation of lines of source code. An indentation style generally specifies a consistent number of whitespace characters before each line of a block, so that ...
*
Line feed A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
*
Newline A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
* Programming style *
Prosigns for Morse code Procedural signs or prosigns are shorthand signals used in Morse code telegraphy, for the purpose of simplifying and standardizing procedural protocols for landline and radio communication. The procedural signs are distinct from conventional Morse ...
* for the white-space character class. * Space bar *
Space (punctuation) In writing, a space () is a blank area that word divider, separates words, Sentence spacing, sentences, and other written or printed glyphs (characters). Conventions for spacing vary among languages, and in some languages the spacing rules are co ...
* Tab key * Trimming (computer programming) * Whitespace (programming language) *
Zero-width space The zero-width space (rendered: ; HTML entity: or ), abbreviated ZWSP, is a control character, non-printing character used in computerized typesetting to indicate where the word boundaries are, without actually displaying a visible space in the re ...


References


External links


Property List of Unicode Character Database
{{DEFAULTSORT:Whitespace (Computer Science) Character encoding Source code