> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nemu.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Themes

> Centralize named colors and apply defaults by element type and classname

A theme centralizes named colors and applies default styles by element type and by
classname. Build one with `create_theme`, then attach it per page or document wide.

## Creating a theme

```ts theme={null}
create_theme(name: string, definition?): Theme
```

The optional `definition` holds a `colors` map of named colors, along with other optional
fields.

```ts theme={null}
import { Document, create_theme } from "@nemu-ai/pdf";

const theme = create_theme("brand", {
  colors: { primary: "#1a365d", muted: "#718096", accent: "#3182ce" },
});
```

## Applying a theme

Apply a theme document wide with `set_theme`, or pass it to a single page through
`create_page`.

```ts theme={null}
const pdf = new Document({ page_size: "A4", margin: 50 });
pdf.set_theme(theme);
const page = pdf.create_page(theme);
```

## Reading colors

`theme.get_color` returns a registered color by name. Use it anywhere a color is accepted.

```ts theme={null}
theme.get_color("primary");

page.add(
  page.text({
    content: "Heading",
    style: { color: theme.get_color("primary") },
  }),
  page.text({
    content: "Subtle note",
    style: { color: theme.get_color("muted") },
  }),
);
```

<Tip>
  Define every brand color once in `create_theme`, then reference it with `get_color` so a
  single edit updates the whole document.
</Tip>

## Related pages

<CardGroup cols={2}>
  <Card title="Elements" icon="shapes" href="/packages/pdf/document/elements">
    Apply theme colors to text, rectangles, and images.
  </Card>

  <Card title="Overview" icon="ruler-combined" href="/packages/pdf/document/overview">
    The Document and Page classes and the build pipeline.
  </Card>
</CardGroup>
