From 35a1646baf39aad40d75384323cda4e71008fb20 Mon Sep 17 00:00:00 2001 From: Charlotte Wickham Date: Wed, 18 Dec 2024 11:06:23 -0800 Subject: [PATCH] Extract typst title block into a partial --- src/format/typst/format-typst.ts | 1 + .../formats/typst/pandoc/quarto/template.typ | 2 + .../typst/pandoc/quarto/typst-template.typ | 62 ++++-------------- .../typst/pandoc/quarto/typst-title.typ | 65 +++++++++++++++++++ 4 files changed, 82 insertions(+), 48 deletions(-) create mode 100644 src/resources/formats/typst/pandoc/quarto/typst-title.typ diff --git a/src/format/typst/format-typst.ts b/src/format/typst/format-typst.ts index eb2f5f4484..0b9f69db07 100644 --- a/src/format/typst/format-typst.ts +++ b/src/format/typst/format-typst.ts @@ -92,6 +92,7 @@ export function typstFormat(): Format { "definitions.typ", "typst-template.typ", "typst-show.typ", + "typst-title.typ", "notes.typ", "biblio.typ", ].map((partial) => join(templateDir, partial)), diff --git a/src/resources/formats/typst/pandoc/quarto/template.typ b/src/resources/formats/typst/pandoc/quarto/template.typ index 3b23beaa08..6b1d13d50a 100644 --- a/src/resources/formats/typst/pandoc/quarto/template.typ +++ b/src/resources/formats/typst/pandoc/quarto/template.typ @@ -1,5 +1,7 @@ $definitions.typ()$ +$typst-title.typ()$ + $typst-template.typ()$ $for(header-includes)$ diff --git a/src/resources/formats/typst/pandoc/quarto/typst-template.typ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ index b9175e6f0b..2ba98ad398 100644 --- a/src/resources/formats/typst/pandoc/quarto/typst-template.typ +++ b/src/resources/formats/typst/pandoc/quarto/typst-template.typ @@ -39,55 +39,21 @@ font: font, size: fontsize) set heading(numbering: sectionnumbering) - if title != none { - align(center)[#block(inset: 2em)[ - #set par(leading: heading-line-height) - #if (heading-family != none or heading-weight != "bold" or heading-style != "normal" - or heading-color != black or heading-decoration == "underline" - or heading-background-color != none) { - set text(font: heading-family, weight: heading-weight, style: heading-style, fill: heading-color) - text(size: title-size)[#title] - if subtitle != none { - parbreak() - text(size: subtitle-size)[#subtitle] - } - } else { - text(weight: "bold", size: title-size)[#title] - if subtitle != none { - parbreak() - text(weight: "bold", size: subtitle-size)[#subtitle] - } - } - ]] - } - - 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-title] #h(1em) #abstract - ] - } + title_block( + title: title, + subtitle: subtitle, + authors: authors, + date: date, + abstract: abstract, + title-size: title-size, + subtitle-size: subtitle-size, + heading-family: heading-family, + heading-weight: heading-weight, + heading-style: heading-style, + heading-color: heading-color, + heading-line-height: heading-line-height + ) if toc { let title = if toc_title == none { diff --git a/src/resources/formats/typst/pandoc/quarto/typst-title.typ b/src/resources/formats/typst/pandoc/quarto/typst-title.typ new file mode 100644 index 0000000000..883274aa7b --- /dev/null +++ b/src/resources/formats/typst/pandoc/quarto/typst-title.typ @@ -0,0 +1,65 @@ +#let title_block( + title: none, + subtitle: none, + authors: none, + date: none, + abstract: none, + title-size: none, + subtitle-size: none, + heading-family: none, + heading-weight: none, + heading-style: none, + heading-color: none, + heading-line-height: none + ) = { + if title != none { + align(center)[#block(inset: 2em)[ + #set par(leading: heading-line-height) + #if (heading-family != none or heading-weight != "bold" or heading-style != "normal" + or heading-color != black or heading-decoration == "underline" + or heading-background-color != none) { + set text(font: heading-family, weight: heading-weight, style: heading-style, fill: heading-color) + text(size: title-size)[#title] + if subtitle != none { + parbreak() + text(size: subtitle-size)[#subtitle] + } + } else { + text(weight: "bold", size: title-size)[#title] + if subtitle != none { + parbreak() + text(weight: "bold", size: subtitle-size)[#subtitle] + } + } + ]] + } + + 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-title] #h(1em) #abstract + ] + } +} +