I am trying to get the same output as in this answer by topskip (an extended version with comments is presented in the TeX without TeX article). I am getting a paragraph consisting of 6 lines with hyphenation, but kerning and ligatures are lost (turned off?) as it can be seen around the character V in VLTAVA and in the letters ffi in office.
I use WinXP + TeX Live 2014 and Lubuntu 13.10 + TeX Live 2013. I've got the same output, the font is LinLibertine_R.otf
.
First tip by topskip is to skip loading of the fontspec
package which could handle things differently than the luaotfload
package. Therefore, instead of libertine
and luatextra
(they both load the fontspec
package), I tried to load luacode
and luaotfload
packages directly, no success, no errors and no warnings. Where the problem might be?
We run lualatex testfonts.tex
.
% lualatex testfonts.tex
\documentclass[a4paper]{article}
\pagestyle{empty}
%\usepackage{luatextra}
%\usepackage{libertine}
\usepackage{luaotfload}
\usepackage{luacode}
\begin{document}
\font\main={file:LinLibertine_R.otf}
\main
\begin{luacode*}
function count_lines (head)
local linecount = 0
while head do
if head.id == 0 then linecount = linecount + 1 end
head = head.next
end
return linecount
end
function mknodes( text )
local current_font = font.current()
local font_parameters = font.getfont(current_font).parameters
local n, head, last
-- we should insert the paragraph indentation at the beginning
head = node.new("glue")
head.spec = node.new("glue_spec")
head.spec.width = 20 * 2^16
last = head
for s in string.utfvalues( text ) do
local char = unicode.utf8.char(s)
if unicode.utf8.match(char,"%s") then
-- its a space
n = node.new("glue")
n.spec = node.new("glue_spec")
n.spec.width = font_parameters.space
n.spec.shrink = font_parameters.space_shrink
n.spec.stretch = font_parameters.space_stretch
else -- a glyph
n = node.new("glyph")
n.font = current_font
n.subtype = 1
n.char = s
n.lang = tex.language
n.uchyph = 1
n.left = tex.lefthyphenmin
n.right = tex.righthyphenmin
end
last.next = n
last = n
end
-- now add the final parts: a penalty and the parfillskip glue
local penalty = node.new("penalty")
penalty.penalty = 10000
local parfillskip = node.new("glue")
parfillskip.spec = node.new("glue_spec")
parfillskip.spec.stretch = 2^16
parfillskip.spec.stretch_order = 2
last.next = penalty
penalty.next = parfillskip
-- just to create the prev pointers for tex.linebreak
node.slide(head)
return head
end
local txt = "VLTAVA office A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine."
tex.baselineskip = node.new("glue_spec")
tex.baselineskip.width = 14 * 2^16
local head = mknodes(txt)
lang.hyphenate(head)
head = node.kerning(head)
head = node.ligaturing(head)
local vbox
local size = 90
lines = 0
lines_goal = 6
while lines < lines_goal do
texio.write_nl(string.format("Formatting text to %d mm",size))
local copy_of_head = node.copy_list(head)
vbox = tex.linebreak(copy_of_head,{ hsize = tex.sp(string.format("%dmm",size))})
size = size - 10
lines = count_lines(vbox)
texio.write_nl(string.format("lines=%d",lines))
end
node.write(vbox)
\end{luacode*}
VLTAVA office
\end{document}