Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   https://anggtwu.net/LUA/PictRect1.lua.html
--   https://anggtwu.net/LUA/PictRect1.lua
--           (find-angg "LUA/PictRect1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/PictRect1.lua"))
--
-- Used by:
--   (find-angg "LUA/Pict4.lua" ".Pict-show-tests")
--
-- TODO: replace sub by add!!!
--
-- This file contains low-level functions that generate Pict2e code
-- for Dednat7. In this version the indentation is done by
-- manipulating Rect objects; this is much simpler than what I did in
-- the previous versions, in which the desired indentation was
-- described with a DSL that was parsed with Lpeg. Here are some links
-- to the previous versions:
--
--   (find-angg "LUA/Indent1.lua" "Indent")
--   (find-angg "LUA/Indent2.lua" "Indent")
--   (find-angg "LUA/Indent2.lua" "Pict")
--   (find-angg "LUA/Indent2.lua" "Pict" "{+1" "{<i:ind(1);o=''>")
--   (find-angg "LUA/Pict2e2.lua" "Pict" "{<+1>")
--   (find-angg "LUA/Pict3.lua")
--
-- «.Rect»		(to "Rect")
-- «.Rect-tests»	(to "Rect-tests")
-- «.Pict»		(to "Pict")
-- «.Pict-tests»	(to "Pict-tests")


--  ____           _   
-- |  _ \ ___  ___| |_ 
-- | |_) / _ \/ __| __|
-- |  _ <  __/ (__| |_ 
-- |_| \_\___|\___|\__|
--                     
-- «Rect»  (to ".Rect")
-- See: (find-angg "LUA/Rect.lua" "Rect-add-mul-tests")
Rect.__index.rest = function (rect)
    rect = copy(rect)
    table.remove(rect,1)
    return rect
  end
Rect.__index.indentrest = function (rect,spaces)
    if #rect == 0 then return Rect {} end
    if #rect == 1 then return rect end
    if #rect  > 1 then return rect[1] / (spaces .. rect:rest()) end
  end
Rect.__index.plusindent = function (rect,str1,spaces)
    return str1 + rect:indentrest(spaces)
  end

-- «Rect-tests»  (to ".Rect-tests")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "PictRect1.lua"
r3 = Rect {"abc", "de", "f"}
= r3
= r3:plusindent("_foo{", "  ")
= r3:plusindent("_foo{", "  ") + "}"

--]]



--  ____  _      _   
-- |  _ \(_) ___| |_ 
-- | |_) | |/ __| __|
-- |  __/| | (__| |_ 
-- |_|   |_|\___|\__|
--                   
-- «Pict»  (to ".Pict")
-- Supersedes:
--   (find-angg "LUA/Indent2.lua" "Pict")
--   (find-angg "LUA/Pict2e1.lua" "Pict2e-methods")
--   (find-angg "LUA/Pict2e2.lua" "Pict")
--
Pict = Class {
  type   = "Pict",
  r_ = function (o) return type(o)=="string" and o or Pict.r(o) end,
  r = function (o)
      if type(o)=="string" then return Rect{o} end
      local rects = map(Pict.r, o)
      local bigrect = Rect {}
      for _,rect in ipairs(rects) do
        for _,line in ipairs(rect) do
          table.insert(bigrect, line)
        end
      end
      return bigrect
    end,
  __tostring = function (p)     return p:tostring() end,
  __div      = function (p1,p2) return Pict(Pict.r(p1) /  Pict.r(p2)) end,
  __concat   = function (p1,p2) return Pict(Pict.r(p1) .. Pict.r(p2)) end,
  __add      = function (p1,p2) return Pict(Pict.r_(p1) + Pict.r_(p2)) end,
  __mul      = function (p1,p2) return Pict(Pict.r_(p1) * Pict.r_(p2)) end,
  __index = {
    torect   = function (p) return Pict.r(p) end,
    tostring = function (p) return p:torect():tostring() end,
    output   = function (p) output(tostring(p)) end,
    add      = function (p, o) table.insert(p, o); return p end,
    pre      = function (p, o) return Pict {o, p} end,
    print    = function (p, o) return p:add(o) end,
    printf   = function (p, ...) return p:add(format(...)) end,
    pprintf  = function (p, ...) return p:add(pformat(...)) end,
    --
    indentrest = function (p,spaces) return Pict(Pict.r(p):indentrest(spaces)) end,
    plusindent = function (p,o,i) return Pict(Pict.r(p):plusindent(o,i)) end,
    wrap_00 = function (p,o,i,c) return p:plusindent(o,i) + c end,
    wrap_01 = function (p,o,i,c) return p:plusindent(o,i) / c end,
    wrap_02 = function (p,o,i,c) return (p / c):plusindent(o,i) end,
    wrap_10 = function (p,o,i,c) return o / ((i..p) + c) end,
    wrap_11 = function (p,o,i,c) return o / (i..p) / c end,
    wrap_12 = function (p,o,i,c) return o / (i..(p / c)) end,
    --
    -- Compatibility:
    -- (find-angg "LUA/Indent2.lua" "Pict-tests")
    Wrap10  = function (p,pre) return p:wrap_10((pre or "").."{{", "  ", "}}") end,
    wrap00  = function (p,pre) return p:wrap_00((pre or "").."{",  " ",  "}") end,
    wrapin  = function (p,pre) return p:wrap_00((pre or "").."{",  " ",  "}") end,
    wrap1   = function (p,pre) return p:wrap_00((pre or "").."{",  " ",  "}") end,
    wrap2   = function (p,pre) return p:wrap_11((pre or "").."{",  "  ", "}") end,
    wrapbe  = function (p,b,e) return b/("  "..p)/e end,
    pre0    = function (p,prestr) return prestr / p end,
    --
    -- (find-angg "LUA/Pict2e1.lua" "Pict2e-methods")
    -- (find-angg "LUA/Indent2.lua" "Pict" "ensuremath")
    em        = function (o) return o:wrap1("\\ensuremath")  end,
    d         = function (p) return p:wrap_00("$",  " ",  "$") end,    -- changed
    dd        = function (p) return p:wrap_00("$$", "  ", "$$") end,   -- changed
    def       = function (p, name) return p:Wrap10("\\def\\"..name) end,
    sa        = function (p, name) return p:Wrap10("\\sa{"..name.."}") end,
    color     = function (p, color) return p:wrap00("\\color{"..color.."}") end,
    Color     = function (p, color) return p:wrap00("\\Color"..color) end,
    precolor0 = function (p, color) return p:pre("\\color{"..color.."}") end,
    precolor  = function (p, color) return p:pre("\\color{"..color.."}"):wrap1() end,
    prethickness = function (p, th) return p:pre("\\linethickness{"..th.."}") end,
    preunitlength = function (p, u) return p:pre("\\unitlength="..u) end,
    bhbox     = function (p) return p:wrap_00("\\bhbox{$", " ", "$}") end,
    myvcenter = function (p) return p:wrap00("\\myvcenter") end,
    putat     = function (p, xy) return p:wrap00(pformat("\\put%s", xy)) end,
    --
    scalebox  = function (o, scale)
        if not scale then return o end
        return o:em():wrap2("\\scalebox{"..scale.."}")
      end,
  },
}

-- «Pict-tests»  (to ".Pict-tests")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
-- dofile "Pict2e3.lua"
dofile "PictRect1.lua"
p = Pict {"ab","cd","ef"} 
= p:wrap_00("\\foo{", " ", "}")
= p:wrap_01("\\foo{", " ", "}")
= p:wrap_02("\\foo{", " ", "}")
= p:wrap_10("\\foo{", " ", "}")
= p:wrap_11("\\foo{", " ", "}")
= p:wrap_12("\\foo{", " ", "}")
= p:wrap1("\\foo")
= p:wrap1()

ab = Pict {"a", "b"}
= ab:def"foo"
= ab:sa "foo"
= ab:Color"Red"
= ab:precolor"red"
= ab:prethickness"1pt"
= ab:preunitlength"1pt"   -- ok até aqui
= ab:bhbox()
= ab:myvcenter()
-- = ab:putat(v(2,3))
-- = ab:scalebox(2.3)

--]]


-- Local Variables:
-- coding:  utf-8-unix
-- End: