While I couldn't get David Carlisle's answer to work, I made a simple tielable vector version of the xkcd snake:
\documentclass{article}
\usepackage[text={1.2in,3in}]{geometry}
\usepackage[none]{hyphenat}
\directlua{
PDF_LITERAL = node.subtype("pdf_literal")
WS = node.id("whatsit")
GLUE = node.id("glue")
add_image = function(line, n, width, height, name)
local sni = img.node{filename=name}
sni.height = height
sni.width = width
return node.insert_before(line,n,sni)
end
add_snake = function(line, n, width, height)
local segments_middle = 0;
local segments_wave = 0;
local unstretched_width = height * (1.0 + 1.5)
while unstretched_width + height * 1.5 < width do
unstretched_width = unstretched_width + height * 1.5
segments_wave = segments_wave + 1
end
while unstretched_width + height * 0.5 < width do
unstretched_width = unstretched_width + height * 0.5
segments_middle = segments_middle + 1
end
local stretch = width / unstretched_width
line = add_image(line, n, height * 1.0 * stretch, height, "snake_tail.pdf")
for i = 1, segments_wave do
line = add_image(line, n, height * 1.5 * stretch, height, "snake_wave.pdf")
end
for i = 1, segments_middle do
line = add_image(line, n, height * 0.5 * stretch, height, "snake_middle.pdf")
end
line = add_image(line, n, height * 1.5 * stretch, height, "snake_head.pdf")
return line
end
local w = 1250000 % remove when effective_glue works!
snakefill = function(head)
for line in node.traverse_id(0,head) do
for n in node.traverse_id(GLUE,line.head) do
if n.subtype == 9 then
%local w = node.effective_glue(n,line) / 65536
w = w * 1.1 % remove when effective_glue works!
local h = 500000
line = add_snake(line, n, w, 500000)
end
end
end
return head
end
}
\def\snakefill{%
\directlua{
luatexbase.add_to_callback("post_linebreak_filter",snakefill,"snake fill")
}%
}
\def\offsnakefill{%
\directlua{
luatexbase.remove_from_callback("post_linebreak_filter","snake fill")
}%
}
\begin{document}
\raggedright
\snakefill
\noindent Their famous paper on the relationship between deindustrialization and the growth of ecological\ldots\par
\noindent Their famous paper on the relationship between deindustrialization and the growth of ecological\ldots\par
\noindent Their famous paper on the relationship between deindustrialization and the growth of ecological\ldots\par
\end{document}
The snake images can be obtained from this gist. I'll update the post if I find a way to get effective_glue
to work.