fix(typst): ship template as partials so code blocks render (#12)
R-CMD-check / R CMD check (pull_request) Successful in 3m54s
R-CMD-check / R CMD check (pull_request) Successful in 3m54s
The single-file `template: civilytics-typst.typ` discarded Quarto's auto-generated `definitions` partial, so any Typst document containing a code block failed with `unknown variable: Skylighting`. Ship the template as Quarto template-partials instead, so Quarto keeps its definitions (Skylighting + token functions) and syntax-highlighted code blocks render while the Civilytics branding still applies: - split civilytics-typst.typ into typst-template.typ (the styling function) and typst-show.typ (the show/entry point, keyword-safe [ ] wrapping kept); remove the single-file template - use_civilytics_theme() now copies both partials and prints the template-partials usage - example report.qmd uses template-partials Verified: a report with an R code block renders with working syntax highlighting and full branding.
This commit is contained in:
+9
-7
@@ -135,12 +135,12 @@ use_civilytics_theme <- function(path = ".", force = FALSE) {
|
|||||||
.copy_pkg_file(file.path("quarto/latex", f), file.path("latex", f), path, force)
|
.copy_pkg_file(file.path("quarto/latex", f), file.path("latex", f), path, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Typst
|
# Typst — shipped as template-partials so Quarto keeps its Skylighting
|
||||||
.copy_pkg_file(
|
# definitions and syntax-highlighted code blocks render (see issue #12)
|
||||||
"quarto/typst/civilytics-typst.typ",
|
typst_files <- c("typst-template.typ", "typst-show.typ")
|
||||||
"typst/civilytics-typst.typ",
|
for (f in typst_files) {
|
||||||
path, force
|
.copy_pkg_file(file.path("quarto/typst", f), file.path("typst", f), path, force)
|
||||||
)
|
}
|
||||||
|
|
||||||
# Logos — for _brand.yml (expects assets/logo/)
|
# Logos — for _brand.yml (expects assets/logo/)
|
||||||
.copy_logos("assets/logo", path, force)
|
.copy_logos("assets/logo", path, force)
|
||||||
@@ -158,7 +158,9 @@ use_civilytics_theme <- function(path = ".", force = FALSE) {
|
|||||||
message(" include-in-header: latex/civilytics.tex")
|
message(" include-in-header: latex/civilytics.tex")
|
||||||
message(" include-before-body: latex/civilytics-title.tex")
|
message(" include-before-body: latex/civilytics-title.tex")
|
||||||
message(" typst:")
|
message(" typst:")
|
||||||
message(" template: typst/civilytics-typst.typ")
|
message(" template-partials:")
|
||||||
|
message(" - typst/typst-template.typ")
|
||||||
|
message(" - typst/typst-show.typ")
|
||||||
message("---")
|
message("---")
|
||||||
message("\nSee examples/report.qmd for a complete example.")
|
message("\nSee examples/report.qmd for a complete example.")
|
||||||
invisible(NULL)
|
invisible(NULL)
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ format:
|
|||||||
toc: true
|
toc: true
|
||||||
toc-location: right
|
toc-location: right
|
||||||
typst:
|
typst:
|
||||||
template: ../typst/civilytics-typst.typ
|
template-partials:
|
||||||
|
- ../typst/typst-template.typ
|
||||||
|
- ../typst/typst-show.typ
|
||||||
pdf:
|
pdf:
|
||||||
include-in-header: ../latex/civilytics.tex
|
include-in-header: ../latex/civilytics.tex
|
||||||
include-before-body: ../latex/civilytics-title.tex
|
include-before-body: ../latex/civilytics-title.tex
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// Civilytics — Typst show/entry partial for Quarto (typst-show.typ).
|
||||||
|
// Pairs with typst-template.typ. Quarto appends the rendered document body
|
||||||
|
// after this partial, so this file intentionally ends with the show rule and
|
||||||
|
// no trailing body token. (Do not write that token in a comment here: Quarto
|
||||||
|
// interpolates its template variables even inside comments.)
|
||||||
|
// Title/subtitle/date are wrapped in [ ] so arbitrary text (including words
|
||||||
|
// that are Typst keywords like "for"/"in") is treated as content, not code.
|
||||||
|
// See civilyticsR issue #12.
|
||||||
|
#show: doc => civilytics(
|
||||||
|
title: [$title$],
|
||||||
|
$if(subtitle)$subtitle: [$subtitle$],$endif$
|
||||||
|
$if(by-author)$authors: ($for(by-author)$"$it.name.literal$",$endfor$),$endif$
|
||||||
|
$if(date)$date: [$date$],$endif$
|
||||||
|
$if(abstract)$abstract: [$abstract$],$endif$
|
||||||
|
toc: $if(toc)$true$else$false$endif$,
|
||||||
|
doc
|
||||||
|
)
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
// =============================================================
|
// =============================================================
|
||||||
// Civilytics — Typst template for Quarto PDF
|
// Civilytics — Typst template partial for Quarto PDF (typst-template.typ).
|
||||||
|
// Shipped as a Quarto template-partial (paired with typst-show.typ) rather
|
||||||
|
// than a full `template:` so Quarto keeps its own `definitions` partial —
|
||||||
|
// which defines Skylighting/token functions needed for syntax-highlighted
|
||||||
|
// code blocks. See civilyticsR issue #12.
|
||||||
// Usage in YAML:
|
// Usage in YAML:
|
||||||
// format:
|
// format:
|
||||||
// typst:
|
// typst:
|
||||||
// template: quarto/typst/civilytics-typst.typ
|
// template-partials:
|
||||||
|
// - quarto/typst/typst-template.typ
|
||||||
|
// - quarto/typst/typst-show.typ
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|
||||||
#let paper-bg = rgb("#FAF7F2")
|
#let paper-bg = rgb("#FAF7F2")
|
||||||
@@ -229,19 +235,3 @@
|
|||||||
|
|
||||||
doc
|
doc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quarto entry point
|
|
||||||
// Title/subtitle/date are wrapped in [ ] so arbitrary text (incl. words that
|
|
||||||
// are Typst keywords like "for"/"in") is treated as content, not code.
|
|
||||||
// See civilyticsR issue #12.
|
|
||||||
#show: doc => civilytics(
|
|
||||||
title: [$title$],
|
|
||||||
$if(subtitle)$subtitle: [$subtitle$],$endif$
|
|
||||||
$if(by-author)$authors: ($for(by-author)$"$it.name.literal$",$endfor$),$endif$
|
|
||||||
$if(date)$date: [$date$],$endif$
|
|
||||||
$if(abstract)$abstract: [$abstract$],$endif$
|
|
||||||
toc: $if(toc)$true$else$false$endif$,
|
|
||||||
doc
|
|
||||||
)
|
|
||||||
|
|
||||||
$body$
|
|
||||||
Reference in New Issue
Block a user