|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- https://anggtwu.net/LUA/TocLines3.lua.html
-- https://anggtwu.net/LUA/TocLines3.lua
-- (find-angg "LUA/TocLines3.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/TocLines3.lua"))
-- (defun o () (interactive) (find-angg "LUA/TocLines2.lua"))
-- (defun oo () (interactive) (find-angg "LUA/TocLines1.lua"))
--
-- Used in:
-- (find-LATEX "edrx26c.tex" "TocLines3")
-- (find-Deps1-links "TocLines3")
-- (find-Deps1-cps "TocLines3")
-- (find-Deps1-anggs "TocLines3")
-- «.TocLines3» (to "TocLines3")
-- «.TocLines3-tests» (to "TocLines3-tests")
-- _____ _ _ _____
-- |_ _|__ ___| | (_)_ __ ___ ___|___ /
-- | |/ _ \ / __| | | | '_ \ / _ \/ __| |_ \
-- | | (_) | (__| |___| | | | | __/\__ \___) |
-- |_|\___/ \___|_____|_|_| |_|\___||___/____/
--
-- «TocLines3» (to ".TocLines3")
TocLines3 = Class {
type = "TocLines3",
new = function (fname) return TocLines3 {fname=fname} end,
fmts = VTable {},
__tostring = function (tls) return tls:totex() end,
__index = {
add = function (tls, o) table.insert(tls, o); PP(o) end,
getfmt = function (tls, style) return TocLines3.fmts[style] end,
format = function (tls, o) return tls:format0(o, tls:getfmt(o.style)) end,
format0 = function (tls, o, fmt)
local f = function (s) return o[s] end
return (fmt:gsub("<(.-)>", f))
end,
totex = function (tls)
local f = function (i)
if type(tls[i]) == "string" then return tls[i] end
return tls:format(tls[i])
end
return mapconcat(f, seq(1, #tls), "")
end,
--
tocbody = function (tls) return "\n"..tls:totex().."\n" end,
tocfname = function (tls) return tls:fnamestem()..".mytoc" end,
fnamestem = function (tls)
return (tls.fname:gsub("%.tex$", ""):gsub("%.mytoc$", ""))
end,
writetoc = function (tls)
ee_writefile(tls:tocfname(), tls:tocbody())
print("Writing: "..tls:tocfname())
return tls
end,
},
}
TocLines3.fmts["slide"] = "\\toclineslidetex {<body>} {<page>}\n"
TocLines3.fmts["slident"] = "\\toclineslidenttex {<body>} {<page>}\n"
-- «TocLines3-tests» (to ".TocLines3-tests")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "TocLines3.lua"
tls = TocLines3.new("/tmp/toclines2-test.tex")
TocLines3.fmts["slide"] = "_<page>_<body>_\n"
tls:add {style="slide", page=2, body="Links"}
tls:add {style="slide", page=3, body="Intro"}
tls:add "BLA\n"
tls:add {style="slide", page=4, body="More stuff"}
= tls:getfmt("slide")
= tls:format(tls[1])
= tls:format(tls[2])
= tls:format(tls[4])
= tls:totex()
= tls:tocbody()
= tls:fnamestem()
= tls:tocfname()
= tls:writetoc()
TocLines3.fmts["slide"] = "\\mytocline{<page>}{<body>}\n"
= tls:totex()
--]==]
-- Local Variables:
-- coding: utf-8-unix
-- End: