Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/Verbatim2.lua.html
--   http://anggtwu.net/LUA/Verbatim2.lua
--          (find-angg "LUA/Verbatim2.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Verbatim2.lua"))
-- (defun o () (interactive) (find-angg "LUA/Verbatim1.lua"))
--
-- Superseded by: (find-angg "LUA/Verbatim3.lua")
-- Supersedes:    (find-angg "LUA/Verbatim1.lua")
--                (find-LATEX "2021verbatim.lua")
--                (find-dednat6 "myverbatim.lua")
-- Used by:       (find-LATEXgrep "grep --color=auto -nH --null -e '^%V ' *.tex")
--                (c2m212isp 5 "set-compr-traducao")
--                (c2m212isa   "set-compr-traducao")
-- See:           (find-LATEX "edrx21.sty" "defvbt")

-- «.Verbatim»		(to "Verbatim")
-- «.Verbatim-tests»	(to "Verbatim-tests")
-- «.vbt-head»		(to "vbt-head")
--   «.defvbt»		(to "defvbt")
-- «.vbt-head-tests»	(to "vbt-head-tests")
-- «.show2»		(to "show2")

require "Show2"      -- (find-angg "LUA/Show2.lua")
require "Co1"        -- (find-angg "LUA/Co1.lua" "Co-tests")


-- __     __        _           _   _           
-- \ \   / /__ _ __| |__   __ _| |_(_)_ __ ___  
--  \ \ / / _ \ '__| '_ \ / _` | __| | '_ ` _ \ 
--   \ V /  __/ |  | |_) | (_| | |_| | | | | | |
--    \_/ \___|_|  |_.__/ \__,_|\__|_|_| |_| |_|
--                                              
-- «Verbatim»  (to ".Verbatim")
Verbatim = Class {
  type    = "Verbatim",
  from    = function (o) return Verbatim {o = o} end,
  __tostring = function (vb)
      if type(vb.o) == "string" then return vb.o end
      return mytostringv(vb.o)
    end,
  __index = {
    --
    -- See: (find-angg "LUA/Co1.lua" "Co-tests")
    -- vb:e(str) expands some (non-utf8) characters in str.
    co = Co.new("#$", " %&\\^_{}~"):add("\n", "\\\\\n"),
    e  = function (vb, s) return vb.co:translate(s) end,
    --
    -- Some functions that are not methods
    f = {
      e  = function (s) return Verbatim({}):e(s) end,
      v  = function (s) return format("\\vbox{%%\n%s%%\n}", s) end,
      h1 = function (s) return format("\\vbthbox{%s}", s) end,
      bg = function (s) return format("\\vbtbgbox{%s}", s) end,
    },
    --
    prefix = "  ",
    actions = {
      h  = function (vb) vb.o = map(vb.f.h1, vb.o) end,
      c  = function (vb) vb.o = table.concat(vb.o, "%\n"..vb.prefix) end,
      p  = function (vb) vb.o = vb.prefix..vb.o end,
      e  = function (vb) vb.o = map(vb.f.e, vb.o) end,
      v  = function (vb) vb.o = vb.f.v (vb.o) end,
      bg = function (vb) vb.o = vb.f.bg(vb.o) end,
      o  = function (vb) output(vb.o) end,
      P  = function (vb) print(vb) end,
      def = function (vb, name)
	  vb.o = format("\\def\\%s{%s}", name, vb.o)
        end,
      defvbt = function (vb, name)
          vb.o = format("\\defvbt{%s}{%s}", name, vb.o)
        end,
    },
    act = function (vb, str)
        for _,actionarg in ipairs(split(str)) do
	  local action,arg = actionarg:match("^([^:]+):?(.*)$")
	  if not vb.actions[action] then
	    error("Unrecognized action: "..action)
	  end
	  vb.actions[action](vb, arg)
	end
	return vb
      end,
    sa = function (vb, name)
        vb.o = format("\\sa{%s}{%s}", name, vb.o)
	return vb
      end,
    defvbt = function (vb, name)
        return vb:act("e h c p v bg defvbt:"..name)
      end,
  },
}

-- «Verbatim-tests»  (to ".Verbatim-tests")
-- See: (find-LATEX "edrx21.sty" "defvbt")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Verbatim2.lua"
output = print
= Verbatim.__index.co
= Verbatim({}):e "Hello #$\n%&\\^_{}~!!!\n  Hey  hey"

  Verbatim.from({"a", "bb", "ccc"}):act("P")
  Verbatim.from({"a", "bb", "ccc"}):act("c P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c p P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c v P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c p v P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg def:foo P")
  Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg defvbt:foo P")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg"):sa("[a b c] box")
  Verbatim.from({"a", "bb", "ccc"}):defvbt("foo"):act("o")

--]==]





-- «vbt-head»  (to ".vbt-head")
-- (find-LATEX "2021fitch.lua" "fitch-head")
registerhead = registerhead or function () return nop end
registerhead "%V" {
  name   = "vbt",
  action = function ()
      local i,j,origlines = tf:getblock()
      vbt_lines = origlines
    end,
}

-- «defvbt»  (to ".defvbt")
defvbt = function (name)
    Verbatim.from(vbt_lines):defvbt(name):act("o")
  end

-- «show2»  (to ".show2")
-- (find-angg "LUA/Show2.lua" "dednat6")
-- (find-angg "LUA/Show2.lua" "dednat6" "Verbatim2")



-- «vbt-head-tests»  (to ".vbt-head-tests")
--[==[
** (find-angg "LUA/Show2.lua" "texbody")
** (find-code-show2 "~/LATEX/Show2.tex")
*       (code-show2 "~/LATEX/Show2.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Verbatim2.lua"
usepackages.edrx21 = true
dednat6["0"]       = true
dednat6.Verbatim2  = true
= outertexbody

defs = [=[
%V foo
%V   bar
%L defvbt "foobar"
\pu
]=]

test = [[ a:\vbt{foobar}:b ]]
= test:show()
= Show.log
= Show.bigstr
* (etv)

--]==]








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