Knowledge

Line wrap and word wrap

Source 📝

36: 283:, that are appropriate places in which to begin a new line. The actual line break positions are picked from among the break opportunities by the higher level software that calls the algorithm, not by the algorithm itself, because only the higher level software knows about the width of the display the text is displayed on and the width of the glyphs that make up the displayed text. 764:"The reflow algorithm tries to keep the lines the same length but also tries to break at punctuation, and avoid breaking within a proper name or after certain connectives ("a", "the", etc.). The result is a file with a more "ragged" right margin than is produced by fmt or Text::Wrap but it is easier to read since fewer phrases are broken across line breaks." 114:
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
102:
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
327:
in it. When the word isn't wrapped (i.e., isn't broken across lines), the soft hyphen isn't visible. But if the word is wrapped across lines, this is done at the soft hyphen, at which point it is shown as a visible hyphen on the top line where the word is broken. (In the rare case of a word that
780:"The detailed description of the model and the algorithm can be found on the paper "Breaking Paragraphs into Lines" by Donald E. Knuth, published in the book "Digital Typography" (Stanford, California: Center for the Study of Language and Information, 1999), (CSLI Lecture Notes, no. 78.)"; part of 223:
Alternatively, "soft return" can mean an intentional, stored line break that is not a paragraph break. For example, it is common to print postal addresses in a multiple-line format, but the several lines are understood to be a single paragraph. Line breaks are needed to divide the words of the
210:
A soft return or soft wrap is the break resulting from line wrap or word wrap (whether automatic or manual), whereas a hard return or hard wrap is an intentional break, creating a new paragraph. With a hard return, paragraph-break formatting can (and should) be applied (either
438:
SpaceLeft := LineWidth for each Word in Text if (Width(Word) + SpaceWidth) > SpaceLeft insert line break before Word in Text SpaceLeft := LineWidth - Width(Word) else SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth)
246:) between each paragraph. Formatting settings, such as first-line indentation or spacing between paragraphs, take effect where the carriage return marks the break. A non-paragraph line break, which is a soft return, is inserted using 215:
or vertical whitespace). Soft wrapping allows line lengths to adjust automatically with adjustments to the width of the user's window or margin settings, and is a standard feature of all modern text editors, word processors, and
480:, minimizes the sum of the squares of the lengths of the spaces at the end of lines to produce a more aesthetically pleasing result than the greedy algorithm, which does not always minimize squared space. 431:
that puts as many words on a line as possible, then moving on to the next line to do the same until there are no more words left to place. This method is used by many modern word processors, such as
58: 435:
and Microsoft Word. This algorithm always uses the minimum possible number of lines but may lead to lines of widely varying lengths. The following pseudocode implements this algorithm:
814:... The *really* interesting thing is how Adobe's algorithm differs from the Knuth–Plass algorithm. It must differ, since Adobe has managed to patent its algorithm (6,510,441)." 496:. In the Western Union system, each line was broken at the first space character to appear after the 58th character, or at the 70th character if no space character was found. 308:
The soft returns are usually placed after the ends of complete words, or after the punctuation that follows complete words. However, word wrap may also occur following a
781: 175:
is continuing on a new line when a line is full, so that each line fits into the viewable window, allowing text to be read from top to bottom without any horizontal
618: 260:
or via the menus, and is provided for cases when the text should start on a new line but none of the other side effects of starting a new paragraph are desired.
286:
The Unicode character set provides a line separator character as well as a paragraph separator to represent the semantics of the soft return and hard return.
171:, is breaking a section of text into lines so that it will fit into the available width of a page, window or other display area. In text display, 492:. This system used relays rather than programmable digital computers, and therefore needed a simple algorithm that could be implemented without 103:
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
115:
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
767: 404: 220:. Manual soft breaks are unnecessary when word wrap is done automatically, so hitting the "Enter" key usually produces a hard return. 805: 758:
Reference: "Breaking Paragraphs into Lines", D.E. Knuth and M.F. Plass, chapter 3 of _Digital Typography_, CSLI Lecture Notes #78.
503:
in an unpublished 1977 memo describing his TeX typesetting system and later published in more detail by Knuth & Plass (1981).
379:) by extension, meaning words can, and tend to be, broken without any explicit indication that a word continues on the next line. 786: 202:
delimiters within paragraphs, and allows the display of text to adapt flexibly and dynamically to displays of varying sizes.
799: 471: 630: 339:
Sometimes word wrap is undesirable between adjacent words. In such cases, word wrap can usually be blocked by using a
685: 601: 84: 389:
word wrapping might not be desired within any compound words (when the text is flush left but only in some styles).
823: 195:, of breaking lines between words rather than within words, where possible. Word wrap makes it unnecessary to 843: 680:, CSLI Lecture Notes, vol. 78, Stanford, California: Center for the Study of Language and Information, 853: 267:
there is a <br> tag that has the same purpose as the soft return in word processors described above.
403:
punctuation may or may not follow rules similar to the above-mentioned special circumstances. It is up to
858: 263:
In text-oriented markup languages, a soft return is typically offered as a markup tag. For example, in
212: 17: 228: 66: 62: 46: 815: 811: 488:
A primitive line-breaking feature was used in 1955 in a "page printer control unit" developed by
54: 591: 521: – Setting of text flow or image placement relative to a page, column, table cell, or tab 518: 499:
The greedy algorithm for line-breaking predates the dynamic programming method outlined by
416: 8: 848: 762:
Text::Reflow - Perl module for reflowing text files using Knuth's paragraphing algorithm.
313: 787:"Bridging the Algorithm Gap: A Linear-time Functional Program for Paragraph Formatting" 750: 718: 674: 512: 432: 344: 236: 777: 558: 722: 681: 597: 360: 710: 524: 428: 371:, but certain punctuation characters are not allowed to begin a new line. Japanese 356: 333: 382:
Under certain circumstances, however, word wrapping is not desired. For instance,
827: 593:
CJKV Information Processing: Chinese, Japanese, Korean & Vietnamese Computing
364: 350: 188: 701:
Knuth, Donald Ervin; Plass, Michael F (1981), "Breaking Paragraphs into Lines",
655: 312:
inside of a word. This is sometimes not desired, and can be blocked by using a
400: 232: 419:. Depending on what needs to be optimized for, different algorithms are used. 837: 800:
the reverse problem -- picking columns just wide enough to fit (wrapped) text
489: 368: 808:
by Simon Pepping 2006. Extends the Knuth model to handle a few enhancements.
771: 756:"tex_wrap": "Implements TeX's algorithm for breaking paragraphs into lines." 761: 714: 669: 651: 530: 500: 217: 755: 578:
WORD JOINER should be used if the intent is to merely prevent a line break
536: 493: 394: 324: 317: 196: 192: 184: 738: 256: 249: 242: 176: 819: 65:
external links, and converting useful links where appropriate into
276: 199: 303: 279:
Line Breaking Algorithm determines a set of positions, known as
309: 351:
Word wrapping in text containing Chinese, Japanese, and Korean
386:
word wrapping might not be desired within personal names, and
376: 372: 264: 477: 328:
is meant to be wrappable by breaking it across lines but
336:
is put at the permitted breaking point(s) in the word.)
150:
fugiat nulla pariatur. Excepteur sint occaecat cupidatat
127:
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
367:, word wrapping can usually occur before and after any 323:
A word without hyphens can be made wrappable by having
154:
non proident, sunt in culpa qui officia deserunt mollit
27:
Feature of continuing on a new line when a line is full
822:
compares the algorithms of various time complexities (
397:
software cannot handle either of the above scenarios.
299:* may be used to represent this semantic unambiguously 293:* may be used to represent this semantic unambiguously 146:
reprehenderit in voluptate velit esse cillum dolore eu
450:
is the remaining width of space on the line to fill,
806:"Knuth linebreaking elements for Formatting Objects" 130:
sed do eiusmod tempor incididunt ut labore et dolore
134:
magna aliqua. Ut enim ad minim veniam, quis nostrud
673: 138:exercitation ullamco laboris nisi ut aliquip ex ea 568:. Annex #14 (Proposed Update Unicode Standard): 2 49:may not follow Knowledge's policies or guidelines 835: 239:, users are expected to type a carriage return ( 347:between the words, instead of regular spaces. 224:address into lines of the appropriate length. 427:A simple way to do word wrapping is to use a 304:Word boundaries, hyphenation, and hard spaces 527: – Special character in text processing 515: – Special character in text processing 375:are treated the same way as Han Characters ( 751:"Knuth & Plass line-breaking Revisited" 142:commodo consequat. Duis aute irure dolor in 812:"a Knuth–Plass-like linebreaking algorithm 700: 533: – Glyph that separates written words 454:is the width of a single space character, 422: 85:Learn how and when to remove this message 793: 556: 205: 14: 836: 616: 550: 458:is the input text to iterate over and 789:by Oege de Moor, Jeremy Gibbons, 1997 668: 650: 596:, O'Reilly Media, Inc., p. 352, 589: 465: 744: 539: – Character in text processing 29: 472:Knuth-Plass line-breaking algorithm 24: 617:Harris, Robert W. (January 1956), 557:Heninger, Andy, ed. (2013-01-25). 393:Most existing word processors and 183:is the additional feature of most 25: 870: 732: 703:Software: Practice and Experience 559:"Unicode Line Breaking Algorithm" 34: 739:Unicode Line Breaking Algorithm 476:A different algorithm, used in 332:making a hyphen ever appear, a 320:, instead of a regular hyphen. 694: 644: 623:Western Union Technical Review 610: 583: 13: 1: 768:adjusting the Knuth algorithm 543: 410: 7: 778:Knuth's breaking algorithm. 506: 10: 875: 782:Google Summer Of Code 2006 629:(1): 37–42, archived from 619:"Keyboard standardization" 483: 469: 405:line breaking rules in CJK 296:0x2029 PARAGRAPH SEPARATOR 270: 462:is a word in this text. 446:is the width of a line, 423:Minimum number of lines 715:10.1002/spe.4380111102 161: 118: 105: 794:Other word-wrap links 519:Typographic alignment 290:0x2028 LINE SEPARATOR 206:Soft and hard returns 124: 111: 100: 844:Text editor features 417:optimization problem 415:Word wrapping is an 227:In the contemporary 158:anim id est laborum. 55:improve this article 854:Dynamic programming 590:Lunde, Ken (1999), 314:non-breaking hyphen 281:break opportunities 122:Hard coded newlines 67:footnote references 859:Unicode algorithms 826:2024-08-01 at the 802:(Archived version) 676:Digital Typography 513:Non-breaking space 466:Minimum raggedness 433:Libreoffice Writer 345:non-breaking space 237:Libreoffice Writer 770:to recognize the 745:Knuth's algorithm 566:Technical Reports 109:Without word wrap 95: 94: 87: 16:(Redirected from 866: 726: 725: 698: 692: 690: 679: 666: 665: 664: 648: 642: 640: 639: 638: 614: 608: 606: 587: 581: 580: 575: 573: 563: 554: 525:Zero-width space 461: 457: 453: 449: 445: 429:greedy algorithm 334:zero-width space 231:word processors 167:, also known as 159: 155: 151: 147: 143: 139: 135: 131: 128: 116: 90: 83: 79: 76: 70: 38: 37: 30: 21: 874: 873: 869: 868: 867: 865: 864: 863: 834: 833: 828:Wayback Machine 820:"Line breaking" 796: 747: 735: 730: 729: 709:(11): 1119–84, 699: 695: 688: 667:. Reprinted in 662: 660: 649: 645: 636: 634: 615: 611: 604: 588: 584: 571: 569: 561: 555: 551: 546: 509: 486: 474: 468: 459: 455: 451: 447: 443: 440: 425: 413: 353: 306: 273: 259: 252: 245: 208: 189:word processors 162: 157: 156: 153: 152: 149: 148: 145: 144: 141: 140: 137: 136: 133: 132: 129: 126: 123: 119: 113: 110: 106: 99: 91: 80: 74: 71: 52: 43:This article's 39: 35: 28: 23: 22: 15: 12: 11: 5: 872: 862: 861: 856: 851: 846: 832: 831: 817: 809: 803: 795: 792: 791: 790: 784: 775: 765: 759: 753: 746: 743: 742: 741: 734: 733:External links 731: 728: 727: 693: 686: 643: 609: 602: 582: 548: 547: 545: 542: 541: 540: 534: 528: 522: 516: 508: 505: 485: 482: 470:Main article: 467: 464: 437: 424: 421: 412: 409: 391: 390: 387: 352: 349: 305: 302: 301: 300: 297: 294: 291: 272: 269: 254: 247: 240: 233:Microsoft Word 207: 204: 121: 120: 108: 107: 98:With word wrap 97: 96: 93: 92: 47:external links 42: 40: 33: 26: 9: 6: 4: 3: 2: 871: 860: 857: 855: 852: 850: 847: 845: 842: 841: 839: 829: 825: 821: 818: 816: 813: 810: 807: 804: 801: 798: 797: 788: 785: 783: 779: 776: 773: 772:"soft hyphen" 769: 766: 763: 760: 757: 754: 752: 749: 748: 740: 737: 736: 724: 720: 716: 712: 708: 704: 697: 689: 687:1-57586-010-4 683: 678: 677: 671: 670:Knuth, Donald 659: 658: 653: 652:Knuth, Donald 647: 633:on 2015-08-03 632: 628: 624: 620: 613: 605: 603:9781565922242 599: 595: 594: 586: 579: 567: 560: 553: 549: 538: 535: 532: 529: 526: 523: 520: 517: 514: 511: 510: 504: 502: 497: 495: 491: 490:Western Union 481: 479: 473: 463: 436: 434: 430: 420: 418: 408: 406: 402: 398: 396: 388: 385: 384: 383: 380: 378: 374: 370: 369:Han character 366: 362: 358: 348: 346: 342: 337: 335: 331: 326: 321: 319: 315: 311: 298: 295: 292: 289: 288: 287: 284: 282: 278: 268: 266: 261: 258: 251: 244: 238: 234: 230: 225: 221: 219: 218:email clients 214: 203: 201: 198: 194: 190: 186: 182: 178: 174: 170: 169:word wrapping 166: 165:Line breaking 160: 117: 104: 89: 86: 78: 68: 64: 63:inappropriate 60: 56: 50: 48: 41: 32: 31: 19: 706: 702: 696: 675: 661:, retrieved 656: 646: 635:, retrieved 631:the original 626: 622: 612: 592: 585: 577: 570:. Retrieved 565: 552: 531:Word divider 501:Donald Knuth 498: 494:data buffers 487: 475: 441: 426: 414: 399: 392: 381: 354: 340: 338: 329: 325:soft hyphens 322: 307: 285: 280: 274: 262: 226: 222: 209: 193:web browsers 185:text editors 180: 172: 168: 164: 163: 125: 112: 101: 81: 72: 57:by removing 44: 537:Word joiner 395:typesetting 318:hard hyphen 849:Typography 838:Categories 663:2013-04-07 637:2013-04-07 544:References 452:SpaceWidth 341:hard space 75:March 2015 723:206508107 657:TEXDR.AFT 448:SpaceLeft 444:LineWidth 411:Algorithm 229:graphical 213:indenting 197:hard-code 181:Word wrap 177:scrolling 173:line wrap 59:excessive 18:Word wrap 824:Archived 672:(1999), 654:(1977), 572:10 March 507:See also 361:Japanese 484:History 357:Chinese 330:without 277:Unicode 271:Unicode 200:newline 53:Please 45:use of 721:  684:  600:  442:Where 365:Korean 363:, and 310:hyphen 191:, and 719:S2CID 562:(PDF) 377:Kanji 316:, or 257:Enter 250:Shift 243:Enter 682:ISBN 598:ISBN 574:2015 460:Word 456:Text 373:kana 275:The 265:HTML 235:and 711:doi 478:TeX 401:CJK 355:In 343:or 61:or 840:: 830:). 717:, 707:11 705:, 627:10 625:, 621:, 576:. 564:. 407:. 359:, 255:↵ 248:⇧ 241:↵ 187:, 179:. 774:. 713:: 691:. 641:. 607:. 253:+ 88:) 82:( 77:) 73:( 69:. 51:. 20:)

Index

Word wrap
external links
improve this article
excessive
inappropriate
footnote references
Learn how and when to remove this message
scrolling
text editors
word processors
web browsers
hard-code
newline
indenting
email clients
graphical
Microsoft Word
Libreoffice Writer
Enter
Shift
Enter
HTML
Unicode
hyphen
non-breaking hyphen
hard hyphen
soft hyphens
zero-width space
non-breaking space
Chinese

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.