-
-
Save wrtlprnft/4cc8fe07f114449f0d8748fe60af39e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lovely work, bro!