Tuesday, 12 February 2013
‌“ ”
Double quotes (curly)
‘ ’  " "  ' '
Inverted commas  Typewriter double quotes  Typewriter single quotes
Punctuation
apostrophe ( ’ ' )
brackets ( [ ], ( ), { }, ⟨ ⟩ )
colon ( : )
comma ( , ، 、 )
dash ( , –, —, ― )
ellipsis ( …, ..., . . . )
exclamation mark ( ! )
full stop/period ( . )
guillemets ( « » )
hyphen ( )
hyphen-minus ( - )
question mark ( ? )
quotation marks ( ‘ ’, “ ”, ' ', " " )
semicolon ( ; )
slash‌/stroke‌/solidus ( /,  ⁄  )
Word dividers
space ( ) ( ) ( )
interpunct ( · )
General typography
ampersand ( & )
at sign ( @ )
asterisk ( * )
backslash ( \ )
bullet ( )
caret ( ^ )
dagger ( †, ‡ )
degree ( ° )
ditto mark ( )
inverted exclamation mark ( ¡ )
inverted question mark ( ¿ )
number sign‌/pound‌/hash ( # )
numero sign ( )
obelus ( ÷ )
ordinal indicator ( º, ª )
percent, per mil ( %, ‰, )
pilcrow ( )
prime ( ′, ″, ‴ )
section sign ( § )
tilde ( ~ )
underscore‌/understrike ( _ )
vertical bar‌/broken bar‌/pipe ( ¦, | )
Intellectual property
copyright symbol ( © )
registered trademark ( ® )
service mark ( )
sound recording copyright ( )
trademark ( )
Currency
currency (generic) ( ¤ )
currency (specific)
( ฿ ¢ $ ƒ £ ¥ )
Uncommon typography
asterism ( )
tee ( )
up tack ( )
index/fist ( )
therefore sign ( )
because sign ( )
interrobang ( )
irony punctuation ( ؟ )
lozenge ( )
reference mark ( )
tie ( )
Related
diacritical marks
whitespace characters
non-English quotation style ( « », „ ” )
In other scripts
Chinese punctuation
Wikipedia book Book  · Category Category  · Portal

In English writing, quotation marks or inverted commas (informally referred to as quotes or speech marks)[1] are punctuation marks surrounding a quotation, direct speech, or a literal title or name. Quotation marks can also be used to indicate a different meaning of a word or phrase than the one typically associated with it and are often used to express irony. Quotation marks are sometimes used to provide emphasis, although this is usually considered incorrect.[2][3]

Quotation marks are written as a pair of opening and closing marks in either of two styles: single (‘…’) or double (“…”). Opening and closing quotation marks may be identical in form (called neutral, vertical, straight, typewriter or "dumb" quotation marks), or may be distinctly left-handed and right-handed (typographic or, colloquially, curly quotation marks); see quotation mark glyphs for details. Typographic quotation marks are usually used in manuscript and typeset text. Because typewriter and computer keyboards lack keys to directly enter typographic quotation marks, much typed writing has neutral quotation marks. The “smart quotes” feature in some computer software can convert neutral quotation marks to typographic ones, but sometimes imperfectly.

The closing single quotation mark is identical or similar in form to the apostrophe and similar to the prime symbol. However, these three characters have quite different purposes. The double quotation mark is similar to, and often used to represent, the ditto mark.

Contents

History[link]

In the first centuries of typesetting, quotations were distinguished merely by indicating the speaker, and this can still be seen in some editions of the Bible. During the Renaissance, quotations were distinguished by setting in a typeface contrasting with the main body text (often Italic type with roman, or the other way around). Long quotations were also set this way, at full size and full measure.[4]

Quotation marks were first cut in metal type during the middle of the sixteenth century, and were used copiously by some printers by the seventeenth. In some Baroque and Romantic-period books, they would be repeated at the beginning of every line of a long quotation. When this practice was abandoned, the empty margin remained, leaving the modern form of indented block quotation.[4]

In Early Modern English, quotation marks were used only to denote pithy comments. They first began to quote direct speech in 1714. By 1749, single quotation marks, or inverted commas, were commonly used to denote direct speech.[5]

Usage[link]

Quotations and speech[link]

Single or double quotation marks denote either speech or a quotation. Double quotes are preferred in the United States, and also tend to be preferred in Canada, Australia and New Zealand. Single quotes are more usual in the United Kingdom and South Africa, though double quotes are also common there.[6] A publisher's or author's style may take precedence over regional general preferences. The important idea is that the style of opening and closing quotation marks must be matched:

'Good morning, Frank,' said Hal.
"Good morning, Frank," said Hal.

For speech within speech, the other style is used as inner quotation marks:

'Hal said, "Good morning, Dave,"' recalled Frank.
"Hal said, 'Good morning, Dave,'" recalled Frank.

Sometimes quotations are nested in more levels than inner and outer quotation. Nesting levels up to five can be found in the Christian Bible.[7] In these cases, questions arise about the form (and names) of the quotation marks to be used. The most common way is to simply alternate between the two forms,[8] thus:

"...'..."...' ... '..."...'..."

If such a passage is further quoted in another publication, then all of their forms have to be shifted up by one level.

In most cases, quotations that span multiple paragraphs should be set as block quotations, and thus do not require quotation marks. Quotation marks are used for multiple-paragraph quotations in some cases, especially in narratives. The convention in English is to give opening quotation marks to the first and each subsequent paragraph, using closing quotation marks only for the final paragraph of the quotation, as in the following example from Pride and Prejudice:

The letter was to this effect:

"My dear Lizzy,

"I wish you joy. If you love Mr. Darcy half as well as I do my dear Wickham, you must be very happy. It is a great comfort to have you so rich, and when you have nothing else to do, I hope you will think of us. I am sure Wickham would like a place at court very much, and I do not think we shall have quite money enough to live upon without some help. Any place would do, of about three or four hundred a year; but however, do not speak to Mr. Darcy about it, if you had rather not.

"Yours, etc."

As noted above, in some older texts, the quotation mark is repeated every line, rather than every paragraph. The Spanish convention uses closing quotation marks at the beginning of all subsequent paragraphs beyond the first.

When quoted text is interrupted, such as with the phrase he said, a closing quotation mark is used before the interruption, and an opening quotation mark after. Commas are also often used before and after the interruption, more often for quotations of speech than for quotations of text:

"Hal," noted Frank, "said that everything was going extremely well."

Quotation marks are not used for paraphrased speech. This is because a paraphrase is not a direct quote, and in the course of any composition, it is important to document when one is using a quotation versus when one is using a paraphrased idea, which could be open to interpretation.

If Hal says: "All systems are functional," then:

Incorrect: Hal said "everything was going extremely well."
Correct: Hal said that everything was going extremely well.

Irony[link]

Another common use of quotation marks is to indicate or call attention to ironic or apologetic words:

He shared his "wisdom" with me.
The lunch lady plopped a glob of "food" onto my tray.

Quotes indicating verbal irony, or other special use, are sometimes called scare, sneer, shock, distance, or horror quotes. They are sometimes gestured in oral speech using air quotes, or indicated in speech with a tone change or by replacement with supposed[ly] or so-called.

Signaling unusual usage[link]

Quotation marks are also used to indicate that the writer realizes that a word is not being used in its current commonly accepted sense:

Crystals somehow "know" which shape to grow into.

In addition to conveying a neutral attitude and to call attention to a neologism, or slang, or special terminology (also known as jargon), quoting can also indicate words or phrases that are descriptive but unusual, colloquial, folksy, startling, humorous, metaphoric, or contain a pun: Dawkins's concept of a meme could be described as an "evolving idea".

People also use quotation marks in this way to distance the writer from the terminology in question so as not to be associated with it, for example to indicate that a quoted word is not official terminology, or that a quoted phrase presupposes things that the author does not necessarily agree with; or to indicate special terminology that should be identified for accuracy's sake as someone else's terminology, as when a term (particularly a controversial term) pre-dates the writer or represents the views of someone else, perhaps without judgement (contrast this neutrally-distancing quoting to the negative use of scare quotes).

The Chicago Manual of Style, 15th edition,[9] acknowledges this type of use but, in section 7.58, cautions against its overuse: "Quotation marks are often used to alert readers that a term is used in a nonstandard, ironic, or other special sense... [T]hey imply ‘This is not my term,’ or ‘This is not how the term is usually applied.’ Like any such device, scare quotes lose their force and irritate readers if overused."

Use–mention distinction[link]

Either quotation marks or italic type can emphasize that an instance of a word refers to the word itself rather than its associated concept.

Cheese is derived from milk.
"Cheese" is derived from a word in Old English.
Cheese has calcium, protein, and phosphorus.
Cheese has three e's.

A three-way distinction is occasionally made between normal use of a word (no quotation marks), referring to the concept behind the word (single quotation marks), and the word itself (double quotation marks):

When discussing 'use', use "use".

The logic for this derives from the need to distinguish use forms, coupled with the mandate to retain consistent notation for like use forms.[10] The switching between double and single quotes in nested citation quotes reveals the same literary device for reducing ambiguity.

Writing about language often uses italics for the word itself and single quotation marks for a gloss, with the two not separated by a comma or other punctuation, and with strictly logical quotation around the gloss – extraneous terminal punctuation outside the quotation marks – even in North American publications, which might otherwise prefer them inside:[11]

Latin ovis 'sheep', canis 'dog', and equus 'horse' are nouns.[11]

Titles of artistic works[link]

Quotation marks, rather than italics, are generally used for the titles of shorter works. Whether these are single or double depends on the context; however, many styles, especially for poetry, prefer the use of single quotation marks.

  • Short fiction, poetry, etc.: Arthur C. Clarke's "The Sentinel"
  • Book chapters: The first chapter of 3001: The Final Odyssey is "Comet Cowboy"
  • Articles in books, magazines, journals, etc.: "Extra-Terrestrial Relays", Wireless World, October 1945
  • Album tracks, singles, etc.: David Bowie's "Space Oddity"

As a rule, a whole publication would be italicised, whereas the titles of minor works within or a subset of the larger publication (such as poems, short stories, named chapters, journal papers, newspaper articles, TV show episodes, editorial sections of websites, etc.) would be written with quotation marks.

  • Shakespeare's Romeo and Juliet
  • Dahl's "Taste" in Completely Unexpected Tales

Nicknames and false titles[link]

Quotation marks can also offset a nickname embedded in an actual name, or a false or ironic title embedded in an actual title; for example, Nat "King" Cole, Miles "Tails" Prower, or John "Hannibal" Smith.

Nonstandard usage[link]

Quotes are sometimes used for emphasis in lieu of underlining or italics, most commonly on signs or placards. This usage can be confused with ironic or altered-usage quotation, sometimes with unintended humor. For example, For sale: "fresh" fish, "fresh" oysters, could be construed to imply that fresh is not used with its everyday meaning, or indeed to indicate that the fish or oysters are anything but fresh. As another example, Cashiers' desks open until noon for your "convenience" could be interpreted to mean that the convenience was for the bank employees, not the customers.[2][3]

Typographical considerations[link]

Punctuation[link]

With regard to quotation marks adjacent to periods and commas, there are two styles of punctuation in widespread use. While these two styles are most commonly referred to as "American" and "British" and some style sheets provide no other names, some American writers and organizations use the "British" style and vice versa. Both systems have the same rules regarding question marks, exclamation points, colons and semicolons. They differ on the treatment of periods and commas.

In all major forms of English, question marks and exclamation marks are placed inside or outside quoted material depending on whether they apply to the whole sentence or just the quoted portion, but colons and semicolons are always placed outside.[12]

  • Did he say, "Good morning, Dave"?
  • No, he said, "Where are you, Dave?"
  • There are three major definitions of the word "gender": vernacular, sociological, and linguistic.

The prevailing style in the United Kingdom—called British style,[13] logical quotation[14][15]—is to include within quotation marks only those punctuation marks that appeared in the quoted material but otherwise to place punctuation outside the closing quotation marks.[15] Fowler's A Dictionary of Modern English Usage provides an early example of the rule: "All signs of punctuation used with words in quotation marks must be placed according to the sense."[16] When dealing with words-as-words, short-form works and sentence fragments, this style places periods and commas outside the quotation marks:

  • "Carefree", in general, means "free from care or anxiety".
  • The name of the song was "Gloria", which many already knew.
  • She said she felt "free from care and anxiety".

When dealing with direct speech, British placement depends on whether or not the quoted statement is complete or a fragment. According to the British style guide Butcher's Copy-editing, American style should be used when writing fiction.[17] In non-fiction, some British publishers may permit placing punctuation that is not part of the person's speech inside the quotation marks but prefer that it be placed outside.[17] Periods and commas that are part of the person's speech are permitted inside the quotation marks regardless of whether the material is fiction.[17]

  • "Today," said Cinderella, "I feel free from care and anxiety." (fiction)
  • "Today", said the Prime Minister, "I feel free from care and anxiety." (preferred in non-fiction)
  • "Today I feel happy," said the woman, "carefree, and well." (regardless)

In the U.S., the prevailing style is called American style,[13] whereby commas and periods are almost always placed inside closing quotation marks.[18] This style of punctuation is common in the U.S. and Canada, and is the style usually recommended by The Chicago Manual of Style and most other American style guides. However, many American style guides specific to certain specialties, such as legal writing and linguistics, prefer British style.[19][20]

When dealing with words-as-words, short-form works and sentence fragments, this style places periods and commas inside the quotation marks:

  • "Carefree," in general, means "free from care or anxiety."
  • The name of the song was "Gloria," which many already knew.
  • She said she felt "free from care and anxiety."

This style also places periods and commas inside the quotation marks when dealing with direct speech, regardless of whether the work is fiction or non-fiction:

  • "Today," said Cinderella, "I feel free from care and anxiety." (fiction)
  • "Today," said the Prime Minister, "I feel free from care and anxiety." (non-fiction)

Many American style guides explicitly permit periods and commas outside the quotation marks when the presence of the punctuation mark inside the quotation marks will lead to ambiguity, such as when describing keyboard input:

  • To use a long dash on Wikipedia, type in "—".
  • It should look like this: —

In both major styles, regardless of placement, only one end mark (?, !, or .) can end a sentence. Only the period, however, may not end a quoted sentence when it does not also end the enclosing sentence, except for literal text:[21]

  • "Hello, world," she said. (American style)
  • "Hello, world", she said. (British non-fiction)
  • She said, "Hello, world." (both styles)
  • "Hello, world!" she exclaimed. (both styles)
  • "Is there anybody out there?" she asked into the void. (both styles)

Spacing[link]

In English, when a quotation follows other writing on a line of text, a space precedes the opening quotation mark unless the preceding symbol, such as an em dash, requires that there be no space. When a quotation is followed by other writing on a line of text, a space follows the closing quotation mark unless it is immediately followed by other punctuation within the sentence, such as a colon or closing punctuation. (These exceptions are ignored by some Asian computer systems that systematically display quotation marks with the included spacing, as this spacing is part of the fixed-width characters.)

There is generally no space between an opening quotation mark and the following word, or a closing quotation mark and the preceding word. When a double quotation mark or a single quotation mark immediately follows the other, proper spacing for legibility may suggest that a non-breaking space ( ) or thin space ( ) be inserted.

So Dave actually said, "He said, 'Good morning' "?
Yes, he did say, "He said, 'Good morning.' "

This is not common practice in mainstream publishing, which will generally use more precise kerning. It is common in online writing, though using CSS to create the spacing by kerning is more semantically appropriate in Web typography than inserting extraneous spacing characters.

Non-language related usage[link]

Straight quotation marks (or italicized straight quotation marks) are often used to approximate the prime and double prime, e. g., when signifying feet and inches, arcminutes and arcseconds or minutes and seconds, where the quotation mark symbolises the latter part of the pair. For instance, 5 feet and 6 inches is often written 5' 6"; and 40 degrees, 20 arcminutes, and 50 arcseconds is written 40° 20' 50". When available, however, the prime should be used instead (e. g., 5′ 6″, and 40° 20′ 50″). Prime and double prime are not present in most code pages, including ASCII and Latin-1, but are present in Unicode, as characters U+2032 prime and U+2033 double prime.

Double quotation marks, or pairs of single ones, are also often used to represent the ditto mark.

Straight single and double quotation marks are used in most programming languages to delimit strings or literal characters, collectively known as string literals. In some languages (e.g. Pascal) only one type is allowed, in some (e.g. C and its derivatives) both are used with different meanings and in others (e.g. Python) both are used interchangeably. In some languages, if it is desired to include the same quotation marks used to delimit a string inside the string, the quotation marks are doubled. For example, to represent the string eat 'hot' dogs in Pascal one uses 'eat ''hot'' dogs'. Other languages use an escape character, often the backslash, as in 'eat \'hot\' dogs'.

Typing quotation marks on a computer keyboard[link]

Standard English computer keyboard layouts inherited the single and double straight quotation marks from the typewriter (the single quotation mark also doubling as an apostrophe), and they do not include individual keys for left-handed and right-handed typographic quotation marks. However, most computer text-editing programs provide a "smart quotes" feature (see below) to automatically convert straight quotation marks into typographic punctuation. Generally, this smart quote feature is enabled by default. Some websites do not allow typographic quotation marks or apostrophes in posts (one such example being YouTube). One can skirt these limitations, however, by using the HTML character codes or entities (though not on YouTube).[22]

How to type quotation marks (and apostrophes) on a computer keyboard
  Macintosh key combinations Windows key combinations Linux (X) keys Unicode point HTML entity HTML decimal
Single opening    Opt+] Alt+0145 (on number pad) Compose+<+' or Alt Gr+ Shift+V U+2018 &lsquo; &#8216;
Single closing
(& apostrophe[23][24])
   Opt+ Shift+] Alt+0146 (on number pad) Compose+>+' or Alt Gr+ Shift+B U+2019 &rsquo; &#8217;
Double opening    Opt+[ Alt+0147 (on number pad) Compose+<+" or Alt Gr+V U+201C &ldquo; &#8220;
Double closing    Opt+ Shift+[ Alt+0148 (on number pad) Compose+>+" or Alt Gr+B U+201D &rdquo; &#8221;

Smart quotes[link]

To make typographic quotation marks easier to enter, publishing software often automatically converts typewriter quotation marks (and apostrophes) to typographic form during text entry (with or without the users being aware of it). These are known as smart quotes (“ ”). Straight quotation marks are also known as dumb quotes (" ").[25] Some word processing programs incorrectly produce an opening single quotation mark in places where an apostrophe is required, for example, in abbreviated years like ‘08 for 2008, or ‘tis for It is.

See also[link]

Notes[link]

  1. ^ Barber, 2004.
  2. ^ a b English Department, 1999.
  3. ^ a b Language Log: Dubious quotation marks
  4. ^ a b Bringhurst (2002), p 86.
  5. ^ Truss, Lynne. Eats, Shoots & Leaves, 2003. p. 151. ISBN 1-59240-087-6.
  6. ^ The Penguin Guide to Punctuation, R. L. Trask, p. 94.
  7. ^ Jeremiah 27:1-11; 29:1-28; 29:30-32; 34:1-5; Ezekiel 27:1-36
  8. ^ Stilman, Ann. Grammatically Correct, 1997. p. 181. ISBN 978-0-89879-776-3.
  9. ^ "The Chicago Manual of Style Online". http://www.chicagomanualofstyle.org/home.html. Retrieved 2007-11-08. 
  10. ^ Butcher, J.; Drake, C.; Leach, M. (2006). Butcher's Copy-Editing: The Cambridge Handbook for Editors, Copy-Editors and Proofreaders (4th ed ed.). Cambridge, England: Cambridge University Press. 
  11. ^ a b "Language Style Sheet". Language. Washington, DC, US: Linguistic Society of America. 2011. http://www.lsadc.org/info/pubs-lang-style.cfm. Retrieved 2011-10-23. "After the first occurrence of non-English forms, provide a gloss in single quotation marks: Latin ovis 'sheep' is a noun. No comma precedes the gloss and no comma follows, unless necessary for other reasons: Latin ovis ‘sheep’, canis ‘dog’, and equus ‘horse’ are nouns." 
  12. ^ TJHSST[dead link]
  13. ^ a b "Punctuating Around Quotation Marks" (blog). Style Guide of the American Psychological Association. 2011. http://blog.apastyle.org/apastyle/2011/08/punctuating-around-quotation-marks.html. Retrieved 2011-10-25. 
  14. ^ "Journal of Irish and Scottish Studies – Style Guide" (PDF). U. of Aberdeen, Scotland: Research Institute of Irish and Scottish Studies. 2008. http://www.abdn.ac.uk/riiss/Documents/JISS%20Style%20Guide%20revised%20FV.pdf. Retrieved 2011-10-22. "Punctuation marks are placed inside the quotation marks only if the sense of the punctuation is part of the quotation; this system is referred to as logical quotation." 
  15. ^ a b Ben Yagoda (12 May 2011). "The Rise of "Logical Punctuation".". Slate. http://www.slate.com/id/2293056/. Retrieved 13 May 2011. 
  16. ^ Burchfield, R.W., ed. (1996). The New Fowler's Modern English Usage (3rd ed.). Oxford University Press. p. 646.  Emphasis in original.
  17. ^ a b c Butcher, Judith; et al. (2006). Butcher's Copy-editing: The Cambridge Handbook for Editors, Copy-editors and Proofreaders. Cambridge, England: Cambridge University Press. p. 273. ISBN 978-0-521-84713-1. 
  18. ^ The Associated Press Stylebook, p. 337; The Chicago Manual of Style, 15th ed., ch. 6.9, pp. 242–243, http://www.chicagomanualofstyle.org/CMS_FAQ/Punctuation/Punctuation50.html; Strunk, William Jr., and White, E. B. ,The Elements of Style, Pearson Education Company, 4th ed., p. 36; McFarlane and Warren Clements. The Globe and Mail Style Book, 9th ed., p. 237; Brinck, Tom, et al., Usability for the Web, Morgan Kaufmann, 2002, p. 277.
  19. ^ As just two examples, The ABA Journal of the American Bar Association has preferred logical quotation since at least as early as 1951, and the journal Language of the Linguistic Society of America also requires logical quotation.
  20. ^ Stephen Wilbers. "Frequently Asked Questions Concerning Punctuation*" (web site). http://www.wilbers.com/FAQPunctuation.htm. Retrieved 2011-10-25. 
  21. ^ The Chicago Manual of Style, 15th edition; Hart's Rules for Compositors and Readers at the University Press, Oxford; Merriam-Webster's Guide to Punctuation and Style, second edition.
  22. ^ See the WWW Consortium tables here.
  23. ^ http://www.fileformat.info/info/unicode/char/2019/index.htm
  24. ^ http://www.unicode.org/charts/PDF/U2000.pdf
  25. ^ David Spencer (31 January 2011). "Typographic Train Wrecks". Type Desk. Matador. http://typedesk.com/2011/01/31/typographic-train-wrecks/. Retrieved 31 January 2011. 

References[link]

External links[link]

This article is based on material taken from the Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the GFDL, version 1.3 or later.

http://wn.com/Quotation_mark

Related pages:

http://it.wn.com/Virgolette

http://cs.wn.com/Uvozovky

http://id.wn.com/Tanda petik

http://es.wn.com/Comillas

http://ru.wn.com/Кавычки

http://nl.wn.com/Aanhalingsteken

http://pl.wn.com/Cudzysłów

http://fr.wn.com/Guillemet

http://de.wn.com/Anführungszeichen

http://pt.wn.com/Aspas




This page contains text from Wikipedia, the Free Encyclopedia - http://en.wikipedia.org/wiki/Quotation_mark

This article is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License, which means that you can copy and modify it as long as the entire work (including additions) remains under this license.


Text file created with gedit and viewed with a hex editor
Besides the text objects there are only EOL markers
with the hexadecimal value 0A.

In computing, a newline,[1] also known as a line break or end-of-line (EOL) marker, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line—that is, on the next line below the text immediately preceding the newline. The actual codes representing a newline vary across operating systems, which can be a problem when exchanging text files between systems with different newline representations.

There is also some confusion whether newlines terminate or separate lines. If a newline is considered a separator, there will be no newline after the last line of a file. The general convention on most systems is to add a newline even after the last line, i.e. to treat newline as a line terminator. Some programs have problems processing the last line of a file if it is not newline terminated. Conversely, programs that expect newline to be used as a separator will interpret a final newline as starting a new (empty) line.

In text intended primarily to be read by humans using software which implements the word wrap feature, a newline character typically only needs to be stored if a line break is required independent of whether the next word would fit on the same line, such as between paragraphs and in vertical lists. See hard return and soft return.

Contents

Representations[link]

Software applications and operating systems usually represent a newline with one or two control characters:

  • Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A, 10 in decimal) or CR (Carriage return, '\r', 0x0D, 13 in decimal) individually, or CR followed by LF (CR+LF, '\r\n', 0x0D0A). These characters are based on printer commands: The line feed indicated that one line of paper should feed out of the printer thus instructed the printer to advance the paper one line, and a carriage return indicated that the printer carriage should return to the beginning of the current line. Some rare systems, such as QNX before version 4, used the ASCII RS (record separator, 0x1E, 30 in decimal) character as the newline character.
  • EBCDIC systems—mainly IBM mainframe systems, including z/OS (OS/390) and i5/OS (OS/400)—use NEL (Next Line, 0x15) as the newline character. Note that EBCDIC also has control characters called CR and LF, but the numerical value of LF (0x25) differs from the one used by ASCII (0x0A). Additionally, there are some EBCDIC variants that also use NEL but assign a different numeric code to the character.
  • Operating systems for the CDC 6000 series defined a newline as two or more zero-valued six-bit characters at the end of a 60-bit word. Some configurations also defined a zero-valued character as a colon character, with the result that multiple colons could be interpreted as a newline depending on position.
  • ZX80 and ZX81, home computers from Sinclair Research Ltd used a specific non-ASCII character set with code NEWLINE (0x76, 118 decimal) as the newline character.
  • OpenVMS uses a record-based file system, which stores text files as one record per line. In most file formats, no line terminators are actually stored, but the Record Management Services facility can transparently add a terminator to each line when it is retrieved by an application. The records themselves could contain the same line terminator characters, which could either be considered a feature or a nuisance depending on the application.
  • Fixed line length was used by some early mainframe operating systems. In such a system, an implicit end-of-line was assumed every 80 characters, for example. No newline character was stored. If a file was imported from the outside world, lines shorter than the line length had to be padded with spaces, while lines longer than the line length had to be truncated. This mimicked the use of punched cards, on which each line was stored on a separate card, usually with 80 columns on each card. Many of these systems added an carriage control character to the start of the next record, this could indicate if the next record was a continuation of the line started by the previous record, or a new line, or should overprint the previous line (similar to a CR). Often this was a normal printing character such as '#' that thus could not be used as the first character in a line. Some early line printers interpreted these characters directly in the records sent to them.

Most textual Internet protocols (including HTTP, SMTP, FTP, IRC and many others) mandate the use of ASCII CR+LF (0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF as well. In practice, there are many applications that erroneously use the C newline character '\n' instead (see section Newline in programming languages below). This leads to problems when trying to communicate with systems adhering to a stricter interpretation of the standards; one such system is the qmail MTA that actively refuses to accept messages from systems that send bare LF instead of the required CR+LF.[2]

FTP has a feature to transform newlines between CR+LF and LF only when transferring text files. This must not be used on binary files. Usually binary files and text files are recognised by checking their filename extension.

Unicode[link]

The Unicode standard defines a large number of characters that conforming applications should recognize as line terminators:[3]

 LF:    Line Feed, U+000A
 VT:    Vertical Tab, U+000B
 FF:    Form Feed, U+000C
 CR:    Carriage Return, U+000D
 CR+LF: CR (U+000D) followed by LF (U+000A)
 NEL:   Next Line, U+0085
 LS:    Line Separator, U+2028
 PS:    Paragraph Separator, U+2029

This may seem overly complicated compared to an approach such as converting all line terminators to a single character, for example LF. However, Unicode was designed to preserve all information when converting a text file from any existing encoding to Unicode and back. Therefore, Unicode should contain characters included in existing encodings. NEL is included in ISO-8859-1[citation needed] and EBCDIC (0x15). The approach taken in the Unicode standard allows round-trip transformation to be information-preserving while still enabling applications to recognize all possible types of line terminators.

Recognizing and using the newline codes greater than 0x7F is not often done. They are multiple bytes in UTF-8 and the code for NEL has been used as the ellipsis ('…') character in Windows-1252. For instance:

  • YAML[4] no longer recognizes them as special in order to be compatible with JSON.
  • ECMAScript[5] accepts LS and PS as line breaks, but considers U+0085 (NEL) white space, not a line break.
  • Microsoft Windows 2000 does not treat any of NEL, LS or PS as line-break in the default text editor Notepad
  • In Linux, a popular editor "gedit" treats LS and PS as newlines but does not for NEL.

History[link]

ASCII was developed simultaneously by the ISO and the ASA, the predecessor organization to ANSI. During the period of 1963–1968, the ISO draft standards supported the use of either CR+LF or LF alone as a newline, while the ASA drafts supported only CR+LF.

The sequence CR+LF was in common use on many early computer systems that had adopted Teletype machines, typically a Teletype Model 33 ASR, as a console device, because this sequence was required to position those printers at the start of a new line. On these systems, text was often routinely composed to be compatible with these printers, since the concept of device drivers hiding such hardware details from the application was not yet well developed; applications had to talk directly to the Teletype machine and follow its conventions.

Most minicomputer systems from DEC used this convention. CP/M used it as well, to print on the same terminals that minicomputers used. From there MS-DOS (1981) adopted CP/M's CR+LF in order to be compatible, and this convention was inherited by Microsoft's later Windows operating system.

The separation of the two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. In fact, it was often necessary to send extra characters (extraneous CRs or NULs, which are ignored) to give the print head time to move to the left margin. Even many early video displays required multiple character times to scroll the display.

The Multics operating system began development in 1964 and used LF alone as its newline. Multics used a device driver to translate this character to whatever sequence a printer needed (including extra padding characters), and the single byte was much more convenient for programming. The seemingly more obvious choice of CR was not used, as a plain CR provided the useful function of overprinting one line with another, and thus it was useful to not translate it. Unix followed the Multics practice, and later systems followed Unix.

In programming languages[link]

To facilitate the creation of portable programs, programming languages provide some abstractions to deal with the different types of newline sequences used in different environments.

The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:

  1. Each of these escape sequences maps to a unique implementation-defined number that can be stored in a single char value.
  2. When writing a file in text mode, '\n' is transparently translated to the native newline sequence used by the system, which may be longer than one character. When reading in text mode, the native newline sequence is translated back to '\n'. In binary mode, no translation is performed, and the internal representation produced by '\n' is output directly.

On Unix platforms, where C originated, the native newline sequence is ASCII LF (0x0A), so '\n' was simply defined to be that value. With the internal and external representation being identical, the translation performed in text mode is a no-op, and text mode and binary mode behave the same. This has caused many programmers who developed their software on Unix systems simply to ignore the distinction completely, resulting in code that is not portable to different platforms.

The C library function fgets() is best avoided in binary mode because any file not written with the UNIX newline convention will be misread. Also, in text mode, any file not written with the system's native newline sequence (such as a file created on a UNIX system, then copied to a Windows system) will be misread as well.

Another common problem is the use of '\n' when communicating using an Internet protocol that mandates the use of ASCII CR+LF for ending lines. Writing '\n' to a text mode stream works correctly on Windows systems, but produces only LF on Unix, and something completely different on more exotic systems. Using "\r\n" in binary mode is slightly better.

Many languages, such as C++, Perl,[6] and Haskell provide the same interpretation of '\n' as C.

Java, PHP,[7] and Python[8] provide the '\r\n' sequence (for ASCII CR+LF). In contrast to C, these are guaranteed to represent the values U+000A and U+000D, respectively.

The Java I/O libraries do not transparently translate these into platform-dependent newline sequences on input or output. Instead, they provide functions for writing a full line that automatically add the native newline sequence, and functions for reading lines that accept any of CR, LF, or CR+LF as a line terminator (see BufferedReader.readLine()). The System.getProperty() method can be used to retrieve the underlying line separator.

Example:

  String eol = System.getProperty( "line.separator" );
  String lineColor = "Color: Red" + eol;

Python permits "Universal Newline Support" when opening a file for reading, when importing modules, and when executing a file.[9]

Some languages have created special variables, constants, and subroutines to facilitate newlines during program execution.

Common problems[link]

The different newline conventions often cause text files that have been transferred between systems of different types to be displayed incorrectly. For example, files originating on Unix or Apple Macintosh systems may appear as a single long line on some Windows programs. Conversely, when viewing a file originating from a Windows computer on a Unix system, the extra CR may be displayed as ^M at the end of each line or as a second line break.

The problem can be hard to spot if some programs handle the foreign newlines properly while others do not. For example, a compiler may fail with obscure syntax errors even though the source file looks correct when displayed on the console or in an editor. On a Unix system, the command cat -v myfile.txt will send the file to stdout (normally the terminal) and make the ^M visible, which can be useful for debugging. Modern text editors generally recognize all flavours of CR / LF newlines and allow the user to convert between the different standards. Web browsers are usually also capable of displaying text files and websites which use different types of newlines.

The File Transfer Protocol can automatically convert newlines in files being transferred between systems with different newline representations when the transfer is done in "ASCII mode". However, transferring binary files in this mode usually has disastrous results: Any occurrence of the newline byte sequence—which does not have line terminator semantics in this context, but is just part of a normal sequence of bytes—will be translated to whatever newline representation the other system uses, effectively corrupting the file. FTP clients often employ some heuristics (for example, inspection of filename extensions) to automatically select either binary or ASCII mode, but in the end it is up to the user to make sure his or her files are transferred in the correct mode. If there is any doubt as to the correct mode, binary mode should be used, as then no files will be altered by FTP, though they may display incorrectly.

Conversion utilities[link]

Text editors are often used for converting a text file between different newline formats; most modern editors can read and write files using at least the different ASCII CR/LF conventions. The standard Windows editor Notepad is not one of them (although Wordpad and the MS-DOS Editor are).

Editors are often unsuitable for converting larger files. For larger files (on Windows NT/2000/XP) the following command is often used:

TYPE unix_file | FIND "" /V > dos_file

On many Unix systems, the dos2unix (sometimes named fromdos or d2u) and unix2dos (sometimes named todos or u2d) utilities are used to translate between ASCII CR+LF (DOS/Windows) and LF (Unix) newlines. Different versions of these commands vary slightly in their syntax. However, the tr command is available on virtually every Unix-like system and is used to perform arbitrary replacement operations on single characters. A DOS/Windows text file can be converted to Unix format by simply removing all ASCII CR characters with

tr -d '\r' < inputfile > outputfile

or, if the text has only CR newlines, by converting all CR newlines to LF with

tr '\r' '\n' < inputfile > outputfile

The same tasks are sometimes performed with awk, sed, Tr_(Unix) or in Perl if the platform has a Perl interpreter:

awk '{sub("$","\r\n"); printf("%s",$0);}' inputfile > outputfile  # UNIX to DOS  (adding CRs on Linux and BSD based OS that haven't GNU extensions)
awk '{gsub("\r",""); print;}' inputfile > outputfile              # DOS to UNIX  (removing CRs on Linux and BSD based OS that haven't GNU extensions)
sed -e 's/$/\r/' inputfile > outputfile              # UNIX to DOS  (adding CRs on Linux based OS that use GNU extensions)
sed -e 's/\r$//' inputfile > outputfile              # DOS  to UNIX (removing CRs on Linux based OS that use GNU extensions)
cat inputfile | tr -d "\r" > outputfile              # DOS  to UNIX (removing CRs using tr(1). Not Unicode compliant.)
perl -pe 's/\r?\n|\r/\r\n/g' inputfile > outputfile  # Convert to DOS
perl -pe 's/\r?\n|\r/\n/g'   inputfile > outputfile  # Convert to UNIX
perl -pe 's/\r?\n|\r/\r/g'   inputfile > outputfile  # Convert to old Mac

To identify what type of line breaks a text file contains, the file command can be used. Moreover, the editor Vim can be convenient to make a file compatible with the Windows notepad text editor. For example:

[prompt] > file myfile.txt
myfile.txt: ASCII English text
[prompt] > vim myfile.txt
  within vim :set fileformat=dos
             :wq
[prompt] > file myfile.txt
myfile.txt: ASCII English text, with CRLF line terminators

The following grep commands echo the filename (in this case myfile.txt) to the command line if the file is of the specified style:

grep -PL $'\r\n' myfile.txt # show UNIX style file (LF terminated)
grep -Pl $'\r\n' myfile.txt # show DOS style file (CRLF terminated)

For Debian-based systems, these commands are used:

egrep -L $'\r\n' myfile.txt # show UNIX style file (LF terminated)
egrep -l $'\r\n' myfile.txt # show DOS style file (CRLF terminated)

The above grep commands work under Unix systems or in Cygwin under Windows. Note that these commands make some assumptions about the kinds of files that exist on the system (specifically it's assuming only UNIX and DOS-style files—no Mac OS 9-style files).

This technique is often combined with find to list files recursively. For instance, the following command checks all "regular files" (e.g. it will exclude directories, symbolic links, etc.) to find all UNIX-style files in a directory tree, starting from the current directory (.), and saves the results in file unix_files.txt, overwriting it if the file already exists:

find . -type f -exec grep -PL '\r\n' {} \; > unix_files.txt

This example will find C files and convert them to LF style line endings:

find -name '*.[ch]' -exec fromdos {} \;

The file command also detects the type of EOL used:

file myfile.txt
> myfile.txt: ASCII text, with CRLF line terminators

Other tools permit the user to visualise the EOL characters:

od -a myfile.txt
cat -e myfile.txt
hexdump -c myfile.txt

dos2unix, unix2dos, mac2unix, unix2mac, mac2dos, dos2mac can perform conversions. The flip[10] command is often used.

See also[link]

References[link]

  1. ^ The origin of the older computer term "CRLF" - which redirects to this Newline article - or "Carriage Return [and] Line Feed", derives from standard manual typewriter design, whereby at the end of a line of text the typist pushes a lever at the left end of the carriage to return it to position for beginning the next line. In so doing, a mechanism also rolls the typewriter's platen by one line, advancing ("feeding") the paper to the correct position.
  2. ^ cr.yp.to
  3. ^ UTR #13: Unicode Newline Guidelines
  4. ^ YAML Ain't Markup Language (YAML™) Version 1.2
  5. ^ "ECMAScript Language Specification 5th edition". ECMA International. December 2009. p. 15. http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf. Retrieved 4 April 2010. 
  6. ^ binmode - perldoc.perl.org
  7. ^ PHP: Strings - Manual
  8. ^ Lexical analysis – Python v3.0.1 documentation
  9. ^ What's new in Python 2.3
  10. ^ ASCII text converstion between UNIX, Macintosh, MS-DOS

External links[link]

http://wn.com/Newline

Related pages:

http://ru.wn.com/Перевод строки

http://fr.wn.com/Fin de ligne

http://pt.wn.com/Nova linha

http://de.wn.com/Zeilenumbruch

http://it.wn.com/Newline

http://pl.wn.com/End-of-line

http://cs.wn.com/Nový řádek

http://es.wn.com/Nueva línea




This page contains text from Wikipedia, the Free Encyclopedia - http://en.wikipedia.org/wiki/Newline

This article is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License, which means that you can copy and modify it as long as the entire work (including additions) remains under this license.