11-- theorems.lua
22-- Shared Typst theorem/proof setup logic using theorion
3- -- Copyright (C) 2020-2022 Posit Software, PBC
3+ -- Copyright (C) 2026 Posit Software, PBC
44
55local typst_theorem_appearance_imported = false
66local typst_theorem_like_frames = {}
@@ -75,6 +75,32 @@ local function ensure_simple_render(render_name, italic_body)
7575]] )
7676end
7777
78+ -- Writes text as a Typst string literal, so that titles from the language
79+ -- files reach the page as written instead of being read as Typst markup.
80+ local function typst_string (text )
81+ return ' "' .. text :gsub (" \\ " , " \\\\ " ):gsub (' "' , ' \\ "' ) .. ' "'
82+ end
83+
84+ -- Returns the `render:` argument of make-frame for the theorem appearance.
85+ -- opts.color_scheme: fancy color set (primary, secondary or tertiary)
86+ -- opts.color: clouds and rainbow fill color
87+ -- opts.simple_render, opts.italic_body: name and body style of the simple renderer
88+ local function render_code (appearance , opts )
89+ if appearance == " fancy" then
90+ return " render: fancy-box.with(\n " ..
91+ " get-border-color: get-" .. opts .color_scheme .. " -border-color,\n " ..
92+ " get-body-color: get-" .. opts .color_scheme .. " -body-color,\n " ..
93+ " get-symbol: loc => none,\n " ..
94+ " ),\n "
95+ elseif appearance == " clouds" then
96+ return " render: clouds-render.with(fill: " .. opts .color .. " .lighten(85%)),\n "
97+ elseif appearance == " rainbow" then
98+ return " render: rainbow-render.with(fill: " .. opts .color .. " .darken(20%)),\n "
99+ end
100+ ensure_simple_render (opts .simple_render , opts .italic_body )
101+ return " render: " .. opts .simple_render .. " ,\n "
102+ end
103+
78104local function ensure_frame (env_name , title , render_code )
79105 if typst_theorem_like_frames [env_name ] then
80106 return false
@@ -84,7 +110,7 @@ local function ensure_frame(env_name, title, render_code)
84110 quarto .doc .include_text (" in-header" , " #let (" .. env_name .. " -counter, " .. env_name .. " -box, " ..
85111 env_name .. " , show-" .. env_name .. " ) = make-frame(\n " ..
86112 " \" " .. env_name .. " \" ,\n " ..
87- " text(weight: \" bold\" )[ " .. title .. " ] ,\n " ..
113+ " text(weight: \" bold\" , " .. typst_string ( title ) .. " ) ,\n " ..
88114 " inherited-levels: theorem-inherited-levels,\n " ..
89115 " numbering: theorem-numbering,\n " ..
90116 render_code ..
@@ -98,4 +124,6 @@ return {
98124 ensure_appearance_imports = ensure_appearance_imports ,
99125 ensure_simple_render = ensure_simple_render ,
100126 ensure_frame = ensure_frame ,
127+ render_code = render_code ,
128+ typst_string = typst_string ,
101129}
0 commit comments