Skip to content

typst: customize light and dark logo at document level #13133

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

Merged
merged 4 commits into from
Jul 31, 2025
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
1 change: 1 addition & 0 deletions news/changelog-1.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ All changes included in 1.8:
- ([#12739](https://github.com/quarto-dev/quarto-cli/pull/12739)): Remove unused variable `heading-background-color` and `heading-decoration` from Typst's templates. They are leftover from previous change, and not part of Brand.yml schema for typography of headings.
- ([#12815](https://github.com/quarto-dev/quarto-cli/issues/12815)): Do not crash when floats have no content.
- ([#13119](https://github.com/quarto-dev/quarto-cli/pull/13119)): Expose `brand.logo` metadata as Typst dictionaries.
- ([#13133](https://github.com/quarto-dev/quarto-cli/pull/13133)): Allow customization of light and dark logos at document level, consistent with other formats.

### `beamer`

Expand Down
62 changes: 62 additions & 0 deletions src/core/brand/brand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import { join, relative } from "../../deno_ral/path.ts";
import { warnOnce } from "../log.ts";
import { isCssColorName } from "../css/color-names.ts";
import { assert } from "testing/asserts";
import {
LogoLightDarkSpecifierPathOptional,
LogoOptionsPathOptional,
LogoSpecifier,
LogoSpecifierPathOptional,
} from "../../resources/types/schema-types.ts";

type ProcessedBrandData = {
color: Record<string, string>;
Expand Down Expand Up @@ -379,6 +385,62 @@ export function resolveLogo(
};
}

// this a typst workaround but might as well write it as a proper function
export function fillLogoPaths(
brand: LightDarkBrand | undefined,
spec: LogoLightDarkSpecifierPathOptional | undefined,
order: BrandNamedLogo[],
): LogoLightDarkSpecifier | undefined {
function findLogoSize(
mode: "light" | "dark",
): string | undefined {
if (brand?.[mode]) {
for (const size of order) {
if (brand[mode].processedData.logo[size]) {
return size;
}
}
}
return undefined;
}
function resolveMode(
mode: "light" | "dark",
spec: LogoSpecifierPathOptional | undefined,
): LogoSpecifier | undefined {
if (!spec) {
return undefined;
}
if (!spec || typeof spec === "string") {
return spec;
} else if (spec.path) {
return spec as LogoOptions;
} else {
const size = findLogoSize(mode) ||
findLogoSize(mode === "light" ? "dark" : "light");
if (size) {
return {
path: size,
...spec,
};
}
}
return undefined;
}
if (!spec || typeof spec === "string") {
return spec;
}
if ("light" in spec || "dark" in spec) {
return {
light: resolveMode("light", spec.light),
dark: resolveMode("dark", spec.dark),
};
}
return {
light: resolveMode("light", spec as LogoOptionsPathOptional),
dark: resolveMode("dark", spec as LogoOptionsPathOptional),
};
}

function splitColorLightDark(
bcld: BrandColorLightDark,
): LightDarkColor {
Expand Down
20 changes: 20 additions & 0 deletions src/format/typst/format-typst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
kFigFormat,
kFigHeight,
kFigWidth,
kLogo,
kNumberSections,
kSectionNumbering,
kShiftHeadingLevelBy,
Expand All @@ -30,6 +31,12 @@ import {
import { formatResourcePath } from "../../core/resources.ts";
import { createFormat } from "../formats-shared.ts";
import { hasLevelOneHeadings as hasL1Headings } from "../../core/lib/markdown-analysis/level-one-headings.ts";
import {
BrandNamedLogo,
LogoLightDarkSpecifier,
} from "../../resources/types/schema-types.ts";
import { fillLogoPaths, resolveLogo } from "../../core/brand/brand.ts";
import { LogoLightDarkSpecifierPathOptional } from "../../resources/types/zod/schema-types.ts";

export function typstFormat(): Format {
return createFormat("Typst", "pdf", {
Expand Down Expand Up @@ -78,6 +85,19 @@ export function typstFormat(): Format {
pandoc[kShiftHeadingLevelBy] = -1;
}

const brand = format.render.brand;
const logoSpec = format
.metadata[kLogo] as LogoLightDarkSpecifierPathOptional;
const sizeOrder: BrandNamedLogo[] = [
"small",
"medium",
"large",
];
// temporary: if document logo has object or light/dark objects
// without path, do our own findLogo to add the path
// typst is the exception not needing path but we'll probably deprecate this
const logo = fillLogoPaths(brand, logoSpec, sizeOrder);
format.metadata[kLogo] = resolveLogo(brand, logo, sizeOrder);
// force columns to wrap and move any 'columns' setting to metadata
const columns = format.pandoc[kColumns];
if (columns) {
Expand Down
48 changes: 40 additions & 8 deletions src/resources/editor/tools/vs-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12090,6 +12090,34 @@ var require_yaml_intelligence_resources = __commonJS({
}
]
},
{
id: "logo-light-dark-specifier-path-optional",
description: "Any of the ways a logo can be specified: string, object, or light/dark object of string or object\n",
anyOf: [
{
ref: "logo-specifier-path-optional"
},
{
object: {
closed: true,
properties: {
light: {
schema: {
ref: "logo-specifier-path-optional"
},
description: "Specification of a light logo\n"
},
dark: {
schema: {
ref: "logo-specifier-path-optional"
},
description: "Specification of a dark logo\n"
}
}
}
}
]
},
{
id: "normalized-logo-light-dark-specifier",
description: "Any of the ways a logo can be specified: string, object, or light/dark object of string or object\n",
Expand Down Expand Up @@ -16116,10 +16144,11 @@ var require_yaml_intelligence_resources = __commonJS({
default: "light",
tags: {
formats: [
"typst"
"typst",
"revealjs"
]
},
description: "The brand mode to use for rendering the Typst document, `light` or `dark`.\n"
description: "The brand mode to use for rendering the document, `light` or `dark`.\n"
},
{
name: "layout",
Expand Down Expand Up @@ -18319,7 +18348,7 @@ var require_yaml_intelligence_resources = __commonJS({
]
},
schema: {
ref: "logo-specifier"
ref: "logo-light-dark-specifier"
},
description: "Logo image (placed in bottom right corner of slides)"
},
Expand Down Expand Up @@ -24640,7 +24669,10 @@ var require_yaml_intelligence_resources = __commonJS({
"Disambiguating year suffix in author-date styles (e.g.&nbsp;\u201Ca\u201D in \u201CDoe,\n1999a\u201D).",
"Manuscript configuration",
"internal-schema-hack",
"List execution engines you want to give priority when determining\nwhich engine should render a notebook. If two engines have support for a\nnotebook, the one listed earlier will be chosen. Quarto\u2019s default order\nis \u2018knitr\u2019, \u2018jupyter\u2019, \u2018markdown\u2019, \u2018julia\u2019."
"List execution engines you want to give priority when determining\nwhich engine should render a notebook. If two engines have support for a\nnotebook, the one listed earlier will be chosen. Quarto\u2019s default order\nis \u2018knitr\u2019, \u2018jupyter\u2019, \u2018markdown\u2019, \u2018julia\u2019.",
"Any of the ways a logo can be specified: string, object, or\nlight/dark object of string or object",
"Specification of a light logo",
"Specification of a dark logo"
],
"schema/external-schemas.yml": [
{
Expand Down Expand Up @@ -24869,12 +24901,12 @@ var require_yaml_intelligence_resources = __commonJS({
mermaid: "%%"
},
"handlers/mermaid/schema.yml": {
_internalId: 197461,
_internalId: 197480,
type: "object",
description: "be an object",
properties: {
"mermaid-format": {
_internalId: 197453,
_internalId: 197472,
type: "enum",
enum: [
"png",
Expand All @@ -24890,7 +24922,7 @@ var require_yaml_intelligence_resources = __commonJS({
exhaustiveCompletions: true
},
theme: {
_internalId: 197460,
_internalId: 197479,
type: "anyOf",
anyOf: [
{
Expand Down Expand Up @@ -24960,7 +24992,7 @@ var require_yaml_intelligence_resources = __commonJS({
{
name: "logo",
schema: {
ref: "logo-specifier-path-optional"
ref: "logo-light-dark-specifier-path-optional"
},
tags: {
formats: [
Expand Down

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions src/resources/editor/tools/yaml/web-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading