diff --git a/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-show.typ b/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-show.typ index 9ab462a0ccd..c82e7ba9810 100644 --- a/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-show.typ +++ b/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-show.typ @@ -1,3 +1,4 @@ + // Typst custom formats typically consist of a 'typst-template.typ' (which is // the source code for a typst template) and a 'typst-show.typ' which calls the // template's function (forwarding Pandoc metadata values as required) @@ -11,11 +12,13 @@ // documentation on creating typst templates here and some examples here: // - https://typst.app/docs/tutorial/making-a-template/ // - https://github.com/typst/templates - #show: doc => article( $if(title)$ title: [$title$], $endif$ +$if(subtitle)$ + subtitle: [$subtitle$], +$endif$ $if(by-author)$ authors: ( $for(by-author)$ @@ -48,9 +51,33 @@ $if(papersize)$ $endif$ $if(mainfont)$ font: ("$mainfont$",), +$elseif(brand.typography.base.family)$ + font: ("$brand.typography.base.family$",), $endif$ $if(fontsize)$ fontsize: $fontsize$, +$elseif(brand.typography.base.size)$ + fontsize: $brand.typography.base.size$, +$endif$ +$if(title)$ +$if(brand.typography.headings.family)$ + heading-family: ("$brand.typography.headings.family$",), +$endif$ +$if(brand.typography.headings.weight)$ + heading-weight: $brand.typography.headings.weight$, +$endif$ +$if(brand.typography.headings.style)$ + heading-style: "$brand.typography.headings.style$", +$endif$ +$if(brand.typography.headings.decoration)$ + heading-decoration: "$brand.typography.headings.decoration$", +$endif$ +$if(brand.typography.headings.color)$ + heading-color: $brand.typography.headings.color$, +$endif$ +$if(brand.typography.headings.line-height)$ + heading-line-height: $brand.typography.headings.line-height$, +$endif$ $endif$ $if(section-numbering)$ sectionnumbering: "$section-numbering$", diff --git a/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-template.typ b/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-template.typ index d08be1763be..10e20a6a7fc 100644 --- a/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-template.typ +++ b/src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-template.typ @@ -13,6 +13,7 @@ #let article( title: none, + subtitle: none, authors: none, date: none, abstract: none, @@ -22,8 +23,15 @@ paper: "us-letter", lang: "en", region: "US", - font: (), + font: "linux libertine", fontsize: 11pt, + title-size: 1.5em, + subtitle-size: 1.25em, + heading-family: "linux libertine", + heading-weight: "bold", + heading-style: "normal", + heading-color: black, + heading-line-height: 0.65em, sectionnumbering: none, toc: false, toc_title: none, @@ -42,10 +50,25 @@ font: font, size: fontsize) set heading(numbering: sectionnumbering) - if title != none { align(center)[#block(inset: 2em)[ - #text(weight: "bold", size: 1.5em)[#title] + #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] + } + } ]] } diff --git a/tools/copy-typst-partials.ts b/tools/copy-typst-partials.ts new file mode 100644 index 00000000000..468a9041d9d --- /dev/null +++ b/tools/copy-typst-partials.ts @@ -0,0 +1,47 @@ +import * as path from 'stdlib/path'; + +const srcTemplate = path.parse('../src/resources/formats/typst/pandoc/quarto/typst-template.typ'); +const destTemplate = path.parse('../src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-template.typ'); +const srcShow = path.parse('../src/resources/formats/typst/pandoc/quarto/typst-show.typ'); +const destShow = path.parse('../src/resources/create/extensions/format-typst/_extensions/qstart-filesafename-qend/typst-show.typ'); + +const templatePreamble = ` +// This is an example typst template (based on the default template that ships +// with Quarto). It defines a typst function named 'article' which provides +// various customization options. This function is called from the +// 'typst-show.typ' file (which maps Pandoc metadata function arguments) +// +// If you are creating or packaging a custom typst template you will likely +// want to replace this file and 'typst-show.typ' entirely. You can find +// documentation on creating typst templates and some examples here: +// - https://typst.app/docs/tutorial/making-a-template/ +// - https://github.com/typst/templates +`; + +const showPreamble = ` +// Typst custom formats typically consist of a 'typst-template.typ' (which is +// the source code for a typst template) and a 'typst-show.typ' which calls the +// template's function (forwarding Pandoc metadata values as required) +// +// This is an example 'typst-show.typ' file (based on the default template +// that ships with Quarto). It calls the typst function named 'article' which +// is defined in the 'typst-template.typ' file. +// +// If you are creating or packaging a custom typst template you will likely +// want to replace this file and 'typst-template.typ' entirely. You can find +// documentation on creating typst templates here and some examples here: +// - https://typst.app/docs/tutorial/making-a-template/ +// - https://github.com/typst/templates +`; + +const encoder = new TextEncoder(), decoder = new TextDecoder(); +const scriptDir = import.meta.dirname; + +async function splicePartial(preamble : string, source : string, dest : string) { + const template = await Deno.readFile(path.join(scriptDir, path.format(source))); + const templateOut = preamble + decoder.decode(template); + await Deno.writeFile(path.join(scriptDir, path.format(dest)), encoder.encode(templateOut)); +} + +await splicePartial(templatePreamble, srcTemplate, destTemplate); +await splicePartial(showPreamble, srcShow, destShow); \ No newline at end of file