aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-03-26 13:37:08 -0700
committerJohn MacFarlane <[email protected]>2023-03-26 19:02:05 -0700
commitcd6b3bde622c93eea763e981692b4bc53dd5e5df (patch)
tree78659dda4e5c40ef4ab62e8ad3949165da442c9d /data
parent657ebffd8f4efe334e27e7398700c5b92e453363 (diff)
Typst writer improvements.
+ Fix non-decimal enumerated lists. + Fix endnotes ending with code blocks. + Improve default template to use a typst template. + Factor out definitions and typst template into partials. + Properly escape backslash and quote inside double quotes. + Update tests.
Diffstat (limited to 'data')
-rw-r--r--data/templates/default.typst90
-rw-r--r--data/templates/definitions.typst18
-rw-r--r--data/templates/template.typst73
3 files changed, 135 insertions, 46 deletions
diff --git a/data/templates/default.typst b/data/templates/default.typst
index c6066dd24..11e7b1211 100644
--- a/data/templates/default.typst
+++ b/data/templates/default.typst
@@ -1,59 +1,55 @@
-#set page(
+$definitions.typst()$
+
+$if(template)$
+#import "$template$": conf
+$else$
+$template.typst()$
+$endif$
+
+#show: doc => conf(
+$if(title)$
+ title: [$title$],
+$endif$
+$if(author)$
+ authors: (
+$for(author)$
+$if(author.name)$
+ ( name: [$author.name$],
+ affiliation: [$author.affiliation$],
+ email: [$author.email$] ),
+$else$
+ ( name: [$author$],
+ affiliation: [],
+ email: [] ),
+$endif$
+$endfor$
+ ),
+$endif$
+$if(date)$
+ date: [$date$],
+$endif$
+$if(abstract)$
+ abstract: [$abstract$],
+$endif$
+$if(margin)$
+ margin: ($for(margin/pairs)$$margin.key$: $margin.value$,$endfor$),
+$endif$
$if(papersize)$
paper: "$papersize$",
$endif$
- numbering: "1"
-)
-#set par(justify: true)
-#set text(
-$if(lang)$
- lang: "$lang$",
-$endif$
$if(mainfont)$
- font: "$mainfont$",
+ font: ("$mainfont$",),
$endif$
$if(fontsize)$
- size: $fontsize$,
+ fontsize: $fontsize$,
$endif$
-)
-#set heading(
-$if(numbering)$
- numbering: "$numbering$"
+$if(section-numbering)$
+ sectionnumbering: "$section-numbering$",
$endif$
+ cols: $if(columns)$$columns$$else$1$endif$,
+ doc,
)
-#align(center)[#block(inset: 2em)[
- #text(weight: "bold", size: 18pt)[$title$] \
-$for(author)$
- $author$ \
-$endfor$
-$if(date)$
- $date$
-$endif$
-]]
-
-#let definition(term, ..defs) = [
- #strong(term) \
- #(defs.pos().join("\n"))
-]
-
-#let blockquote(body) = [
- #set text( size: 0.92em )
- #block(inset: (left: 1.5em, top: 0.2em, bottom: 0.2em))[#body]
-]
-
-#let horizontalrule = [
- #line(start: (25%,0%), end: (75%,0%))
-]
-
-#let endnote(num, contents) = [
- #stack(dir: ltr, spacing: 3pt, super[#num], contents)
-]
-
-$if(columns)$
-#show: doc => columns($columns$, doc)
-$endif$
-
$for(header-includes)$
$header-includes$
@@ -71,6 +67,7 @@ $endif$
$body$
+$if(notes)$
#v(1em)
#block[
#horizontalrule
@@ -79,6 +76,7 @@ $body$
$notes$
]
+$endif$
$if(bibliographystyle)$
#set bibliography(style: "$bibliographystyle$")
diff --git a/data/templates/definitions.typst b/data/templates/definitions.typst
new file mode 100644
index 000000000..02fe80f38
--- /dev/null
+++ b/data/templates/definitions.typst
@@ -0,0 +1,18 @@
+// Some definitions presupposed by pandoc's typst output.
+#let definition(term, ..defs) = [
+ #strong(term) \
+ #(defs.pos().join("\n"))
+]
+
+#let blockquote(body) = [
+ #set text( size: 0.92em )
+ #block(inset: (left: 1.5em, top: 0.2em, bottom: 0.2em))[#body]
+]
+
+#let horizontalrule = [
+ #line(start: (25%,0%), end: (75%,0%))
+]
+
+#let endnote(num, contents) = [
+ #stack(dir: ltr, spacing: 3pt, super[#num], contents)
+]
diff --git a/data/templates/template.typst b/data/templates/template.typst
new file mode 100644
index 000000000..29edca969
--- /dev/null
+++ b/data/templates/template.typst
@@ -0,0 +1,73 @@
+#let conf(
+ title: none,
+ authors: none,
+ date: none,
+ abstract: none,
+ cols: 1,
+ margin: (x: 1.25in, y: 1.25in),
+ paper: "us-letter",
+ lang: none,
+ font: none,
+ fontsize: 11pt,
+ sectionnumbering: none,
+ doc,
+) = {
+ set page(
+ paper: paper,
+ margin: margin,
+ numbering: "1",
+ )
+ set par(justify: true)
+ if lang != none {
+ set text(lang: lang)
+ }
+ if font != none {
+ set text(font: font)
+ }
+ if fontsize != none {
+ set text(size: fontsize)
+ }
+ if sectionnumbering != none {
+ set heading(numbering: sectionnumbering)
+ }
+
+ if title != none {
+ align(center)[#block(inset: 2em)[
+ #text(weight: "bold", size: 1.5em)[#title]
+ ]]
+ }
+
+ if authors != none {
+ let count = authors.len()
+ let ncols = calc.min(count, 3)
+ grid(
+ columns: (1fr,) * ncols,
+ row-gutter: 1.5em,
+ ..authors.map(author =>
+ align(center)[
+ #author.name \
+ #author.affiliation \
+ #author.email
+ ]
+ )
+ )
+ }
+
+ if date != none {
+ align(center)[#block(inset: 1em)[
+ #date
+ ]]
+ }
+
+ if abstract != none {
+ block(inset: 2em)[
+ #text(weight: "semibold")[Abstract] #h(1em) #abstract
+ ]
+ }
+
+ if cols == 1 {
+ doc
+ } else {
+ columns(cols, doc)
+ }
+}