<s>
Line	B-Algorithm
breaking	I-Algorithm
,	O
also	O
known	O
as	O
word	B-Algorithm
wrapping	I-Algorithm
,	O
is	O
breaking	O
a	O
section	O
of	O
text	O
into	O
lines	O
so	O
that	O
it	O
will	O
fit	O
into	O
the	O
available	O
width	O
of	O
a	O
page	O
,	O
window	O
or	O
other	O
display	O
area	O
.	O
</s>
<s>
In	O
text	O
display	O
,	O
line	B-Algorithm
wrap	I-Algorithm
is	O
continuing	O
on	O
a	O
new	O
line	O
when	O
a	O
line	O
is	O
full	O
,	O
so	O
that	O
each	O
line	O
fits	O
into	O
the	O
viewable	O
window	O
,	O
allowing	O
text	O
to	O
be	O
read	O
from	O
top	O
to	O
bottom	O
without	O
any	O
horizontal	O
scrolling	O
.	O
</s>
<s>
Word	B-Algorithm
wrap	I-Algorithm
is	O
the	O
additional	O
feature	O
of	O
most	O
text	B-Application
editors	I-Application
,	O
word	B-General_Concept
processors	I-General_Concept
,	O
and	O
web	B-Application
browsers	I-Application
,	O
of	O
breaking	O
lines	O
between	O
words	O
rather	O
than	O
within	O
words	O
,	O
where	O
possible	O
.	O
</s>
<s>
Word	B-Algorithm
wrap	I-Algorithm
makes	O
it	O
unnecessary	O
to	O
hard-code	O
newline	O
delimiters	O
within	O
paragraphs	O
,	O
and	O
allows	O
the	O
display	O
of	O
text	O
to	O
adapt	O
flexibly	O
and	O
dynamically	O
to	O
displays	O
of	O
varying	O
sizes	O
.	O
</s>
<s>
A	O
soft	B-Algorithm
return	I-Algorithm
or	O
soft	B-Algorithm
wrap	I-Algorithm
is	O
the	O
break	O
resulting	O
from	O
line	B-Algorithm
wrap	I-Algorithm
or	O
word	B-Algorithm
wrap	I-Algorithm
(	O
whether	O
automatic	O
or	O
manual	O
)	O
,	O
whereas	O
a	O
hard	O
return	O
or	O
hard	O
wrap	O
is	O
an	O
intentional	O
break	O
,	O
creating	O
a	O
new	O
paragraph	O
.	O
</s>
<s>
Soft	O
wrapping	O
allows	O
line	O
lengths	O
to	O
adjust	O
automatically	O
with	O
adjustments	O
to	O
the	O
width	O
of	O
the	O
user	O
's	O
window	O
or	O
margin	O
settings	O
,	O
and	O
is	O
a	O
standard	O
feature	O
of	O
all	O
modern	O
text	B-Application
editors	I-Application
,	O
word	B-General_Concept
processors	I-General_Concept
,	O
and	O
email	B-Protocol
clients	I-Protocol
.	O
</s>
<s>
Manual	O
soft	O
breaks	O
are	O
unnecessary	O
when	O
word	B-Algorithm
wrap	I-Algorithm
is	O
done	O
automatically	O
,	O
so	O
hitting	O
the	O
"	O
Enter	B-Device
"	O
key	O
usually	O
produces	O
a	O
hard	O
return	O
.	O
</s>
<s>
Alternatively	O
,	O
"	O
soft	B-Algorithm
return	I-Algorithm
"	O
can	O
mean	O
an	O
intentional	O
,	O
stored	O
line	O
break	O
that	O
is	O
not	O
a	O
paragraph	O
break	O
.	O
</s>
<s>
In	O
the	O
contemporary	O
graphical	B-Application
word	B-General_Concept
processors	I-General_Concept
Microsoft	B-Application
Word	I-Application
and	O
OpenOffice.org,	O
users	O
are	O
expected	O
to	O
type	O
a	O
carriage	O
return	O
(	O
)	O
between	O
each	O
paragraph	O
.	O
</s>
<s>
A	O
non-paragraph	O
line	O
break	O
,	O
which	O
is	O
a	O
soft	B-Algorithm
return	I-Algorithm
,	O
is	O
inserted	O
using	O
or	O
via	O
the	O
menus	O
,	O
and	O
is	O
provided	O
for	O
cases	O
when	O
the	O
text	O
should	O
start	O
on	O
a	O
new	O
line	O
but	O
none	O
of	O
the	O
other	O
side	O
effects	O
of	O
starting	O
a	O
new	O
paragraph	O
are	O
desired	O
.	O
</s>
<s>
In	O
text-oriented	O
markup	O
languages	O
,	O
a	O
soft	B-Algorithm
return	I-Algorithm
is	O
typically	O
offered	O
as	O
a	O
markup	O
tag	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
HTML	B-Language
there	O
is	O
a	O
br	O
tag	O
that	O
has	O
the	O
same	O
purpose	O
as	O
the	O
soft	B-Algorithm
return	I-Algorithm
in	O
word	B-General_Concept
processors	I-General_Concept
described	O
above	O
.	O
</s>
<s>
The	O
Unicode	O
Line	B-Algorithm
Breaking	I-Algorithm
Algorithm	O
determines	O
a	O
set	O
of	O
positions	O
,	O
known	O
as	O
break	O
opportunities	O
,	O
that	O
are	O
appropriate	O
places	O
in	O
which	O
to	O
begin	O
a	O
new	O
line	O
.	O
</s>
<s>
The	O
Unicode	O
character	B-General_Concept
set	I-General_Concept
provides	O
a	O
line	O
separator	O
character	O
as	O
well	O
as	O
a	O
paragraph	O
separator	O
to	O
represent	O
the	O
semantics	O
of	O
the	O
soft	B-Algorithm
return	I-Algorithm
and	O
hard	O
return	O
.	O
</s>
<s>
The	O
soft	B-Algorithm
returns	I-Algorithm
are	O
usually	O
placed	O
after	O
the	O
ends	O
of	O
complete	O
words	O
,	O
or	O
after	O
the	O
punctuation	O
that	O
follows	O
complete	O
words	O
.	O
</s>
<s>
However	O
,	O
word	B-Algorithm
wrap	I-Algorithm
may	O
also	O
occur	O
following	O
a	O
hyphen	O
inside	O
of	O
a	O
word	O
.	O
</s>
<s>
Sometimes	O
word	B-Algorithm
wrap	I-Algorithm
is	O
undesirable	O
between	O
adjacent	O
words	O
.	O
</s>
<s>
In	O
such	O
cases	O
,	O
word	B-Algorithm
wrap	I-Algorithm
can	O
usually	O
be	O
blocked	O
by	O
using	O
a	O
hard	O
space	O
or	O
non-breaking	O
space	O
between	O
the	O
words	O
,	O
instead	O
of	O
regular	O
spaces	O
.	O
</s>
<s>
In	O
Chinese	O
,	O
Japanese	O
,	O
and	O
Korean	O
,	O
word	B-Algorithm
wrapping	I-Algorithm
can	O
usually	O
occur	O
before	O
and	O
after	O
any	O
Han	O
character	O
,	O
but	O
certain	O
punctuation	O
characters	O
are	O
not	O
allowed	O
to	O
begin	O
a	O
new	O
line	O
.	O
</s>
<s>
Under	O
certain	O
circumstances	O
,	O
however	O
,	O
word	B-Algorithm
wrapping	I-Algorithm
is	O
not	O
desired	O
.	O
</s>
<s>
word	B-Algorithm
wrapping	I-Algorithm
might	O
not	O
be	O
desired	O
within	O
any	O
compound	O
words	O
(	O
when	O
the	O
text	O
is	O
flush	O
left	O
but	O
only	O
in	O
some	O
styles	O
)	O
.	O
</s>
<s>
Most	O
existing	O
word	B-General_Concept
processors	I-General_Concept
and	O
typesetting	O
software	O
cannot	O
handle	O
either	O
of	O
the	O
above	O
scenarios	O
.	O
</s>
<s>
It	O
is	O
up	O
to	O
line	B-Algorithm
breaking	I-Algorithm
rules	O
in	O
CJK	O
.	O
</s>
<s>
A	O
special	O
case	O
of	O
line	B-Algorithm
breaking	I-Algorithm
rules	O
in	O
CJK	O
,	O
however	O
,	O
always	O
applies	O
:	O
line	B-Algorithm
wrap	I-Algorithm
must	O
never	O
occur	O
inside	O
the	O
CJK	O
dash	O
and	O
ellipsis	O
.	O
</s>
<s>
Even	O
though	O
each	O
of	O
these	O
punctuation	O
marks	O
must	O
be	O
represented	O
by	O
two	O
characters	O
due	O
to	O
a	O
limitation	O
of	O
all	O
existing	O
character	B-General_Concept
encodings	I-General_Concept
,	O
each	O
of	O
these	O
are	O
intrinsically	O
a	O
single	O
punctuation	O
mark	O
that	O
is	O
two	O
ems	O
wide	O
,	O
not	O
two	O
one-em-wide	O
punctuation	O
marks	O
.	O
</s>
<s>
Word	B-Algorithm
wrapping	I-Algorithm
is	O
an	O
optimization	O
problem	O
.	O
</s>
<s>
A	O
simple	O
way	O
to	O
do	O
word	B-Algorithm
wrapping	I-Algorithm
is	O
to	O
use	O
a	O
greedy	B-Algorithm
algorithm	I-Algorithm
that	O
puts	O
as	O
many	O
words	O
on	O
a	O
line	O
as	O
possible	O
,	O
then	O
moving	O
on	O
to	O
the	O
next	O
line	O
to	O
do	O
the	O
same	O
until	O
there	O
are	O
no	O
more	O
words	O
left	O
to	O
place	O
.	O
</s>
<s>
This	O
method	O
is	O
used	O
by	O
many	O
modern	O
word	B-General_Concept
processors	I-General_Concept
,	O
such	O
as	O
OpenOffice.org	B-Application
Writer	I-Application
and	O
Microsoft	B-Application
Word	I-Application
.	O
</s>
<s>
A	O
different	O
algorithm	O
,	O
used	O
in	O
TeX	B-Application
,	O
minimizes	O
the	O
sum	O
of	O
the	O
squares	O
of	O
the	O
lengths	O
of	O
the	O
spaces	O
at	O
the	O
end	O
of	O
lines	O
to	O
produce	O
a	O
more	O
aesthetically	O
pleasing	O
result	O
.	O
</s>
<s>
The	O
following	O
example	O
compares	O
this	O
method	O
with	O
the	O
greedy	B-Algorithm
algorithm	I-Algorithm
,	O
which	O
does	O
not	O
always	O
minimize	O
squared	O
space	O
.	O
</s>
<s>
with	O
line	O
width	O
6	O
,	O
the	O
greedy	B-Algorithm
algorithm	I-Algorithm
would	O
produce	O
:	O
</s>
<s>
By	O
using	O
a	O
dynamic	B-Algorithm
programming	I-Algorithm
algorithm	O
to	O
choose	O
the	O
positions	O
at	O
which	O
to	O
break	O
the	O
line	O
,	O
instead	O
of	O
choosing	O
breaks	O
greedily	O
,	O
the	O
solution	O
with	O
minimum	O
raggedness	O
may	O
be	O
found	O
in	O
time	O
,	O
where	O
is	O
the	O
number	O
of	O
words	O
in	O
the	O
input	O
text	O
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
apply	O
the	O
same	O
dynamic	B-Algorithm
programming	I-Algorithm
technique	O
to	O
minimize	O
more	O
complex	O
cost	O
functions	O
that	O
combine	O
other	O
factors	O
such	O
as	O
the	O
number	O
of	O
lines	O
or	O
costs	O
for	O
hyphenating	O
long	O
words	O
.	O
</s>
<s>
Faster	O
but	O
more	O
complicated	O
linear	O
time	O
algorithms	O
based	O
on	O
the	O
SMAWK	B-Algorithm
algorithm	I-Algorithm
are	O
also	O
known	O
for	O
the	O
minimum	O
raggedness	O
problem	O
,	O
and	O
for	O
some	O
other	O
cost	O
functions	O
that	O
have	O
similar	O
properties	O
.	O
</s>
<s>
This	O
system	O
used	O
relays	O
rather	O
than	O
programmable	O
digital	O
computers	O
,	O
and	O
therefore	O
needed	O
a	O
simple	O
algorithm	O
that	O
could	O
be	O
implemented	O
without	O
data	B-General_Concept
buffers	I-General_Concept
.	O
</s>
<s>
The	O
greedy	B-Algorithm
algorithm	I-Algorithm
for	O
line-breaking	O
predates	O
the	O
dynamic	B-Algorithm
programming	I-Algorithm
method	O
outlined	O
by	O
Donald	O
Knuth	O
in	O
an	O
unpublished	O
1977	O
memo	O
describing	O
his	O
TeX	B-Application
typesetting	O
system	O
and	O
later	O
published	O
in	O
more	O
detail	O
by	O
.	O
</s>
