This is a LuaLaTeX solution. It is a function that gets called just before TeX breaks the text into lines. It inserts ties ~
(only the penalty of 10000, the glue is already there) after the single letter word. Words will still hyphenate (see example below) - as far as I can see (after the w).
[Edit: I have added a check in the code that only letters (L* unicode character class) will be taken into account when preventing a line break after the glyph.]
\documentclass{article}
\usepackage{polski}
\usepackage[polish]{babel}
\usepackage{fontspec}
\usepackage{luatexbase}\usepackage{luacode}
\begin{luacode}
local prevent_single_letter = function (head)
while head do
if head.id == 37 and unicode.utf8.match(unicode.utf8.char(head.char),"%a") then -- a letter
if head.prev.id == 10 and head.next.id == 10 then -- only if we are at a one letter word
local p = node.new("penalty")
p.penalty = 10000
-- This is for debugging only, but then you have to
-- remove the last node.insert_after line:
-- local w = node.new("whatsit","pdf_literal")
-- w.data = "q 1 0 1 RG 1 0 1 rg 0 0 m 0 5 l 2 5 l 2 0 l b Q"
-- node.insert_after(head,head,w)
-- node.insert_after(head,w,p)
node.insert_after(head,head,p)
end
end
head = head.next
end
return true
end
luatexbase.add_to_callback("pre_linebreak_filter",prevent_single_letter,"active~")
\end{luacode}
\begin{document}
\hsize 2.7in
Noc była sierpniowa, ciepła i słodka, Księżyc oświecał srebrnem światłem wgłębienie, tak,
że twarze małego rycerza i Basi były skąpane w blasku.
Poniżej, na podwórzu zamkowem, widać było uśpione kupy żołnierzy, a także i ciała zabitych
podczas dziennej strzelaniny, bo nie znaleziono dotąd czasu na ich pogrzebanie.
\end{document}
BTW: the small hyphenation marks are made with the package showhyphens
.
The choice between ragged right or justified typesetting depends on the nature of the text you have to set. A discussion about this is mostly off-topic for this site, but some TeXnical aspects are surely on topic.
The algorithm TeX uses for breaking lines is equally good for both methods and can be tuned up to give a pleasing result: one can for instance choose to avoid hyphenation in ragged right text (the standard \raggedright
setting in LaTeX) or allow it (with \RaggedRight
from the ragged2e
package.
The facilities provided by microtype
can certainly be helpful also with ragged right typesetting. Here's an example, where the paragraph turns out to be one line longer without microtype
.
\documentclass{article}
\usepackage{microtype,kantlipsum}
\begin{document}
\raggedright
\kant[1]
\bigskip\hrule\bigskip
\microtypesetup{activate=false}
\kant[1]
\end{document}
Here's the result when we load ragged2e
and use \RaggedRight
instead of \raggedright,
thereby allowing hyphenation:
I should note that in this case one line turns out to be overfull when microtype
is active (top paragraph), precisely
Overfull \hbox (0.12758pt too wide) in paragraph at lines 7--7
\OT1/cmr/m/n/10 (+7) re-sen-ta-tion of, as far as I know, the things in them-se
lves; as I have shown else-
However, this is a false problem, because in a ragged right setting one can increase \hfuzz
to a higher value than the 0.1pt default. One should also tune up the parameters for microtype
more carefully.
Here's the last example, where the paragraph is set in two column mode, left with microtype
, right without it:
\documentclass{article}
\usepackage{microtype,kantlipsum,ragged2e,multicol}
\begin{document}
\RaggedRight
\begin{multicols}{2}
\kant[1]
\columnbreak
\microtypesetup{activate=false}
\kant[1]
\end{multicols}
\end{document}
I'll leave the evaluation of the result to personal judgment.
Best Answer
As long as your paragraphs are long enough to make it feasible you can limit the stretch of the
\parfillskip
that pads the final line. It is not so easy to specifically refer to a single word, but you can make it stretch at most (say) half the line). You may need to increase\emergencystretch
or\tolerance
to allow the rest of the paragraph enough flexibility to push the extra words on to the last line:Similarly if you make the glue used for centering have only finite stretch: