Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)$
Expand Down Expand Up @@ -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$",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#let article(
title: none,
subtitle: none,
authors: none,
date: none,
abstract: none,
Expand All @@ -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,
Expand All @@ -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]
}
}
]]
}

Expand Down
47 changes: 47 additions & 0 deletions tools/copy-typst-partials.ts
Original file line number Diff line number Diff line change
@@ -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);
Loading