Skip to content

Commit a65151f

Browse files
typst theorems
tests and feature row in matrix
1 parent e31e31f commit a65151f

File tree

4 files changed

+153
-1
lines changed

4 files changed

+153
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
format:
3+
html:
4+
quality: 2
5+
pdf:
6+
quality: 2
7+
typst:
8+
quality: 2
9+
dashboard:
10+
quality: 1
11+
markdown:
12+
quality: 2
13+
docx:
14+
quality: 1
15+
pptx:
16+
quality: 1
17+
ipynb:
18+
quality: 0
19+
comment: "Renders as HTML prefixed with # on empty line"
20+
21+
---
22+
23+
::: {#thm-line}
24+
25+
## Line
26+
27+
The equation of any straight line, called a linear equation, can be written as:
28+
29+
$$
30+
y = mx + b
31+
$$
32+
:::
33+
34+
See @thm-line.

src/resources/filters/customnodes/theorem.lua

+31-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ _quarto.ast.add_handler({
8888
end
8989
})
9090

91+
local included_typst_theorems = false
92+
local letted_typst_theorem = {}
93+
local function ensure_typst_theorems(reftype)
94+
if not included_typst_theorems then
95+
included_typst_theorems = true
96+
quarto.doc.include_text("in-header", "#import \"@preview/ctheorems:1.1.0\": *")
97+
quarto.doc.include_text("in-header", "#show: thmrules")
98+
end
99+
if not letted_typst_theorem[reftype] then
100+
letted_typst_theorem[reftype] = true
101+
local theorem_type = theorem_types[reftype]
102+
quarto.doc.include_text("in-header", "#let " .. theorem_type.env .. " = thmbox(\"" .. theorem_type.env .. "\", \"" .. theorem_type.title .. "\", fill: rgb(\"#eeffee\"))")
103+
end
104+
end
105+
106+
91107
_quarto.ast.add_renderer("Theorem", function()
92108
return true
93109
end, function(thm)
@@ -136,7 +152,21 @@ end, function(thm)
136152
-- JATS XML theorem
137153
local lbl = captionPrefix({}, type, theorem_type, order)
138154
el = jatsTheorem(el, lbl, name)
139-
155+
156+
elseif _quarto.format.isTypstOutput() then
157+
ensure_typst_theorems(type)
158+
-- el.content:insert(1, pandoc.RawInline("typst", "#" .. theorem_type.env .. "(\"" .. thm.name .. "\")["))
159+
local callthm = pandoc.Para(pandoc.RawInline("typst", "#" .. theorem_type.env .. "(\""))
160+
if name then
161+
tappend(callthm.content, name)
162+
end
163+
quarto.log.output(el.content)
164+
callthm.content:insert(pandoc.RawInline("typst", "\")["))
165+
tappend(callthm.content, quarto.utils.as_inlines(el.content))
166+
callthm.content:insert(pandoc.RawInline("typst", "] <" .. el.attr.identifier .. ">"))
167+
quarto.log.output(callthm.content)
168+
return callthm
169+
140170
else
141171
-- create caption prefix
142172
local captionPrefix = captionPrefix(name, type, theorem_type, order)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
keep-typ: true
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- "a.quarto-xref"
9+
- []
10+
latex:
11+
ensureFileRegexMatches:
12+
-
13+
- "hypertarget{lem-line}"
14+
- "label{lem-line}"
15+
- "Lemma~\\\\ref\\{lem-line\\}"
16+
- []
17+
typst:
18+
ensureTypstFileRegexMatches:
19+
-
20+
- "<lem-line>"
21+
- "@lem-line"
22+
- "#lemma\\(\"Line\"\\)"
23+
- []
24+
markdown:
25+
ensureFileRegexMatches:
26+
-
27+
- "\\[Lemma 1\\]\\(#lem-line\\)\\{.quarto-xref\\}"
28+
- '\[\*\*Lemma 1 \(Line\)\*\*\]\{.theorem-title\}'
29+
30+
31+
---
32+
33+
::: {#lem-line}
34+
35+
## Line
36+
37+
The equation of any straight line, called a linear equation, can be written as:
38+
39+
$$
40+
y = mx + b
41+
$$
42+
:::
43+
44+
See @lem-line.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
keep-typ: true
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
-
8+
- "a.quarto-xref"
9+
- []
10+
latex:
11+
ensureFileRegexMatches:
12+
-
13+
- "hypertarget{thm-line}"
14+
- "label{thm-line}"
15+
- "Theorem~\\\\ref\\{thm-line\\}"
16+
- []
17+
typst:
18+
ensureTypstFileRegexMatches:
19+
-
20+
- "<thm-line>"
21+
- "@thm-line"
22+
- "#theorem\\(\"Line\"\\)"
23+
- []
24+
markdown:
25+
ensureFileRegexMatches:
26+
-
27+
- "\\[Theorem 1\\]\\(#thm-line\\)\\{.quarto-xref\\}"
28+
- '\[\*\*Theorem 1 \(Line\)\*\*\]\{.theorem-title\}'
29+
30+
31+
---
32+
33+
::: {#thm-line}
34+
35+
## Line
36+
37+
The equation of any straight line, called a linear equation, can be written as:
38+
39+
$$
40+
y = mx + b
41+
$$
42+
:::
43+
44+
See @thm-line.

0 commit comments

Comments
 (0)