| 1 |
%=========================================================================== |
| 2 |
% luahyperbolic.sty |
| 3 |
% LuaLaTeX package for hyperbolic geometry |
| 4 |
% Version : ===DATEPLACEHOLDER=== |
| 5 |
% Automatically generated from the following files: |
| 6 |
% - complex.lua |
| 7 |
% - luahyperbolic-core.lua |
| 8 |
% - luahyperbolic-tikz.lua |
| 9 |
% - luahyperbolic-tilings.lua |
| 10 |
% source code and documentation: |
| 11 |
% https://github.com/dmegy/luahyperbolic |
| 12 |
% -- 2026 Damien Mégy |
| 13 |
%=========================================================================== |
| 14 |
|
| 15 |
\NeedsTeXFormat{LaTeX2e} |
| 16 |
\ProvidesPackage{luahyperbolic}[===DATEPLACEHOLDER=== Hyperbolic geometry package written in Lua.] |
| 17 |
|
| 18 |
\RequirePackage{iftex} |
| 19 |
\ifluatex |
| 20 |
\RequirePackage{luacode} |
| 21 |
\else |
| 22 |
{\PackageError{luahyperbolic} |
| 23 |
{Not running under LuaLaTeX} |
| 24 |
{This package requires LuaLaTeX. Try compiling this document with\MessageBreak 'lualatex' instead of 'latex', 'pdflatex' or 'xelatex'. This is a fatal error; I'm aborting now.}% |
| 25 |
}\stop |
| 26 |
\fi |
| 27 |
|
| 28 |
\RequirePackage{tikz} |
| 29 |
%\usetikzlibrary{decorations.markings} |
| 30 |
|
| 31 |
\begin{luacode*} |
| 32 |
-- ===LUACODEPLACEHOLDER=== |
| 33 |
\end{luacode*} |
| 34 |
|
| 35 |
|
| 36 |
\begin{luacode*} |
| 37 |
function parseKeyValueString(str) |
| 38 |
local options = {} |
| 39 |
|
| 40 |
str = str:gsub("%s+", "") -- Remove all spaces |
| 41 |
str = str:gsub(",%s*$", "") -- Remove trailing comma if any |
| 42 |
|
| 43 |
for key, value in string.gmatch(str, "([%w_]+)=([%w_%-%.!0-9]+)") do |
| 44 |
options[key] = value |
| 45 |
end |
| 46 |
|
| 47 |
return options |
| 48 |
end |
| 49 |
\end{luacode*} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
\DeclareDocumentCommand{\hyperbolicTiling}{ m m m O{} }{% |
| 54 |
% #1 = P, #2 = Q, #3 = R (mandatory) |
| 55 |
% #4 = options (optional, key-value string) |
| 56 |
\directlua{ |
| 57 |
local function isInfinite(value) |
| 58 |
local infinity_values = {"inf", "infty", "infinity", "math.huge"} |
| 59 |
for _, v in ipairs(infinity_values) do |
| 60 |
if value == v then |
| 61 |
return true |
| 62 |
end |
| 63 |
end |
| 64 |
return false |
| 65 |
end |
| 66 |
|
| 67 |
local function validate(arg) |
| 68 |
if isInfinite(arg) then |
| 69 |
return math.huge |
| 70 |
elseif tonumber(arg) and tonumber(arg) > 0 then |
| 71 |
return tonumber(arg) |
| 72 |
else |
| 73 |
error("Invalid value for argument: "..tostring(arg)..". Must be a positive integer or one of the allowed infinity values (inf, infty, infinity, math.huge).") |
| 74 |
end |
| 75 |
end |
| 76 |
|
| 77 |
local P = "#1" |
| 78 |
local Q = "#2" |
| 79 |
local R = "#3" |
| 80 |
|
| 81 |
P = validate(P) |
| 82 |
Q = validate(Q) |
| 83 |
R = validate(R) |
| 84 |
local options = "#4" |
| 85 |
local parsedOptions = parseKeyValueString(options) |
| 86 |
|
| 87 |
local depth = tonumber(parsedOptions.depth) or 8 |
| 88 |
local scale = tonumber(parsedOptions.scale) or 3 |
| 89 |
local color = parsedOptions.color or "black" |
| 90 |
local backgroundcolor = parsedOptions.backgroundcolor or "white" |
| 91 |
|
| 92 |
hyper.tikzBegin("scale="..scale) |
| 93 |
hyper.tikzPrintf("\\fill[color=" .. backgroundcolor .."] (0,0) circle (1);") |
| 94 |
hyper.fillTilingFromAngles(math.pi/P, math.pi/Q, math.pi/R, depth,color) |
| 95 |
hyper.tikzEnd() |
| 96 |
}% |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
% End of luahyperbolic.sty |