Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new features to the Typst template #9970

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions data/templates/default.typst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ $endif$
$if(abstract)$
abstract: [$abstract$],
$endif$
$if(thanks)$
thanks: [$thanks$],
$endif$
$if(margin)$
margin: ($for(margin/pairs)$$margin.key$: $margin.value$,$endfor$),
$endif$
Expand All @@ -69,8 +72,26 @@ $endif$
$if(fontsize)$
fontsize: $fontsize$,
$endif$
$if(mathfont)$
mathfont: ($for(mathfont)$"$mathfont$",$endfor$),
$endif$
$if(codefont)$
codefont: ($for(codefont)$"$codefont$",$endfor$),
$endif$
Comment on lines +75 to +80
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why you used $for$ here. mathfont would normally be expected to be a string in pandoc templates.

$if(linestretch)$
linestretch: $linestretch$,
$endif$
$if(section-numbering)$
sectionnumbering: "$section-numbering$",
$endif$
$if(linkcolor)$
linkcolor: [$linkcolor$],
$endif$
$if(citecolor)$
citecolor: [$citecolor$],
$endif$
Comment on lines +90 to +92
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works in content like this, with the escaped #?

citecolor: [\#ffffff]

You've tested I assume?

$if(toccolor)$
toccolor: [$toccolor$],
$endif$
cols: $if(columns)$$columns$$else$1$endif$,
doc,
Expand Down
32 changes: 29 additions & 3 deletions data/templates/template.typst
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,62 @@
keywords: (),
date: none,
abstract: none,
thanks: none,
cols: 1,
margin: (x: 1.25in, y: 1.25in),
paper: "us-letter",
lang: "en",
region: "US",
font: (),
fontsize: 11pt,
mathfont: "New Computer Modern Math",
codefont: "DejaVu Sans Mono",
Comment on lines +27 to +28
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these different from the fonts Typst uses by default? Would it not be better to allow these to be specified but stay with Typst's normal defaults by default?

linestretch: 1,
sectionnumbering: none,
linkcolor: ["#800000"],
citecolor: ["#0000FF"],
toccolor: ["#800000"],
Comment on lines +31 to +33
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, is this the same as Typst's default behavior? If not, why these colors? Would it perhaps be better to make Typst use its standard defaults unless these are specified?

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: ", and "),
Comment on lines -31 to +38
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this because and is an English word; anyone writing in another language would need to change the template. We could consider using &, or just use commas.

keywords: keywords,
)
set page(
paper: paper,
margin: margin,
numbering: "1",
)
set par(justify: true)
set par(
justify: true,
leading: linestretch * 0.65em
)
Comment on lines +48 to +49
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the leading do here, and why is it needed with linestretch? Is the result the same as Typst's defaults when the default linestretch is used?

set text(lang: lang,
region: region,
font: font,
size: fontsize)
show math.equation: set text(font: mathfont)
show raw: set text(font: codefont)
set heading(numbering: sectionnumbering)

show link: set text(fill: rgb(content-to-string(linkcolor)))

show link: this => {
if type(this.dest) == label {
text(this, fill: rgb(content-to-string(filecolor)))
}
}
show ref: this => {
text(this, fill: rgb(content-to-string(citecolor)))
}

if title != none {
align(center)[#block(inset: 2em)[
#text(weight: "bold", size: 1.5em)[#title]
#text(weight: "bold", size: 1.5em)[#title #if thanks != none {
footnote(thanks, numbering: "*")
counter(footnote).update(n => n - 1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is needed because otherwise the first note would be 2? That's a bit unexpected when numbering is explicitly specified, but maybe Typst works that way? (I'd consider it a bug if so.)

}]
#(if subtitle != none {
parbreak()
text(weight: "bold", size: 1.25em)[#subtitle]
Expand Down
32 changes: 29 additions & 3 deletions test/writer.typst
Original file line number Diff line number Diff line change
Expand Up @@ -38,36 +38,62 @@
keywords: (),
date: none,
abstract: none,
thanks: none,
cols: 1,
margin: (x: 1.25in, y: 1.25in),
paper: "us-letter",
lang: "en",
region: "US",
font: (),
fontsize: 11pt,
mathfont: "New Computer Modern Math",
codefont: "DejaVu Sans Mono",
linestretch: 1,
sectionnumbering: none,
linkcolor: ["#800000"],
citecolor: ["#0000FF"],
toccolor: ["#800000"],
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: ", and "),
keywords: keywords,
)
set page(
paper: paper,
margin: margin,
numbering: "1",
)
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)
show raw: set text(font: codefont)
set heading(numbering: sectionnumbering)

show link: set text(fill: rgb(content-to-string(linkcolor)))

show link: this => {
if type(this.dest) == label {
text(this, fill: rgb(content-to-string(filecolor)))
}
}
show ref: this => {
text(this, fill: rgb(content-to-string(citecolor)))
}

if title != none {
align(center)[#block(inset: 2em)[
#text(weight: "bold", size: 1.5em)[#title]
#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]
Expand Down