aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Kenny <[email protected]>2024-07-08 22:08:30 -0400
committerJohn MacFarlane <[email protected]>2025-07-24 10:45:28 -0700
commitf000fa168bd122fee6e67f5a67bdd6d42d173261 (patch)
tree49b8be848793a66f94c207d911091e8026eaee8a
parentebf41dd5392283398f35dac1414c04dbc3e3e7ca (diff)
Add features to typst base template.
This implements the changes suggested in #9956, with the exception of the filecolor/urlcolor one. These would require adding some regex to guess the link types. This is theoretically possible to do, but it wasn't clear to me that this is a good thing to put in a default template. Happy to adjust if you have thoughts on this. Closes #9956. Some things to note: I'm converting colors by passing them as content, as I was seeing pandoc escape # if that was included. I set the default fonts for math and code ("raw") to fonts that are bundled with Typst. These need not be those fonts if there are more familiar pandoc preferences.
-rw-r--r--MANUAL.txt15
-rw-r--r--data/templates/default.typst24
-rw-r--r--data/templates/template.typst100
-rw-r--r--test/writer.typst101
4 files changed, 165 insertions, 75 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index 39355c424..7ee20e59a 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -2728,7 +2728,7 @@ Currently the following pipes are predefined:
documents
`abstract-title`
-: title of abstract, currently used only in HTML, EPUB, and docx.
+: title of abstract, currently used only in HTML, EPUB, docx, and Typst.
This will be set automatically to a localized value,
depending on `lang`, but can be manually overridden.
@@ -3391,6 +3391,19 @@ The `--css` option also affects the output.
`columns`
: Number of columns for body text.
+`thanks`
+: contents of acknowledgments footnote after document title
+
+`mathfont`, `codefont`
+: Name of system font to use for math and code, respectively.
+
+`linestretch`
+: adjusts line spacing, e.g. `1.25`, `1.5`
+
+`linkcolor`, `filecolor`, `citecolor`
+: color for external links, internal links, and citation links,
+ respectively: expects a hexadecimal color code
+
### Variables for ms
`fontfamily`
diff --git a/data/templates/default.typst b/data/templates/default.typst
index 79b2c33f5..00e1ec557 100644
--- a/data/templates/default.typst
+++ b/data/templates/default.typst
@@ -71,9 +71,15 @@ $endif$
$if(region)$
region: "$region$",
$endif$
+$if(abstract-title)$
+ abstract-title: [$abstract-title$],
+$endif$
$if(abstract)$
abstract: [$abstract$],
$endif$
+$if(thanks)$
+ thanks: [$thanks$],
+$endif$
$if(margin)$
margin: ($for(margin/pairs)$$margin.key$: $margin.value$,$endfor$),
$endif$
@@ -86,10 +92,28 @@ $endif$
$if(fontsize)$
fontsize: $fontsize$,
$endif$
+$if(mathfont)$
+ mathfont: ($for(mathfont)$"$mathfont$",$endfor$),
+$endif$
+$if(codefont)$
+ codefont: ($for(codefont)$"$codefont$",$endfor$),
+$endif$
+$if(linestretch)$
+ linestretch: $linestretch$,
+$endif$
$if(section-numbering)$
sectionnumbering: "$section-numbering$",
$endif$
pagenumbering: $if(page-numbering)$"$page-numbering$"$else$none$endif$,
+$if(linkcolor)$
+ linkcolor: [$linkcolor$],
+$endif$
+$if(citecolor)$
+ citecolor: [$citecolor$],
+$endif$
+$if(filecolor)$
+ filecolor: [$filecolor$],
+$endif$
cols: $if(columns)$$columns$$else$1$endif$,
doc,
)
diff --git a/data/templates/template.typst b/data/templates/template.typst
index 24b1320fb..1afaa35fc 100644
--- a/data/templates/template.typst
+++ b/data/templates/template.typst
@@ -15,7 +15,9 @@
authors: (),
keywords: (),
date: none,
+ abstract-title: none,
abstract: none,
+ thanks: none,
cols: 1,
margin: (x: 1.25in, y: 1.25in),
paper: "us-letter",
@@ -23,66 +25,90 @@
region: "US",
font: (),
fontsize: 11pt,
+ mathfont: none,
+ codefont: none,
+ linestretch: 1,
sectionnumbering: none,
+ linkcolor: none,
+ citecolor: none,
+ filecolor: none,
pagenumbering: "1",
doc,
) = {
set document(
title: title,
- author: authors.map(author => content-to-string(author.name)),
+ author: authors.map(author => content-to-string(author.name)).join(", ", last: " & "),
keywords: keywords,
)
set page(
paper: paper,
margin: margin,
numbering: pagenumbering,
- columns: cols,
- )
- set par(justify: true)
+ )
+
+ set par(
+ justify: true,
+ leading: linestretch * 0.65em
+ )
set text(lang: lang,
region: region,
font: font,
size: fontsize)
+
+ show math.equation: set text(font: mathfont) if mathfont != none
+ show raw: set text(font: codefont) if codefont != none
+
set heading(numbering: sectionnumbering)
- place(top, float: true, scope: "parent", clearance: 4mm)[
- #if title != none {
- align(center)[#block(inset: 2em)[
- #text(weight: "bold", size: 1.5em)[#title]
- #(if subtitle != none {
- parbreak()
- text(weight: "bold", size: 1.25em)[#subtitle]
- })
- ]]
+ show link: set text(fill: rgb(content-to-string(linkcolor))) if linkcolor != none
+ show ref: set text(fill: rgb(content-to-string(citecolor))) if citecolor != none
+ show link: this => {
+ if filecolor != none and type(this.dest) == label {
+ text(this, fill: rgb(content-to-string(filecolor)))
+ }
}
- #if authors != none and authors != [] {
- 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
- ]
+ block(below: 4mm)[
+ #if title != none {
+ align(center)[#block(inset: 2em)[
+ #text(weight: "bold", size: 1.5em)[#title #if thanks != none {
+ footnote(thanks, numbering: "*")
+ counter(footnote).update(n => n - 1)
+ }]
+ #(
+ if subtitle != none {
+ parbreak()
+ text(weight: "bold", size: 1.25em)[#subtitle]
+ }
+ )
+ ]]
+ }
+
+ #if authors != none and authors != [] {
+ 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 date != none {
+ align(center)[#block(inset: 1em)[
+ #date
+ ]]
+ }
- #if abstract != none {
- block(inset: 2em)[
- #text(weight: "semibold")[$if(abstract-title)$${abstract-title}$else$Abstract$endif$] #h(1em) #abstract
- ]
- }
+ #if abstract != none {
+ block(inset: 2em)[
+ #text(weight: "semibold")[#abstract-title] #h(1em) #abstract
+ ]
+ }
]
doc
diff --git a/test/writer.typst b/test/writer.typst
index 5ff3051d4..5521680c7 100644
--- a/test/writer.typst
+++ b/test/writer.typst
@@ -39,7 +39,9 @@
authors: (),
keywords: (),
date: none,
+ abstract-title: none,
abstract: none,
+ thanks: none,
cols: 1,
margin: (x: 1.25in, y: 1.25in),
paper: "us-letter",
@@ -47,66 +49,90 @@
region: "US",
font: (),
fontsize: 11pt,
+ mathfont: none,
+ codefont: none,
+ linestretch: 1,
sectionnumbering: none,
+ linkcolor: none,
+ citecolor: none,
+ filecolor: none,
pagenumbering: "1",
doc,
) = {
set document(
title: title,
- author: authors.map(author => content-to-string(author.name)),
+ author: authors.map(author => content-to-string(author.name)).join(", ", last: " & "),
keywords: keywords,
)
set page(
paper: paper,
margin: margin,
numbering: pagenumbering,
- columns: cols,
- )
- set par(justify: true)
+ )
+
+ set par(
+ justify: true,
+ leading: linestretch * 0.65em
+ )
set text(lang: lang,
region: region,
font: font,
size: fontsize)
+
+ show math.equation: set text(font: mathfont) if mathfont != none
+ show raw: set text(font: codefont) if codefont != none
+
set heading(numbering: sectionnumbering)
- place(top, float: true, scope: "parent", clearance: 4mm)[
- #if title != none {
- align(center)[#block(inset: 2em)[
- #text(weight: "bold", size: 1.5em)[#title]
- #(if subtitle != none {
- parbreak()
- text(weight: "bold", size: 1.25em)[#subtitle]
- })
- ]]
+ show link: set text(fill: rgb(content-to-string(linkcolor))) if linkcolor != none
+ show ref: set text(fill: rgb(content-to-string(citecolor))) if citecolor != none
+ show link: this => {
+ if filecolor != none and type(this.dest) == label {
+ text(this, fill: rgb(content-to-string(filecolor)))
+ }
}
- #if authors != none and authors != [] {
- 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
- ]
+ block(below: 4mm)[
+ #if title != none {
+ align(center)[#block(inset: 2em)[
+ #text(weight: "bold", size: 1.5em)[#title #if thanks != none {
+ footnote(thanks, numbering: "*")
+ counter(footnote).update(n => n - 1)
+ }]
+ #(
+ if subtitle != none {
+ parbreak()
+ text(weight: "bold", size: 1.25em)[#subtitle]
+ }
+ )
+ ]]
+ }
+
+ #if authors != none and authors != [] {
+ 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 date != none {
+ align(center)[#block(inset: 1em)[
+ #date
+ ]]
+ }
- #if abstract != none {
- block(inset: 2em)[
- #text(weight: "semibold")[Abstract] #h(1em) #abstract
- ]
- }
+ #if abstract != none {
+ block(inset: 2em)[
+ #text(weight: "semibold")[#abstract-title] #h(1em) #abstract
+ ]
+ }
]
doc
@@ -122,6 +148,7 @@
email: "" ),
),
date: [July 17, 2006],
+ abstract-title: [Abstract],
pagenumbering: "1",
cols: 1,
doc,