|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/Pygments1.lua.html
-- http://anggtwu.net/LUA/Pygments1.lua
-- (find-angg "LUA/Pygments1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- «.introduction» (to "introduction")
-- «.PygSplit» (to "PygSplit")
-- «.PygSplit-tests» (to "PygSplit-tests")
-- «.Verbatim-methods» (to "Verbatim-methods")
-- «.defpygvbt» (to "defpygvbt")
-- «introduction» (to ".introduction")
--
-- Introduction
-- ============
-- This file defines some extensions for Verbatim3.lua.
-- Look at this example, from the introduction of Verbatim3.lua:
-- (find-LATEX "Verbatim3.lua" "introduction")
-- (find-LATEX "Verbatim3.lua" "introduction" "%V")
-- (find-LATEX "Verbatim3.lua" "introduction" "%L defvbt")
-- (find-LATEX "Verbatim3.lua" "introduction" "\\defvbt{")
--
-- With Verbatim3.lua we typeset a "verbatim box" in this way:
-- 1. The "%V"-block in the example above sets the variable "vbt_lines",
-- 2. The "%L"-block with the "defvbt" outputs a "\defvbt{...}{...}",
-- 3. The "\vbt{...}" runs a "\ga{...}", that inserts the box.
--
-- In this variant the "%L"-block calls "defpygvbt" instead of
-- "defvbt", and "defpygvbt" processes the contents of the "%V"-block
-- in a different way. TODO: EXAMPLES!
--
-- \defvbt{T1 T2}{\vbtbgbox{\vbox{%
-- \vbthbox{...}%
-- \vbthbox{...}%
-- }}}
--
-- (defun e () (interactive) (find-angg "LUA/Pygments1.lua"))
-- Used by: (find-LATEX "2025bad-foundations.tex" "defs-pygvbt")
--
-- (find-LATEX "Verbatim3.lua" "dednat6")
-- See: (find-es "pygments" "mypygments.sh")
-- (find-angg ".emacs.templates" "find-leanhtml-links")
-- (find-angg ".emacs.templates" "find-pyghtml-links")
require "Dednat7" -- (find-LATEX "Dednat7.lua")
require "Verbatim3" -- (find-LATEX "Verbatim3.lua")
-- ____ ____ _ _ _
-- | _ \ _ _ __ _/ ___| _ __ | (_) |_
-- | |_) | | | |/ _` \___ \| '_ \| | | __|
-- | __/| |_| | (_| |___) | |_) | | | |_
-- |_| \__, |\__, |____/| .__/|_|_|\__|
-- |___/ |___/ |_|
--
-- «PygSplit» (to ".PygSplit")
PygSplit = Class {
type = "PygSplit",
fromfile = function (fname)
return PygSplit { bigstr = ee_readfile(fname) }
end,
__index = {
--pat_texdefs = "\\makeatletter\n(.-)\n\\makeatother",
pat_texdefs = "(\\makeatletter\n.-\n\\makeatother)",
pat_texbody = "\\begin{Verbatim}[^\n]*\n(.-)\n\\end{Verbatim}",
texdefs = function (ps) return torect(ps.bigstr:match(ps.pat_texdefs)) end,
texbody = function (ps) return torect(ps.bigstr:match(ps.pat_texbody)) end,
defpygvbt = function (ps,name)
local V = "%V " * ps:texbody()
local L = Rect {"", format('%%L defpygvbt("%s")', name), "\\pu"}
return V / L
end,
},
}
-- «PygSplit-tests» (to ".PygSplit-tests")
-- (find-angg ".emacs" "ee-copy-rest-3-cat")
-- (find-es "pygments" "mypygments.sh")
--[==[
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
rm -Rv /tmp/pyg/
mkdir /tmp/pyg/
cd /tmp/pyg/
cp -v ~/LEAN/2025-bad-foundations.lean /tmp/pyg/a.lean
cat a.lean
pygmentize -O full -o a.lean.full.tex a.lean
# (find-fline "/tmp/pyg/a.lean.full.tex")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Pygments1.lua"
p = PygSplit.fromfile "/tmp/pyg/a.lean.full.tex"
= p.bigstr
= p:texdefs()
= p:texbody()
= p:defpygvbt("foo")
--]==]
-- «Verbatim-methods» (to ".Verbatim-methods")
-- (find-LATEX "Verbatim3.lua" "Verbatim")
-- (find-LATEX "Verbatim3.lua" "Verbatim" "_e =")
-- (find-LATEX "Verbatim3.lua" "Verbatim" "defvbt =")
pyg_expandspaces = function (str)
local f = function (s) return (s:gsub(" ", "\\ ")) end
return (str:gsub("({ +})", f))
end
Verbatim.__index._pyg = function (vb)
vb.o = map(pyg_expandspaces, vb.o)
end
Verbatim.__index.defpygvbt = function (vb, name)
return vb:act("pyg h c p v bg"):defvbt0(name)
end
-- «defpygvbt» (to ".defpygvbt")
-- (find-LATEX "Verbatim3.lua" "dednat6" "defvbt =")
defpygvbt = function (name)
Verbatim.from(vbt_lines):defpygvbt(name):act("o")
end
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Pygments1.lua"
= pyg_expandspaces("foo{ }bar{ }plic")
tf = TeXFile.read("~/LATEX/2025bad-foundations-lean.tex")
tf:processuntil(#tf)
= tf
= VTable(vbt_lines)
vb = Verbatim.from(vbt_lines)
= vb
= vb:defpygvbt("T1 T2 T3 T4")
--]]