tiny.zen.math.symbol
Defined in math.
API (7)
Actions
Public operations.
Types and contracts
Public types and contracts.
Values and defaults
Public values and defaults.
Source
Source: lib/zen/src/math/root.zig:5
zig
pub const symbol = @import("symbol.zig");Source: lib/zen/src/math/symbol.zig
zig
const std = @import("std");pub const Kind = enum { identifier, function, operator, fence, largeop, integral, movableop, space, accent,};pub const Entry = struct { kind: Kind, text: []const u8, upright: bool = false,};pub const commands = std.StaticStringMap(Entry).initComptime(.{ .{ "alpha", Entry{ .kind = .identifier, .text = "α" } }, .{ "beta", Entry{ .kind = .identifier, .text = "β" } }, .{ "gamma", Entry{ .kind = .identifier, .text = "γ" } }, .{ "delta", Entry{ .kind = .identifier, .text = "δ" } }, .{ "epsilon", Entry{ .kind = .identifier, .text = "ϵ" } }, .{ "varepsilon", Entry{ .kind = .identifier, .text = "ε" } }, .{ "zeta", Entry{ .kind = .identifier, .text = "ζ" } }, .{ "eta", Entry{ .kind = .identifier, .text = "η" } }, .{ "theta", Entry{ .kind = .identifier, .text = "θ" } }, .{ "vartheta", Entry{ .kind = .identifier, .text = "ϑ" } }, .{ "iota", Entry{ .kind = .identifier, .text = "ι" } }, .{ "kappa", Entry{ .kind = .identifier, .text = "κ" } }, .{ "lambda", Entry{ .kind = .identifier, .text = "λ" } }, .{ "mu", Entry{ .kind = .identifier, .text = "μ" } }, .{ "nu", Entry{ .kind = .identifier, .text = "ν" } }, .{ "xi", Entry{ .kind = .identifier, .text = "ξ" } }, .{ "pi", Entry{ .kind = .identifier, .text = "π" } }, .{ "varpi", Entry{ .kind = .identifier, .text = "ϖ" } }, .{ "rho", Entry{ .kind = .identifier, .text = "ρ" } }, .{ "varrho", Entry{ .kind = .identifier, .text = "ϱ" } }, .{ "sigma", Entry{ .kind = .identifier, .text = "σ" } }, .{ "varsigma", Entry{ .kind = .identifier, .text = "ς" } }, .{ "tau", Entry{ .kind = .identifier, .text = "τ" } }, .{ "upsilon", Entry{ .kind = .identifier, .text = "υ" } }, .{ "phi", Entry{ .kind = .identifier, .text = "ϕ" } }, .{ "varphi", Entry{ .kind = .identifier, .text = "φ" } }, .{ "chi", Entry{ .kind = .identifier, .text = "χ" } }, .{ "psi", Entry{ .kind = .identifier, .text = "ψ" } }, .{ "omega", Entry{ .kind = .identifier, .text = "ω" } }, .{ "Gamma", Entry{ .kind = .identifier, .text = "Γ", .upright = true } }, .{ "Delta", Entry{ .kind = .identifier, .text = "Δ", .upright = true } }, .{ "Theta", Entry{ .kind = .identifier, .text = "Θ", .upright = true } }, .{ "Lambda", Entry{ .kind = .identifier, .text = "Λ", .upright = true } }, .{ "Xi", Entry{ .kind = .identifier, .text = "Ξ", .upright = true } }, .{ "Pi", Entry{ .kind = .identifier, .text = "Π", .upright = true } }, .{ "Sigma", Entry{ .kind = .identifier, .text = "Σ", .upright = true } }, .{ "Upsilon", Entry{ .kind = .identifier, .text = "Υ", .upright = true } }, .{ "Phi", Entry{ .kind = .identifier, .text = "Φ", .upright = true } }, .{ "Psi", Entry{ .kind = .identifier, .text = "Ψ", .upright = true } }, .{ "Omega", Entry{ .kind = .identifier, .text = "Ω", .upright = true } }, .{ "infty", Entry{ .kind = .identifier, .text = "∞", .upright = true } }, .{ "partial", Entry{ .kind = .identifier, .text = "∂" } }, .{ "nabla", Entry{ .kind = .identifier, .text = "∇", .upright = true } }, .{ "hbar", Entry{ .kind = .identifier, .text = "ℏ" } }, .{ "ell", Entry{ .kind = .identifier, .text = "ℓ" } }, .{ "Re", Entry{ .kind = .identifier, .text = "ℜ", .upright = true } }, .{ "Im", Entry{ .kind = .identifier, .text = "ℑ", .upright = true } }, .{ "aleph", Entry{ .kind = .identifier, .text = "ℵ", .upright = true } }, .{ "emptyset", Entry{ .kind = .identifier, .text = "∅", .upright = true } }, .{ "varnothing", Entry{ .kind = .identifier, .text = "∅", .upright = true } }, .{ "imath", Entry{ .kind = .identifier, .text = "ı" } }, .{ "jmath", Entry{ .kind = .identifier, .text = "ȷ" } }, .{ "cdot", Entry{ .kind = .operator, .text = "⋅" } }, .{ "times", Entry{ .kind = .operator, .text = "×" } }, .{ "div", Entry{ .kind = .operator, .text = "÷" } }, .{ "pm", Entry{ .kind = .operator, .text = "±" } }, .{ "mp", Entry{ .kind = .operator, .text = "∓" } }, .{ "le", Entry{ .kind = .operator, .text = "≤" } }, .{ "leq", Entry{ .kind = .operator, .text = "≤" } }, .{ "ge", Entry{ .kind = .operator, .text = "≥" } }, .{ "geq", Entry{ .kind = .operator, .text = "≥" } }, .{ "ne", Entry{ .kind = .operator, .text = "≠" } }, .{ "neq", Entry{ .kind = .operator, .text = "≠" } }, .{ "ll", Entry{ .kind = .operator, .text = "≪" } }, .{ "gg", Entry{ .kind = .operator, .text = "≫" } }, .{ "approx", Entry{ .kind = .operator, .text = "≈" } }, .{ "sim", Entry{ .kind = .operator, .text = "∼" } }, .{ "simeq", Entry{ .kind = .operator, .text = "≃" } }, .{ "cong", Entry{ .kind = .operator, .text = "≅" } }, .{ "equiv", Entry{ .kind = .operator, .text = "≡" } }, .{ "propto", Entry{ .kind = .operator, .text = "∝" } }, .{ "in", Entry{ .kind = .operator, .text = "∈" } }, .{ "notin", Entry{ .kind = .operator, .text = "∉" } }, .{ "ni", Entry{ .kind = .operator, .text = "∋" } }, .{ "subset", Entry{ .kind = .operator, .text = "⊂" } }, .{ "supset", Entry{ .kind = .operator, .text = "⊃" } }, .{ "subseteq", Entry{ .kind = .operator, .text = "⊆" } }, .{ "supseteq", Entry{ .kind = .operator, .text = "⊇" } }, .{ "cup", Entry{ .kind = .operator, .text = "∪" } }, .{ "cap", Entry{ .kind = .operator, .text = "∩" } }, .{ "setminus", Entry{ .kind = .operator, .text = "∖" } }, .{ "wedge", Entry{ .kind = .operator, .text = "∧" } }, .{ "land", Entry{ .kind = .operator, .text = "∧" } }, .{ "vee", Entry{ .kind = .operator, .text = "∨" } }, .{ "lor", Entry{ .kind = .operator, .text = "∨" } }, .{ "oplus", Entry{ .kind = .operator, .text = "⊕" } }, .{ "ominus", Entry{ .kind = .operator, .text = "⊖" } }, .{ "otimes", Entry{ .kind = .operator, .text = "⊗" } }, .{ "odot", Entry{ .kind = .operator, .text = "⊙" } }, .{ "circ", Entry{ .kind = .operator, .text = "∘" } }, .{ "bullet", Entry{ .kind = .operator, .text = "•" } }, .{ "star", Entry{ .kind = .operator, .text = "⋆" } }, .{ "ast", Entry{ .kind = .operator, .text = "∗" } }, .{ "to", Entry{ .kind = .operator, .text = "→" } }, .{ "rightarrow", Entry{ .kind = .operator, .text = "→" } }, .{ "leftarrow", Entry{ .kind = .operator, .text = "←" } }, .{ "gets", Entry{ .kind = .operator, .text = "←" } }, .{ "mapsto", Entry{ .kind = .operator, .text = "↦" } }, .{ "hookrightarrow", Entry{ .kind = .operator, .text = "↪" } }, .{ "Rightarrow", Entry{ .kind = .operator, .text = "⇒" } }, .{ "Leftarrow", Entry{ .kind = .operator, .text = "⇐" } }, .{ "leftrightarrow", Entry{ .kind = .operator, .text = "↔" } }, .{ "Leftrightarrow", Entry{ .kind = .operator, .text = "⇔" } }, .{ "iff", Entry{ .kind = .operator, .text = "⇔" } }, .{ "implies", Entry{ .kind = .operator, .text = "⇒" } }, .{ "uparrow", Entry{ .kind = .operator, .text = "↑" } }, .{ "downarrow", Entry{ .kind = .operator, .text = "↓" } }, .{ "rightharpoonup", Entry{ .kind = .operator, .text = "⇀" } }, .{ "mid", Entry{ .kind = .operator, .text = "∣" } }, .{ "parallel", Entry{ .kind = .operator, .text = "∥" } }, .{ "perp", Entry{ .kind = .operator, .text = "⊥" } }, .{ "vdash", Entry{ .kind = .operator, .text = "⊢" } }, .{ "models", Entry{ .kind = .operator, .text = "⊨" } }, .{ "angle", Entry{ .kind = .operator, .text = "∠" } }, .{ "forall", Entry{ .kind = .operator, .text = "∀" } }, .{ "exists", Entry{ .kind = .operator, .text = "∃" } }, .{ "neg", Entry{ .kind = .operator, .text = "¬" } }, .{ "lnot", Entry{ .kind = .operator, .text = "¬" } }, .{ "prime", Entry{ .kind = .operator, .text = "′" } }, .{ "dots", Entry{ .kind = .operator, .text = "…" } }, .{ "ldots", Entry{ .kind = .operator, .text = "…" } }, .{ "cdots", Entry{ .kind = .operator, .text = "⋯" } }, .{ "vdots", Entry{ .kind = .operator, .text = "⋮" } }, .{ "ddots", Entry{ .kind = .operator, .text = "⋱" } }, .{ "backslash", Entry{ .kind = .operator, .text = "\\" } }, .{ "bmod", Entry{ .kind = .function, .text = "mod" } }, .{ "langle", Entry{ .kind = .fence, .text = "⟨" } }, .{ "rangle", Entry{ .kind = .fence, .text = "⟩" } }, .{ "lfloor", Entry{ .kind = .fence, .text = "⌊" } }, .{ "rfloor", Entry{ .kind = .fence, .text = "⌋" } }, .{ "lceil", Entry{ .kind = .fence, .text = "⌈" } }, .{ "rceil", Entry{ .kind = .fence, .text = "⌉" } }, .{ "lvert", Entry{ .kind = .fence, .text = "|" } }, .{ "rvert", Entry{ .kind = .fence, .text = "|" } }, .{ "vert", Entry{ .kind = .fence, .text = "|" } }, .{ "lVert", Entry{ .kind = .fence, .text = "‖" } }, .{ "rVert", Entry{ .kind = .fence, .text = "‖" } }, .{ "Vert", Entry{ .kind = .fence, .text = "‖" } }, .{ "|", Entry{ .kind = .fence, .text = "‖" } }, .{ "{", Entry{ .kind = .fence, .text = "{" } }, .{ "}", Entry{ .kind = .fence, .text = "}" } }, .{ "$", Entry{ .kind = .identifier, .text = "$", .upright = true } }, .{ "%", Entry{ .kind = .identifier, .text = "%", .upright = true } }, .{ "#", Entry{ .kind = .identifier, .text = "#", .upright = true } }, .{ "&", Entry{ .kind = .identifier, .text = "&", .upright = true } }, .{ "_", Entry{ .kind = .identifier, .text = "_", .upright = true } }, .{ "sum", Entry{ .kind = .largeop, .text = "∑" } }, .{ "prod", Entry{ .kind = .largeop, .text = "∏" } }, .{ "coprod", Entry{ .kind = .largeop, .text = "∐" } }, .{ "bigcup", Entry{ .kind = .largeop, .text = "⋃" } }, .{ "bigcap", Entry{ .kind = .largeop, .text = "⋂" } }, .{ "bigoplus", Entry{ .kind = .largeop, .text = "⨁" } }, .{ "bigotimes", Entry{ .kind = .largeop, .text = "⨂" } }, .{ "bigodot", Entry{ .kind = .largeop, .text = "⨀" } }, .{ "bigwedge", Entry{ .kind = .largeop, .text = "⋀" } }, .{ "bigvee", Entry{ .kind = .largeop, .text = "⋁" } }, .{ "int", Entry{ .kind = .integral, .text = "∫" } }, .{ "iint", Entry{ .kind = .integral, .text = "∬" } }, .{ "iiint", Entry{ .kind = .integral, .text = "∭" } }, .{ "oint", Entry{ .kind = .integral, .text = "∮" } }, .{ "lim", Entry{ .kind = .movableop, .text = "lim" } }, .{ "limsup", Entry{ .kind = .movableop, .text = "lim sup" } }, .{ "liminf", Entry{ .kind = .movableop, .text = "lim inf" } }, .{ "max", Entry{ .kind = .movableop, .text = "max" } }, .{ "min", Entry{ .kind = .movableop, .text = "min" } }, .{ "sup", Entry{ .kind = .movableop, .text = "sup" } }, .{ "inf", Entry{ .kind = .movableop, .text = "inf" } }, .{ "argmax", Entry{ .kind = .movableop, .text = "arg max" } }, .{ "argmin", Entry{ .kind = .movableop, .text = "arg min" } }, .{ "log", Entry{ .kind = .function, .text = "log" } }, .{ "ln", Entry{ .kind = .function, .text = "ln" } }, .{ "lg", Entry{ .kind = .function, .text = "lg" } }, .{ "exp", Entry{ .kind = .function, .text = "exp" } }, .{ "sin", Entry{ .kind = .function, .text = "sin" } }, .{ "cos", Entry{ .kind = .function, .text = "cos" } }, .{ "tan", Entry{ .kind = .function, .text = "tan" } }, .{ "cot", Entry{ .kind = .function, .text = "cot" } }, .{ "sec", Entry{ .kind = .function, .text = "sec" } }, .{ "csc", Entry{ .kind = .function, .text = "csc" } }, .{ "arcsin", Entry{ .kind = .function, .text = "arcsin" } }, .{ "arccos", Entry{ .kind = .function, .text = "arccos" } }, .{ "arctan", Entry{ .kind = .function, .text = "arctan" } }, .{ "sinh", Entry{ .kind = .function, .text = "sinh" } }, .{ "cosh", Entry{ .kind = .function, .text = "cosh" } }, .{ "tanh", Entry{ .kind = .function, .text = "tanh" } }, .{ "coth", Entry{ .kind = .function, .text = "coth" } }, .{ "det", Entry{ .kind = .function, .text = "det" } }, .{ "dim", Entry{ .kind = .function, .text = "dim" } }, .{ "ker", Entry{ .kind = .function, .text = "ker" } }, .{ "deg", Entry{ .kind = .function, .text = "deg" } }, .{ "gcd", Entry{ .kind = .function, .text = "gcd" } }, .{ "Pr", Entry{ .kind = .function, .text = "Pr" } }, .{ "arg", Entry{ .kind = .function, .text = "arg" } }, .{ ",", Entry{ .kind = .space, .text = "0.167em" } }, .{ ":", Entry{ .kind = .space, .text = "0.222em" } }, .{ ";", Entry{ .kind = .space, .text = "0.278em" } }, .{ " ", Entry{ .kind = .space, .text = "0.25em" } }, .{ "quad", Entry{ .kind = .space, .text = "1em" } }, .{ "qquad", Entry{ .kind = .space, .text = "2em" } }, .{ "hat", Entry{ .kind = .accent, .text = "ˆ" } }, .{ "widehat", Entry{ .kind = .accent, .text = "ˆ" } }, .{ "bar", Entry{ .kind = .accent, .text = "¯" } }, .{ "overline", Entry{ .kind = .accent, .text = "¯" } }, .{ "tilde", Entry{ .kind = .accent, .text = "˜" } }, .{ "widetilde", Entry{ .kind = .accent, .text = "˜" } }, .{ "vec", Entry{ .kind = .accent, .text = "⃗" } }, .{ "dot", Entry{ .kind = .accent, .text = "˙" } }, .{ "ddot", Entry{ .kind = .accent, .text = "¨" } }, .{ "check", Entry{ .kind = .accent, .text = "ˇ" } }, .{ "breve", Entry{ .kind = .accent, .text = "˘" } }, .{ "mathring", Entry{ .kind = .accent, .text = "˚" } },});pub const Environment = struct { open: ?[]const u8 = null, close: ?[]const u8 = null, class: ?[]const u8 = null, display_cells: bool = false,};pub const environments = std.StaticStringMap(Environment).initComptime(.{ .{ "matrix", Environment{} }, .{ "pmatrix", Environment{ .open = "(", .close = ")" } }, .{ "bmatrix", Environment{ .open = "[", .close = "]" } }, .{ "Bmatrix", Environment{ .open = "{", .close = "}" } }, .{ "vmatrix", Environment{ .open = "|", .close = "|" } }, .{ "Vmatrix", Environment{ .open = "‖", .close = "‖" } }, .{ "cases", Environment{ .open = "{", .class = "zen-cases" } }, .{ "aligned", Environment{ .class = "zen-aligned", .display_cells = true } },});pub const Style = enum { bb, cal, frak, bf };pub fn styled(style: Style, char: u8) ?u21 { return switch (style) { .bb => styledBb(char), .cal => styledCal(char), .frak => styledFrak(char), .bf => styledBf(char), };}fn styledBb(char: u8) ?u21 { switch (char) { 'C' => return 0x2102, 'H' => return 0x210D, 'N' => return 0x2115, 'P' => return 0x2119, 'Q' => return 0x211A, 'R' => return 0x211D, 'Z' => return 0x2124, else => {}, } if (char >= 'A' and char <= 'Z') return 0x1D538 + @as(u21, char - 'A'); if (char >= 'a' and char <= 'z') return 0x1D552 + @as(u21, char - 'a'); if (char >= '0' and char <= '9') return 0x1D7D8 + @as(u21, char - '0'); return null;}fn styledCal(char: u8) ?u21 { switch (char) { 'B' => return 0x212C, 'E' => return 0x2130, 'F' => return 0x2131, 'H' => return 0x210B, 'I' => return 0x2110, 'L' => return 0x2112, 'M' => return 0x2133, 'R' => return 0x211B, 'e' => return 0x212F, 'g' => return 0x210A, 'o' => return 0x2134, else => {}, } if (char >= 'A' and char <= 'Z') return 0x1D49C + @as(u21, char - 'A'); if (char >= 'a' and char <= 'z') return 0x1D4B6 + @as(u21, char - 'a'); return null;}fn styledFrak(char: u8) ?u21 { switch (char) { 'C' => return 0x212D, 'H' => return 0x210C, 'I' => return 0x2111, 'R' => return 0x211C, 'Z' => return 0x2128, else => {}, } if (char >= 'A' and char <= 'Z') return 0x1D504 + @as(u21, char - 'A'); if (char >= 'a' and char <= 'z') return 0x1D51E + @as(u21, char - 'a'); return null;}fn styledBf(char: u8) ?u21 { if (char >= 'A' and char <= 'Z') return 0x1D400 + @as(u21, char - 'A'); if (char >= 'a' and char <= 'z') return 0x1D41A + @as(u21, char - 'a'); if (char >= '0' and char <= '9') return 0x1D7CE + @as(u21, char - '0'); return null;}test "symbol table resolves commands and classes" { try std.testing.expectEqualStrings("∑", commands.get("sum").?.text); try std.testing.expect(commands.get("sum").?.kind == .largeop); try std.testing.expect(commands.get("int").?.kind == .integral); try std.testing.expect(commands.get("lim").?.kind == .movableop); try std.testing.expect(commands.get("nonesuch") == null);}test "environment table resolves fences and classes" { try std.testing.expectEqualStrings("(", environments.get("pmatrix").?.open.?); try std.testing.expectEqualStrings("‖", environments.get("Vmatrix").?.close.?); try std.testing.expect(environments.get("matrix").?.open == null); const cases = environments.get("cases").?; try std.testing.expectEqualStrings("{", cases.open.?); try std.testing.expect(cases.close == null); try std.testing.expectEqualStrings("zen-cases", cases.class.?); const aligned = environments.get("aligned").?; try std.testing.expect(aligned.display_cells); try std.testing.expect(environments.get("align") == null);}test "styled alphabets honor unicode exception slots" { try std.testing.expectEqual(@as(?u21, 0x211D), styled(.bb, 'R')); try std.testing.expectEqual(@as(?u21, 0x1D538), styled(.bb, 'A')); try std.testing.expectEqual(@as(?u21, 0x2112), styled(.cal, 'L')); try std.testing.expectEqual(@as(?u21, 0x212F), styled(.cal, 'e')); try std.testing.expectEqual(@as(?u21, 0x211C), styled(.frak, 'R')); try std.testing.expectEqual(@as(?u21, 0x1D41A), styled(.bf, 'a')); try std.testing.expectEqual(@as(?u21, null), styled(.cal, '3'));}Audit
| Definitions | 8 |
|---|---|
| Public names | 8 |
| Members | 20 |
| Version | 26.7.0 |
| Revision | daab053ee433 |