<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.luatex.org/index.php?action=history&amp;feed=atom&amp;title=T_wo_T_r%3Apages.lua</id>
	<title>T wo T r:pages.lua - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.luatex.org/index.php?action=history&amp;feed=atom&amp;title=T_wo_T_r%3Apages.lua"/>
	<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=T_wo_T_r:pages.lua&amp;action=history"/>
	<updated>2026-05-31T15:12:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.luatex.org/index.php?title=T_wo_T_r:pages.lua&amp;diff=3562&amp;oldid=prev</id>
		<title>Rkrug: Created page with &quot; &lt;nowiki&gt;   --- Copyright (c) 2021 by Toadstone Enterprises. --- ISC-type license, see License.txt for details.   -------------------------------------------------------------...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.luatex.org/index.php?title=T_wo_T_r:pages.lua&amp;diff=3562&amp;oldid=prev"/>
		<updated>2021-02-22T18:33:27Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; &amp;lt;nowiki&amp;gt;   --- Copyright (c) 2021 by Toadstone Enterprises. --- ISC-type license, see License.txt for details.   -------------------------------------------------------------...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; &amp;lt;nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Copyright (c) 2021 by Toadstone Enterprises.&lt;br /&gt;
--- ISC-type license, see License.txt for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local util = require(&amp;quot;utils&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local node_type        = util.node_type&lt;br /&gt;
local link_nodes       = util.link_nodes&lt;br /&gt;
local make_glue        = util.make_glue&lt;br /&gt;
local make_rule        = util.make_rule&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local format = require(&amp;quot;format&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local text_height   = format.text_height&lt;br /&gt;
&lt;br /&gt;
local top_margin    = format.top_margin&lt;br /&gt;
local left_margin   = format.left_margin&lt;br /&gt;
&lt;br /&gt;
local header_height = format.header_height&lt;br /&gt;
local header_sep    = format.header_sep&lt;br /&gt;
&lt;br /&gt;
local footer_height = format.footer_height&lt;br /&gt;
local footer_sep    = format.footer_sep&lt;br /&gt;
&lt;br /&gt;
local page_number   = format.page_number&lt;br /&gt;
&lt;br /&gt;
local header_tbl    = format.header_tbl&lt;br /&gt;
local footer_tbl    = format.footer_tbl&lt;br /&gt;
local push_tbl      = format.push_tbl&lt;br /&gt;
local pop_tbl       = format.pop_tbl&lt;br /&gt;
local top_tbl       = format.top_tbl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local reader = require(&amp;quot;reader&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local push_reader = reader.push_reader&lt;br /&gt;
local pop_reader  = reader.pop_reader&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local main = main or require(&amp;quot;main&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local main_loop = main.main_loop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local par_height = function(par)&lt;br /&gt;
  -- But can really be used on any list of lines including&lt;br /&gt;
  -- multiple paragraphs.&lt;br /&gt;
  local height = 0&lt;br /&gt;
  while par do&lt;br /&gt;
    if (node_type(par) == &amp;quot;hlist&amp;quot;) then&lt;br /&gt;
      height = height + par.height + par.depth&lt;br /&gt;
    elseif (node_type(par) == &amp;quot;glue&amp;quot;) then&lt;br /&gt;
      height = height + par.width&lt;br /&gt;
    else&lt;br /&gt;
      -- A penalty has zero height, but what else might we find?&lt;br /&gt;
      assert((node_type(par) == &amp;quot;penalty&amp;quot;), &amp;quot;Found a: &amp;quot; .. node_type(par))&lt;br /&gt;
    end&lt;br /&gt;
    par = par.next&lt;br /&gt;
  end&lt;br /&gt;
  return height&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local build_par = function(head, tail)&lt;br /&gt;
  -- We have a linked list of nodes, starting with head, and ending&lt;br /&gt;
  -- with tail. We insert the initial parindent and final penalty&lt;br /&gt;
  -- and parfillskip.&lt;br /&gt;
&lt;br /&gt;
  local tbl = top_tbl()&lt;br /&gt;
&lt;br /&gt;
  local n&lt;br /&gt;
  if State.first_paragraph_of_chapter then&lt;br /&gt;
    -- This is the first paragraph after a title. Do not indent.&lt;br /&gt;
    n = make_glue(0, 0)&lt;br /&gt;
    State.first_paragraph_of_chapter = false&lt;br /&gt;
  else&lt;br /&gt;
    --indent.&lt;br /&gt;
    n = make_glue(0,&lt;br /&gt;
                  tbl.parindent or tex.parindent)&lt;br /&gt;
  end&lt;br /&gt;
  link_nodes(n, head)&lt;br /&gt;
  head = n&lt;br /&gt;
&lt;br /&gt;
  local penalty = node.new(&amp;quot;penalty&amp;quot;)&lt;br /&gt;
  penalty.penalty = 10000&lt;br /&gt;
&lt;br /&gt;
  local parfillskip = make_glue(&amp;quot;parfillskip&amp;quot;,&lt;br /&gt;
                                0,&lt;br /&gt;
                                tbl.parfillskipstretch  or 2^16, 0,&lt;br /&gt;
                                tbl.parfillskipstretch_order or 2, 0)&lt;br /&gt;
&lt;br /&gt;
  link_nodes(tail, penalty, parfillskip)&lt;br /&gt;
&lt;br /&gt;
  -- hyphenate, kern, and ligature&lt;br /&gt;
  lang.hyphenate(head)&lt;br /&gt;
  -- With otf fonts, use this rather than kern and ligature.&lt;br /&gt;
  nodes.simple_font_handler(head)&lt;br /&gt;
&lt;br /&gt;
  -- and make the paragraph.&lt;br /&gt;
  local par = tex.linebreak(head, tbl)&lt;br /&gt;
&lt;br /&gt;
  return par&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local process_par = function(par)&lt;br /&gt;
  -- Move par to the appropriate place, based on State.mode&lt;br /&gt;
  &lt;br /&gt;
  -- If we want to build pages as we go, instead of in batches,&lt;br /&gt;
  -- we can call the page builder from in here.&lt;br /&gt;
&lt;br /&gt;
  local a_par_is_already_there&lt;br /&gt;
  if (State.mode == &amp;quot;main_text&amp;quot;) then&lt;br /&gt;
    a_par_is_already_there = State.main&lt;br /&gt;
  elseif (State.mode == &amp;quot;header&amp;quot;) then&lt;br /&gt;
    a_par_is_already_there = State.header&lt;br /&gt;
  elseif (State.mode == &amp;quot;footer&amp;quot;) then&lt;br /&gt;
    a_par_is_already_there = State.footer&lt;br /&gt;
  elseif (State.mode == &amp;quot;footnote&amp;quot;) then&lt;br /&gt;
    a_par_is_already_there = State.notes[State.max_notes]&lt;br /&gt;
  else&lt;br /&gt;
    assert(false, &amp;quot;Invalid mode seen in process_par&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  if a_par_is_already_there then&lt;br /&gt;
  &lt;br /&gt;
    -- at least one paragraph has already been processed, so we link&lt;br /&gt;
    -- the new par to the old one.&lt;br /&gt;
    local tail = node.tail(a_par_is_already_there)&lt;br /&gt;
    if ((node_type(tail) == &amp;quot;hlist&amp;quot;) and&lt;br /&gt;
        (node_type(par)  == &amp;quot;hlist&amp;quot;)) then&lt;br /&gt;
      -- add tex.baselineskip&lt;br /&gt;
      local glue_needed = tex.baselineskip.width - (par.height + tail.depth)&lt;br /&gt;
      local n = make_glue(&amp;quot;baselineskip&amp;quot;,&lt;br /&gt;
                          glue_needed)&lt;br /&gt;
      link_nodes(tail, n, par)&lt;br /&gt;
    else&lt;br /&gt;
      -- tail or par is glue?&lt;br /&gt;
      assert(((node_type(tail) == &amp;quot;glue&amp;quot;) or&lt;br /&gt;
              (node_type(par)  == &amp;quot;glue&amp;quot;)), &amp;quot;Not glue!&amp;quot;)&lt;br /&gt;
      -- We assume that this glue is enough.&lt;br /&gt;
      link_nodes(tail, par)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
  else&lt;br /&gt;
&lt;br /&gt;
    -- This is the first par, so we just put it where it belongs.&lt;br /&gt;
    if (State.mode == &amp;quot;main_text&amp;quot;) then&lt;br /&gt;
      State.main = par&lt;br /&gt;
    elseif (State.mode == &amp;quot;header&amp;quot;) then&lt;br /&gt;
      State.header = par&lt;br /&gt;
    elseif (State.mode == &amp;quot;footer&amp;quot;) then&lt;br /&gt;
      State.footer = par&lt;br /&gt;
    elseif (State.mode == &amp;quot;footnote&amp;quot;) then&lt;br /&gt;
      State.notes[State.max_notes] = par&lt;br /&gt;
    else&lt;br /&gt;
      assert(false, &amp;quot;Invalid mode seen in process_par&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local pop_line = function()&lt;br /&gt;
  -- Pop the top line from State.main.&lt;br /&gt;
  -- This is used by build_page to incrementally build a page.&lt;br /&gt;
&lt;br /&gt;
  if State.main then&lt;br /&gt;
    local line = State.main&lt;br /&gt;
    State.main = State.main.next&lt;br /&gt;
    if State.main then&lt;br /&gt;
      State.main.prev = nil&lt;br /&gt;
    end&lt;br /&gt;
    line.next = nil&lt;br /&gt;
    return line&lt;br /&gt;
  else&lt;br /&gt;
    return nil&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local return_line = function(line)&lt;br /&gt;
  -- Return a (previously popped) line to State.main&lt;br /&gt;
&lt;br /&gt;
  line.next = State.main&lt;br /&gt;
  if State.main then&lt;br /&gt;
    State.main.prev = line&lt;br /&gt;
  end&lt;br /&gt;
  State.main = line&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- Now, on to build_page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local make_header = function()&lt;br /&gt;
  -- Make the header&lt;br /&gt;
&lt;br /&gt;
  -- The text of our header.&lt;br /&gt;
  -- When we call main_loop, this will be the reader used.&lt;br /&gt;
  if State.header_text then&lt;br /&gt;
    push_reader(State.header_text)&lt;br /&gt;
  else&lt;br /&gt;
    push_reader(&amp;quot;Header&amp;quot;)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  -- This is the tbl that will be used by main_loop.&lt;br /&gt;
  push_tbl(header_tbl)&lt;br /&gt;
  local old_mode = State.mode&lt;br /&gt;
  State.mode = &amp;quot;header&amp;quot;&lt;br /&gt;
  -- Now we do the work.&lt;br /&gt;
  -- When pages and main became mutually dependant, I had to&lt;br /&gt;
  -- prefix main_loop with the package name. Otherwise:&lt;br /&gt;
  -- attempt to call a nil value (upvalue &amp;#039;main_loop&amp;#039;)&lt;br /&gt;
  -- Similarly in make_footer.&lt;br /&gt;
  -- Why is this?&lt;br /&gt;
  main.main_loop()&lt;br /&gt;
  State.mode = old_mode&lt;br /&gt;
&lt;br /&gt;
  -- Restore the old reader and tbl.&lt;br /&gt;
  pop_reader()&lt;br /&gt;
  pop_tbl()&lt;br /&gt;
&lt;br /&gt;
  -- We assume that the header is only one line&lt;br /&gt;
  local line = State.header&lt;br /&gt;
  State.header = nil&lt;br /&gt;
  assert((line.next == nil), &amp;quot;Header is not just one line.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  -- We center the header (vertically) in its header_height box&lt;br /&gt;
  local needed_height  = header_height - line.height&lt;br /&gt;
  local top_glue       = make_glue(0, needed_height / 2)&lt;br /&gt;
  local bot_glue       = make_glue(0, needed_height / 2)&lt;br /&gt;
&lt;br /&gt;
  -- Add a rule&lt;br /&gt;
  local header_rule = make_rule(&amp;quot;normal&amp;quot;, text_width, tex.sp(&amp;quot;1pt&amp;quot;))&lt;br /&gt;
  header_rule_box   = node.hpack(header_rule)  -- Must hpack. Why?&lt;br /&gt;
&lt;br /&gt;
  -- centered (vertically) in its header_sep height box&lt;br /&gt;
  local top_sep_glue = make_glue(0, (header_sep - tex.sp(&amp;quot;1pt&amp;quot;) / 2))&lt;br /&gt;
  local bot_sep_glue = make_glue(0, (header_sep - tex.sp(&amp;quot;1pt&amp;quot;) / 2))&lt;br /&gt;
&lt;br /&gt;
  -- link it al together&lt;br /&gt;
  link_nodes(top_glue, line, bot_glue,&lt;br /&gt;
             top_sep_glue, header_rule_box, bot_sep_glue)&lt;br /&gt;
&lt;br /&gt;
  -- and package it up in a vbox&lt;br /&gt;
  local header = node.vpack(top_glue)&lt;br /&gt;
&lt;br /&gt;
  return header&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local make_footer = function()&lt;br /&gt;
&lt;br /&gt;
  -- the text of our footer&lt;br /&gt;
  push_reader(tostring(page_number))&lt;br /&gt;
&lt;br /&gt;
  push_tbl(footer_tbl)&lt;br /&gt;
  &lt;br /&gt;
  local old_mode = State.mode&lt;br /&gt;
  State.mode = &amp;quot;footer&amp;quot;&lt;br /&gt;
  main.main_loop()&lt;br /&gt;
  State.mode = old_mode&lt;br /&gt;
&lt;br /&gt;
  pop_reader()&lt;br /&gt;
  pop_tbl()&lt;br /&gt;
&lt;br /&gt;
  local line = State.footer&lt;br /&gt;
  State.footer = nil&lt;br /&gt;
  assert((line.next == nil), &amp;quot;Footer is not just one line.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  local needed_height  = footer_height - line.height&lt;br /&gt;
  local foot_glue      = make_glue(0, needed_height)&lt;br /&gt;
&lt;br /&gt;
  local sep_glue = make_glue(0, footer_sep)&lt;br /&gt;
&lt;br /&gt;
  link_nodes(sep_glue, foot_glue, line)&lt;br /&gt;
  &lt;br /&gt;
  local footer = node.vpack(foot_glue)&lt;br /&gt;
&lt;br /&gt;
  return footer&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local build_page_step_one = function(line)&lt;br /&gt;
  -- 1) get the main text from main_text, a line at a time until&lt;br /&gt;
  --    we either run out of lines or text_height.&lt;br /&gt;
&lt;br /&gt;
  local head = line&lt;br /&gt;
  local tail = line&lt;br /&gt;
  local note = nil&lt;br /&gt;
  local notes = nil&lt;br /&gt;
  local current_height = 0   &lt;br /&gt;
  while ((current_height &amp;lt; text_height) and line) do&lt;br /&gt;
&lt;br /&gt;
    if node_type(line) == &amp;quot;hlist&amp;quot; then&lt;br /&gt;
      -- See if this line has an associated footnote.&lt;br /&gt;
      local v, _ = node.find_attribute(line.head, 444)&lt;br /&gt;
      if v then&lt;br /&gt;
        -- Get the note, and account for its height.&lt;br /&gt;
        note = State.notes[v]&lt;br /&gt;
        local extra = par_height(note)&lt;br /&gt;
        if notes then&lt;br /&gt;
          -- The separation between notes.&lt;br /&gt;
          extra = extra + tex.sp(&amp;quot;4pt&amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          -- The separation before the first note.&lt;br /&gt;
          extra = extra + tex.sp(&amp;quot;8pt&amp;quot;)&lt;br /&gt;
        end&lt;br /&gt;
        -- Does the line still fit on the page?&lt;br /&gt;
        if (current_height + line.height + line.depth + extra) &amp;lt; text_height then&lt;br /&gt;
          -- Add the line to the end of the text.&lt;br /&gt;
          link_nodes(tail, line)&lt;br /&gt;
          tail = line&lt;br /&gt;
          current_height = (current_height + line.height + line.depth + par_height(note))&lt;br /&gt;
          if notes then&lt;br /&gt;
            -- Add the note to the notes.&lt;br /&gt;
            local n = make_glue(0, tex.sp(&amp;quot;4pt&amp;quot;))&lt;br /&gt;
            link_nodes(node.tail(notes), n, note)&lt;br /&gt;
          else&lt;br /&gt;
            -- This is the first note.&lt;br /&gt;
            notes = note&lt;br /&gt;
          end&lt;br /&gt;
        else&lt;br /&gt;
          -- The line plus the note do not fit on the page.&lt;br /&gt;
          return_line(line, main_text)&lt;br /&gt;
          return current_height, head, tail, notes&lt;br /&gt;
        end&lt;br /&gt;
      elseif (current_height + line.height + line.depth) &amp;lt; text_height then&lt;br /&gt;
        -- We have a line without a note, that fits on the page.&lt;br /&gt;
        link_nodes(tail, line)&lt;br /&gt;
        tail = line&lt;br /&gt;
        current_height = (current_height + line.height + line.depth)&lt;br /&gt;
      else&lt;br /&gt;
        -- The line does not fit on the page.&lt;br /&gt;
        return_line(line, main_text)&lt;br /&gt;
        return current_height, head, tail, notes&lt;br /&gt;
      end&lt;br /&gt;
    elseif node_type(line) == &amp;quot;glue&amp;quot; then&lt;br /&gt;
      -- line is glue, not an hlist.&lt;br /&gt;
      if (current_height + line.width) &amp;lt; text_height then&lt;br /&gt;
        -- line fits on the page.&lt;br /&gt;
        link_nodes(tail, line)&lt;br /&gt;
        tail = line&lt;br /&gt;
        current_height = current_height + line.width&lt;br /&gt;
      else&lt;br /&gt;
        -- line does not fit on the page.&lt;br /&gt;
        return_line(line, main_text)&lt;br /&gt;
        return current_height, head, tail, notes&lt;br /&gt;
      end&lt;br /&gt;
    else&lt;br /&gt;
      -- line is neither an hlist nor glue.&lt;br /&gt;
      assert((node_type(line) == &amp;quot;penalty&amp;quot;), &amp;quot;Threw away a non-penalty: &amp;quot; .. node_type(line))&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- Get the next line, and go to the top of the while loop&lt;br /&gt;
    line = pop_line()&lt;br /&gt;
&lt;br /&gt;
  end&lt;br /&gt;
  return current_height, head, tail, notes&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local build_page_step_four = function(text_box, notes, header_box, footer_box)&lt;br /&gt;
  -- 4) put it all together&lt;br /&gt;
  &lt;br /&gt;
  local top_margin_glue = make_glue(0, top_margin)&lt;br /&gt;
&lt;br /&gt;
  if State.first_page_of_chapter then&lt;br /&gt;
    -- No header&lt;br /&gt;
    if notes then&lt;br /&gt;
      local n = make_glue(0, tex.sp(&amp;quot;8pt&amp;quot;))&lt;br /&gt;
      link_nodes(top_margin_glue, text_box, n, notes)&lt;br /&gt;
    else&lt;br /&gt;
      link_nodes(top_margin_glue, text_box)&lt;br /&gt;
    end&lt;br /&gt;
    State.first_page_of_chapter = false&lt;br /&gt;
  else&lt;br /&gt;
    -- Include a header&lt;br /&gt;
    if notes then&lt;br /&gt;
      local n = make_glue(0, tex.sp(&amp;quot;8pt&amp;quot;))&lt;br /&gt;
      link_nodes(top_margin_glue, header_box, text_box, n, notes, footer_box)&lt;br /&gt;
    else&lt;br /&gt;
      link_nodes(top_margin_glue, header_box, text_box, footer_box)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  -- 4a) Finish the assembly of the page, and ship it out.&lt;br /&gt;
  &lt;br /&gt;
  local main_box = node.vpack(top_margin_glue)&lt;br /&gt;
&lt;br /&gt;
  local left_margin_glue = make_glue(0, left_margin)&lt;br /&gt;
&lt;br /&gt;
  link_nodes(left_margin_glue, main_box)&lt;br /&gt;
&lt;br /&gt;
  local page_box = node.hpack(left_margin_glue)&lt;br /&gt;
&lt;br /&gt;
  tex.setbox(666, page_box)&lt;br /&gt;
&lt;br /&gt;
  tex.shipout(666)&lt;br /&gt;
&lt;br /&gt;
  -- Increment the page counters, both tex&amp;#039;s and ours.&lt;br /&gt;
  tex.count[0] = tex.count[0] + 1&lt;br /&gt;
  page_number = page_number + 1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local build_page = function()&lt;br /&gt;
  -- Build a page by:&lt;br /&gt;
  -- 1) get the main text from main_text, a line at a time until&lt;br /&gt;
  --    we either run out of lines or text_height.&lt;br /&gt;
  -- 2) pad out the text to fill text_height&lt;br /&gt;
  -- 3) make our header and footer&lt;br /&gt;
  -- 4) put it all together&lt;br /&gt;
&lt;br /&gt;
  local line = pop_line()&lt;br /&gt;
  local current_height = 0&lt;br /&gt;
  local head, tail&lt;br /&gt;
  local notes&lt;br /&gt;
&lt;br /&gt;
  -- We are at the top of the page, so we throw away anything&lt;br /&gt;
  -- that is not an hlist&lt;br /&gt;
  while node_type(line) ~= &amp;quot;hlist&amp;quot; do&lt;br /&gt;
    print(&amp;quot;Throwing away a: &amp;quot; .. node_type(line))&lt;br /&gt;
    line = pop_line(main_text)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  -- 1) get the main text from State.text, a line at a time until&lt;br /&gt;
  --    we either run out of lines or text_height.&lt;br /&gt;
  current_height, head, tail, notes = build_page_step_one(line)  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  -- We have fit all the text that will fit on the page.&lt;br /&gt;
  -- 2) pad out the text to fill text_height&lt;br /&gt;
  &lt;br /&gt;
  if (current_height &amp;lt; text_height) then&lt;br /&gt;
    local needed_height = text_height - current_height&lt;br /&gt;
    local n = make_glue(0, needed_height)&lt;br /&gt;
    link_nodes(tail, n)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  local text_box = node.vpack(head)&lt;br /&gt;
&lt;br /&gt;
  -- 3) make our header and footer&lt;br /&gt;
&lt;br /&gt;
  local header_box = make_header()&lt;br /&gt;
  local footer_box = make_footer()&lt;br /&gt;
&lt;br /&gt;
  -- 4) put it all together&lt;br /&gt;
&lt;br /&gt;
  build_page_step_four(text_box, notes, header_box, footer_box)&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
local build_pages = function()&lt;br /&gt;
  -- While there is text to fill a page, we build pages.&lt;br /&gt;
  while State.main do&lt;br /&gt;
    build_page()&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return {build_par   = build_par,&lt;br /&gt;
        process_par = process_par,&lt;br /&gt;
        build_pages = build_pages}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rkrug</name></author>
		
	</entry>
</feed>