Editing TeX without TeX
From LuaTeXWiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 2: | Line 2: | ||
With the Lua-part in LuaTeX you have access to most of TeX's capabilities for creating PDF documents. Most of the [http://www.luatex.org/svn/trunk/manual/luatexref-t.pdf LuaTeX reference manual] is about this topic. | With the Lua-part in LuaTeX you have access to most of TeX's capabilities for creating PDF documents. Most of the [http://www.luatex.org/svn/trunk/manual/luatexref-t.pdf LuaTeX reference manual] is about this topic. | ||
− | |||
− | |||
The underlying idea is to create TeX's internal data structure as TeX would do by transforming macros and primitives into something called nodes. These nodes are then transformed into instructions for the PDF file (PDF objects). So the following pages deal with node creation and the structures. | The underlying idea is to create TeX's internal data structure as TeX would do by transforming macros and primitives into something called nodes. These nodes are then transformed into instructions for the PDF file (PDF objects). So the following pages deal with node creation and the structures. | ||
Line 86: | Line 84: | ||
In the example code we use black squares as the contents of the pages and not normal text, because character handling takes more code and will be covered later on. | In the example code we use black squares as the contents of the pages and not normal text, because character handling takes more code and will be covered later on. | ||
− | Save the following file into <tt>myprogram.lua</tt> and use the TeX stub from above (or get the source [https:// | + | Save the following file into <tt>myprogram.lua</tt> and use the TeX stub from above (or get the source [https://raw.github.com/gist/1062041/d3de082e955f6535f3820742cef76fe9e50d5a6f/myprogram.lua here]). |
<pre> | <pre> | ||
do | do | ||
Line 193: | Line 191: | ||
start_link.link_attr = "/C [0.9 1 0] /Border [0 0 2]" | start_link.link_attr = "/C [0.9 1 0] /Border [0 0 2]" | ||
− | + | start_link.action = node.new("action") | |
− | |||
− | |||
start_link.action.action_type = 1 | start_link.action.action_type = 1 | ||
start_link.action.action_id = dest | start_link.action.action_id = dest | ||
Line 307: | Line 303: | ||
for s in string.utfvalues( text ) do | for s in string.utfvalues( text ) do | ||
local char = unicode.utf8.char(s) | local char = unicode.utf8.char(s) | ||
− | if unicode.utf8.match(char," | + | if unicode.utf8.match(char,"%s") then |
-- its a space | -- its a space | ||
n = node.new("glue") | n = node.new("glue") | ||
Line 414: | Line 410: | ||
You might be able to guess what happens here. We load the image [[Media:Oilpainting.jpg|oilpainting.jpg]] with <tt>img.scan</tt> but do not write it out to the PDF file yet. We create a copy of the image data so we can manipulate the size for example (another option would be to obtain a specific page of a PDF document or do some rotation). After that we write a reference to that image to the PDF file. In the case above, two references to the image (XObject) get written but the image is only written once. That is easy, right? | You might be able to guess what happens here. We load the image [[Media:Oilpainting.jpg|oilpainting.jpg]] with <tt>img.scan</tt> but do not write it out to the PDF file yet. We create a copy of the image data so we can manipulate the size for example (another option would be to obtain a specific page of a PDF document or do some rotation). After that we write a reference to that image to the PDF file. In the case above, two references to the image (XObject) get written but the image is only written once. That is easy, right? | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |