|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- https://anggtwu.net/LUA/DiagTeX1.lua.html
-- https://anggtwu.net/LUA/DiagTeX1.lua
-- (find-angg "LUA/DiagTeX1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2026may24
-- Used by:
--
-- A partial replacement for:
-- (find-dn6 "diagtex.lua")
-- (find-dn6 "diagtex.lua" "arrow_to_TeX")
-- (find-dn6 "diagtex.lua" "DxyArrow" "arrow_to_TeX")
-- (find-dn6 "diagforth.lua")
-- This file overrides some functions from diagtex.lua and defines a
-- new word in forths[].
--
-- «.coords» (to "coords")
-- «.node_to_TeX» (to "node_to_TeX")
-- «.arrow_to_TeX» (to "arrow_to_TeX")
-- «.diagxy_def_diag» (to "diagxy_def_diag")
-- «.diagxy_def_diag-tests» (to "diagxy_def_diag-tests")
-- «.arrowColor» (to "arrowColor")
-- «.DxyArrow» (to "DxyArrow")
-- «.DxyPlace» (to "DxyPlace")
-- «.DxyLiteral» (to "DxyLiteral")
-- «.DxyLoop» (to "DxyLoop")
require "DiagStacks1" -- (find-angg "LUA/DiagStacks1.lua")
require "DiagForth1" -- (find-angg "LUA/DiagForth1.lua")
require "Pict4" -- (find-angg "LUA/Pict4.lua")
unabbrev = unabbrev or id
-- ____ _
-- / ___|___ ___ _ __ __| |___
-- | | / _ \ / _ \| '__/ _` / __|
-- | |__| (_) | (_) | | | (_| \__ \
-- \____\___/ \___/|_| \__,_|___/
--
-- «coords» (to ".coords")
-- Copied from: (find-dn6 "diagtex.lua" "coords")
dxyorigx = 100
dxyorigy = 100
dxyscale = 15
realx = function (x) return dxyscale * (x - dxyorigx) end
realy = function (y) return -dxyscale * (y - dxyorigy) end
realxy = function (x, y) return realx(x), realy(y) end
-- _ _ _____ __ __
-- _ __ ___ __| | ___ | |_ ___ |_ _|__\ \/ /
-- | '_ \ / _ \ / _` |/ _ \ | __/ _ \ | |/ _ \\ /
-- | | | | (_) | (_| | __/ | || (_) | | | __// \
-- |_| |_|\___/ \__,_|\___|___\__\___/___|_|\___/_/\_\
-- |_____| |_____|
--
-- «node_to_TeX» (to ".node_to_TeX")
-- Copied from: (find-dn6 "diagtex.lua" "node_to_TeX")
node_to_TeX = function (node)
local tex = node.tex or node.tag
local TeX = node.TeX or (tex and unabbrev(tex))
return (TeX and "{"..TeX.."}") or ""
end
-- _ _____ __ __
-- __ _ _ __ _ __ _____ __| |_ ___ |_ _|__\ \/ /
-- / _` | '__| '__/ _ \ \ /\ / /| __/ _ \ | |/ _ \\ /
-- | (_| | | | | | (_) \ V V / | || (_) | | | __// \
-- \__,_|_| |_| \___/ \_/\_/___\__\___/___|_|\___/_/\_\
-- |_____| |_____|
--
-- «arrow_to_TeX» (to ".arrow_to_TeX")
-- Based on: (find-dn6 "diagtex.lua" "arrow_to_TeX")
-- The (fragile) support for colored arrows is for:
-- (wiyp 17 "reconstruct-yoneda")
-- (wiya "reconstruct-yoneda")
diag_wrap = function (fmt,body)
return format(fmt or "%s", body)
end
arrow_to_TeX = function (arrow)
local node1 = nodes[arrow.from]
local node2 = nodes[arrow.to]
local x1,y1 = realxy(node1.x, node1.y)
local x2,y2 = realxy(node2.x, node2.y)
local dx,dy = x2-x1, y2-y1
local N1 = node_to_TeX(node1)
local N2 = node_to_TeX(node2)
--
-- 2026may24:
N1 = diag_wrap(arrow.wrap_from, N1)
N2 = diag_wrap(arrow.wrap_to, N2)
--
-- Calculate p, sh, L.
-- In several complex cases the "placement" p and the "label" L
-- are moved into the "shape" parameter sh; see:
-- (find-es "diagxy" "shape")
local p, sh, L = arrow_to_TeX_pshL(arrow) -- defined below
local morphism = dformat("\\morphism(%d,%d)%s%s<%d,%d>[%s`%s;%s]",
x1, y1, p, sh, dx, dy, N1, N2, L)
return diag_wrap(arrow.wrap_morphism, morphism)
end
arrow_to_TeX_pshL = function (arrow)
local Label = arrow.Label or (arrow.label and unabbrev(arrow.label))
local L = Label and "{"..Label.."}" or ""
local p = arrow.placement and "|"..arrow.placement.."|" or ""
local lplace = arrow.lplacement and arrow.lplacement.."{"..Label.."}"
--
-- 2026may24:
L = diag_wrap(arrow.wrap_label, L)
--
local shape = arrow.shape or "->"
local slide = arrow.slide and "@<"..arrow.slide..">"
local curve = arrow.curve and "@/"..arrow.curve.."/"
local modifier
if slide or curve or lplace then
modifier = (lplace or "")..(slide or "")..(curve or "")
end
if arrow.modifier then modifier = arrow.modifier end -- temp hack
if modifier then
sh = format("/{@{%s}%s}/", shape, modifier)
else
sh = "/"..shape.."/"
end
if lplace then p = "||"; L = "" end
return p, sh, L
end
-- «diagxy_def_diag» (to ".diagxy_def_diag")
-- Used by: (find-angg "LUA/DiagForth1.lua" "enddiagram")
-- See: (find-angg "LUA/DednatPreamble1.lua" "preamble1" "\\bfig#2\\efig")
-- (find-angg "LUA/DiagTikz1.lua" "Tikz_diag_body")
-- (find-angg "LUA/DiagTikz1.lua" "enddiagram")
-- (find-angg "LUA/TreeTeX1.lua" "ProofSty" "defded =")
-- (find-dn6 "diagtex.lua" "arrows_to_defdiag")
diagxy_diag_body = function ()
local f = function (ar) return ar:TeX() end
return Pict(map(f, arrows))
end
diagxy_diag = function ()
return diagxy_diag_body() -- :wrapbe("\\bfig", "\\efig")
end
diagxy_def_diag = function (name) -- not yet: hyperlink
local topline = "\\defdiag{"..name.."}{"
local diag = diagxy_diag()
return topline / (" " .. diag) / "}"
end
-- «diagxy_def_diag-tests» (to ".diagxy_def_diag-tests")
-- (find-angg "LUA/DiagForth1.lua" "2D-and-2Dx-tests")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "DiagTeX1.lua"
dxyrun "2Dx 100 +20 +20"
dxyrun "2D 100 A"
dxyrun "2D /|\\"
dxyrun "2D v v v"
dxyrun "2D +30 FA --> GA"
dxyrun "(( A FA ->"
dxyrun " A GA ->"
dxyrun "))"
= arrows
= diagxy_def_diag("Foo")
--]==]
-- ____ _
-- __ _ _ __ _ __ _____ __/ ___|___ | | ___ _ __
-- / _` | '__| '__/ _ \ \ /\ / / | / _ \| |/ _ \| '__|
-- | (_| | | | | | (_) \ V V /| |__| (_) | | (_) | |
-- \__,_|_| |_| \___/ \_/\_/ \____\___/|_|\___/|_|
--
-- «arrowColor» (to ".arrowColor")
-- Based on: (find-angg "LUA/DiagForth1.lua" "arrow-modifiers")
-- Used by: (wiyp 17 "reconstruct-yoneda")
-- (wiya "reconstruct-yoneda")
forths = forths or VTable {} -- for tests
forthe = forthe or VTable {} -- for tests
forthe[".arrowColor="] = "w"
forths[".arrowColor="] = function (Color)
ds:pick(0).wrap_morphism = "\\Color"..Color.."{%s}%%"
ds:pick(0).wrap_label = "\\ColorBlack{%s}"
ds:pick(0).wrap_from = "\\ColorBlack{%s}"
ds:pick(0).wrap_to = "\\ColorBlack{%s}"
end
forthe[".arrowcolorwrap="] = "w"
forths[".arrowcolorwrap="] = function (fmt)
ds:pick(0).wrap_morphism = fmt
ds:pick(0).wrap_label = "\\ColorBlack{%s}"
ds:pick(0).wrap_from = "\\ColorBlack{%s}"
ds:pick(0).wrap_to = "\\ColorBlack{%s}"
end
-- ____ _
-- | _ \__ ___ _ / \ _ __ _ __ _____ __
-- | | | \ \/ / | | | / _ \ | '__| '__/ _ \ \ /\ / /
-- | |_| |> <| |_| |/ ___ \| | | | | (_) \ V V /
-- |____//_/\_\\__, /_/ \_\_| |_| \___/ \_/\_/
-- |___/
--
-- Initially the array `arrows' only held "DxyArrow" objects,
-- and each "DxyArrow" object had a ".TeX" method...
-- At some point I added other "arrow-like" objects, that could
-- also be placed into the arrow `arrows', and that also had
-- ".TeX" methods.
--
-- Used by: (to "arrow_to_TeX")
-- Uses: (find-angg "LUA/DiagStacks1.lua" "arrows")
--
-- «DxyArrow» (to ".DxyArrow")
-- Copied from: (find-dn6 "diagtex.lua" "DxyArrow")
DxyArrow = Class {
type = "DxyArrow",
__index = {
TeX = function (ar) return arrow_to_TeX(ar) end,
},
}
-- «DxyPlace» (to ".DxyPlace")
-- Copied from: (find-dn6 "diagtex.lua" "DxyPlace")
DxyPlace = Class {
type = "DxyPlace",
__index = {
TeX = function (pseudoar)
local node = pseudoar[1]
local x, y = realxy(node.x, node.y)
return dformat("\\place(%d,%d)[{%s}]", x, y, node_to_TeX(node))
end,
},
}
-- «DxyLiteral» (to ".DxyLiteral")
-- Copied from: (find-dn6 "diagtex.lua" "DxyLiteral")
DxyLiteral = Class {
type = "DxyLiteral",
__index = {
TeX = function (pseudoar) return pseudoar[1] end,
},
}
-- «DxyLoop» (to ".DxyLoop")
-- Copied from: (find-dn6 "diagtex.lua" "DxyLoop")
DxyLoop = Class {
type = "DxyLoop",
__index = {
TeX = function (pseudoar)
local node, dTeX = pseudoar[1], pseudoar.dTeX
local x, y = realxy(node.x, node.y)
return dformat("\\Loop(%d,%d){%s}%s", x, y, node_to_TeX(node), dTeX)
end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "DiagTeX1.lua"
--]]
-- (defun e () (interactive) (find-angg "LUA/DiagTeX1.lua"))
-- Local Variables:
-- coding: utf-8-unix
-- End: