@@ -93,115 +93,42 @@ _quarto.ast.add_handler({
9393 end
9494})
9595
96- -- Get theorem-appearance option (simple, fancy, clouds, rainbow)
97- local function get_theorem_appearance ()
98- local appearance = option (" theorem-appearance" , " simple" )
99- if appearance ~= nil and type (appearance ) == " table" then
100- appearance = pandoc .utils .stringify (appearance )
101- end
102- return appearance or " simple"
103- end
104-
10596-- Color mapping for clouds/rainbow themes (per theorem type)
10697local theme_colors = {
10798 thm = " red" , lem = " teal" , cor = " navy" , prp = " blue" ,
10899 cnj = " navy" , def = " olive" , exm = " green" , exr = " purple" , alg = " maroon"
109100}
110101
111- local included_typst_theorems = false
112- local letted_typst_theorem = {}
113102local function ensure_typst_theorems (reftype )
114- local appearance = get_theorem_appearance ()
115-
116- if not included_typst_theorems then
117- included_typst_theorems = true
118-
119- if appearance == " fancy" then
120- -- Import theorion's make-frame and fancy-box theming
121- quarto .doc .include_text (" in-header" , [[
122- #import "@preview/theorion:0.4.1": make-frame, cosmos
123- #import cosmos.fancy: fancy-box, set-primary-border-color, set-primary-body-color, set-secondary-border-color, set-secondary-body-color, set-tertiary-border-color, set-tertiary-body-color, get-primary-border-color, get-primary-body-color, get-secondary-border-color, get-secondary-body-color, get-tertiary-border-color, get-tertiary-body-color
124- ]] )
125- -- Set theorem colors from brand-color (runs in before-body, after brand-color is defined)
126- quarto .doc .include_text (" before-body" , [[
127- #set-primary-border-color(brand-color.at("primary", default: green.darken(30%)))
128- #set-primary-body-color(brand-color.at("primary", default: green).lighten(90%))
129- #set-secondary-border-color(brand-color.at("secondary", default: orange))
130- #set-secondary-body-color(brand-color.at("secondary", default: orange).lighten(90%))
131- #set-tertiary-border-color(brand-color.at("tertiary", default: blue.darken(30%)))
132- #set-tertiary-body-color(brand-color.at("tertiary", default: blue).lighten(90%))
133- ]] )
134- elseif appearance == " clouds" then
135- -- Import theorion's make-frame and clouds render function
136- quarto .doc .include_text (" in-header" , [[
137- #import "@preview/theorion:0.4.1": make-frame, cosmos
138- #import cosmos.clouds: render-fn as clouds-render
139- ]] )
140- elseif appearance == " rainbow" then
141- -- Import theorion's make-frame and rainbow render function
142- quarto .doc .include_text (" in-header" , [[
143- #import "@preview/theorion:0.4.1": make-frame, cosmos
144- #import cosmos.rainbow: render-fn as rainbow-render
145- ]] )
146- else -- simple (default)
147- -- Import only make-frame and define simple render function
148- quarto .doc .include_text (" in-header" , [[
149- #import "@preview/theorion:0.4.1": make-frame
150-
151- // Simple theorem render: bold title with period, italic body
152- #let simple-theorem-render(prefix: none, title: "", full-title: auto, body) = {
153- if full-title != "" and full-title != auto and full-title != none {
154- strong[#full-title.]
155- h(0.5em)
156- }
157- emph(body)
158- parbreak()
159- }
160- ]] )
103+ local appearance = ensureTheoremTypstAppearanceImports ()
104+ local theorem_type = theorem_types [reftype ]
105+ local title = titleString (reftype , theorem_type .title )
106+ local render_code
107+
108+ if appearance == " fancy" then
109+ local color_scheme = " secondary"
110+ if theorem_type .style == " definition" then
111+ color_scheme = " primary"
112+ elseif reftype == " prp" then
113+ color_scheme = " tertiary"
161114 end
115+ render_code = " render: fancy-box.with(\n " ..
116+ " get-border-color: get-" .. color_scheme .. " -border-color,\n " ..
117+ " get-body-color: get-" .. color_scheme .. " -body-color,\n " ..
118+ " get-symbol: loc => none,\n " ..
119+ " ),\n "
120+ elseif appearance == " clouds" then
121+ local color = theme_colors [reftype ] or " gray"
122+ render_code = " render: clouds-render.with(fill: " .. color .. " .lighten(85%)),\n "
123+ elseif appearance == " rainbow" then
124+ local color = theme_colors [reftype ] or " gray"
125+ render_code = " render: rainbow-render.with(fill: " .. color .. " .darken(20%)),\n "
126+ else
127+ ensureTheoremTypstSimpleRender (" simple-theorem-render" , true )
128+ render_code = " render: simple-theorem-render,\n "
162129 end
163130
164- if not letted_typst_theorem [reftype ] then
165- letted_typst_theorem [reftype ] = true
166- local theorem_type = theorem_types [reftype ]
167- local title = titleString (reftype , theorem_type .title )
168-
169- -- Build render code based on appearance
170- local render_code
171- if appearance == " fancy" then
172- -- Map theorem styles to color schemes (primary=definitions, secondary=theorems, tertiary=propositions)
173- local color_scheme = " secondary" -- default for most theorem types
174- if theorem_type .style == " definition" then
175- color_scheme = " primary"
176- elseif reftype == " prp" then
177- color_scheme = " tertiary"
178- end
179- render_code = " render: fancy-box.with(\n " ..
180- " get-border-color: get-" .. color_scheme .. " -border-color,\n " ..
181- " get-body-color: get-" .. color_scheme .. " -body-color,\n " ..
182- " get-symbol: loc => none,\n " ..
183- " ),\n "
184- elseif appearance == " clouds" then
185- local color = theme_colors [reftype ] or " gray"
186- render_code = " render: clouds-render.with(fill: " .. color .. " .lighten(85%)),\n "
187- elseif appearance == " rainbow" then
188- local color = theme_colors [reftype ] or " gray"
189- render_code = " render: rainbow-render.with(fill: " .. color .. " .darken(20%)),\n "
190- else -- simple
191- render_code = " render: simple-theorem-render,\n "
192- end
193-
194- -- Use theorion's make-frame with appropriate render
195- quarto .doc .include_text (" in-header" , " #let (" .. theorem_type .env .. " -counter, " .. theorem_type .env .. " -box, " ..
196- theorem_type .env .. " , show-" .. theorem_type .env .. " ) = make-frame(\n " ..
197- " \" " .. theorem_type .env .. " \" ,\n " ..
198- " text(weight: \" bold\" )[" .. title .. " ],\n " ..
199- " inherited-levels: theorem-inherited-levels,\n " ..
200- " numbering: theorem-numbering,\n " ..
201- render_code ..
202- " )" )
203- quarto .doc .include_text (" in-header" , " #show: show-" .. theorem_type .env )
204- end
131+ ensureTheoremTypstFrame (theorem_type .env , title , render_code )
205132end
206133
207134
0 commit comments