Skip to content

Instantly share code, notes, and snippets.

@wrtlprnft
Last active May 7, 2016
Embed
What would you like to do?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
\documentclass{article}
%\usepackage{luatextra}
\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}
@nanmu42

This comment has been minimized.

Copy link

@nanmu42 nanmu42 commented May 7, 2016

Lovely work, bro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment