# 配置：练习

> 练习样式（exerciseStyles）和全书的练习设置（exercises）：题号的样子、题目要求的字体、选项的序号和勾选记号、填空处、判断题的答案、连线、词库、书写区、方格、竖式除法、难度记号、图标、答案的颜色、答案印在哪里、教师用书和屏幕版本

- HTML版本: https://postext.dev/zh/docs/configuration-exercises
- 最后更新: 2026-10-24
- 阅读时间: 12分钟
- 其他语言: [en](https://postext.dev/en/docs/configuration-exercises.md), [es](https://postext.dev/es/docs/configuration-exercises.md), [ca](https://postext.dev/ca/docs/configuration-exercises.md), [de](https://postext.dev/de/docs/configuration-exercises.md), [fr](https://postext.dev/fr/docs/configuration-exercises.md), [it](https://postext.dev/it/docs/configuration-exercises.md), [pt](https://postext.dev/pt/docs/configuration-exercises.md), [ja](https://postext.dev/ja/docs/configuration-exercises.md), [ar](https://postext.dev/ar/docs/configuration-exercises.md)

## 简单来说

本页列出控制练习外观的所有设置。练习样式决定题号怎样印、选项怎样标序号、待填的空是什么样子、书写区画什么格线，以及方格和竖式怎样画。全书设置决定答案印在哪里，以及这本书是学生用书还是教师用书。全书设置还决定读者怎样在屏幕上作答。练习本身怎样写，见“练习”一页。

## 练习样式

`exerciseStyles`属性声明一组具名样式，练习用`:::exercise{style="…"}`选用。一种样式是一类练习的形式；题目和答案仍然写在Markdown里（见[练习](https://postext.dev/zh/docs/exercises.md)）。默认自带一种样式`exercise`，所以不做任何配置也能使用这个块；一旦声明`exerciseStyles`，就会替换它，声明的第一种样式就是没写`style`的练习所用的样式。所有字段都是可选的；在各国学校习惯不同的地方，默认值随文档语言而定：选项的序号、判断题的两个符号、除法竖式的排法、印出的文字。

```ts
const config: PostextConfig = {
  exerciseStyles: [
    {
      id: 'activity',
      box: 'activity-frame',
      number: { shape: 'disc', background: { hex: '#2a5ea8', model: 'hex' } },
      instruction: { fontFamily: 'Noto Sans SC' },
      options: { marker: 'circle' },
      blank: { look: 'dots', width: 'answer' },
      area: { kind: 'tianzige', lines: 4 },
      level: { glyph: '★', empty: '☆' },
      icons: { pair: { glyph: '👥' } },
    },
    { id: 'quiz', extends: 'activity', options: { layout: 'row', columns: 4 } },
  ],
};
```

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `id` | `string` | — | 由`:::exercise{style="…"}`选用的标识符。未知的id改用第一种样式，并会被报告（`exerciseUnknownStyle`）。 |
| `name` | `string` | `id` | 便于阅读的名称（仅用于编辑器界面）。 |
| `extends` | `string` | — | 作为基础的另一种样式的id。各组设置（`number`、`options`、`blank`……）逐个字段合并，`icons`按id合并。 |
| `box` | `string` | — | 练习外框所用的[`calloutStyles`](https://postext.dev/zh/docs/configuration-callouts.md#标注框样式)中的id：底色、边框、色条、内边距、放置、拆分。未设置时，练习排在正文里，不加框，并保持在同一页上。 |
| `number` | `object` | — | 题号怎样印。见[编号](https://postext.dev/zh/docs/configuration-exercises.md#编号)。 |
| `instruction` | `object` | — | 题目要求的字体。见[题目要求](https://postext.dev/zh/docs/configuration-exercises.md#题目要求)。 |
| `options` | `object` | — | 选择题的选项。见[选项](https://postext.dev/zh/docs/configuration-exercises.md#选项)。 |
| `blank` | `object` | — | `[[…]]`怎样印。见[填空处](https://postext.dev/zh/docs/configuration-exercises.md#填空处)。 |
| `trueFalse` | `object` | — | 判断题的答案。见[判断](https://postext.dev/zh/docs/configuration-exercises.md#判断)。 |
| `match` | `object` | — | 要连线的两栏。见[连线](https://postext.dev/zh/docs/configuration-exercises.md#连线)。 |
| `bank` | `object` | — | 词库。见[词库](https://postext.dev/zh/docs/configuration-exercises.md#词库)。 |
| `area` | `object` | — | 书写区。见[书写区](https://postext.dev/zh/docs/configuration-exercises.md#书写区)。 |
| `grid` | `object` | — | 找词游戏、填字游戏和竖式的格子。见[方格](https://postext.dev/zh/docs/configuration-exercises.md#方格)。 |
| `arithmetic` | `object` | — | 竖式计算。见[竖式](https://postext.dev/zh/docs/configuration-exercises.md#竖式)。 |
| `level` | `object` | — | 难度记号。见[难度](https://postext.dev/zh/docs/configuration-exercises.md#难度)。 |
| `icons` | `Record<string, ExerciseIcon>` | `{}` | 按id列出的活动图标，由起始行的`icon`指定。见[图标](https://postext.dev/zh/docs/configuration-exercises.md#图标)。 |
| `answers` | `object` | — | 答案在教师用书、示范题和解答中怎样印。见[答案](https://postext.dev/zh/docs/configuration-exercises.md#答案)。 |
| `solutions` | `ExerciseSolutionsConfig` | — | 用于本样式练习的全书[`exercises.solutions`](https://postext.dev/zh/docs/configuration-exercises.md#参考答案)：只改这里设了的字段。 |
| `digital` | `object` | — | 屏幕版本的颜色。见[屏幕上的颜色](https://postext.dev/zh/docs/configuration-exercises.md#屏幕上的颜色)。 |
| `marginTop` | `Dimension` | `1em` | 没有`box`的练习上方的空白。 |
| `marginBottom` | `Dimension` | `1em` | 没有`box`的练习下方的空白。 |
| `itemSpacing` | `Dimension` | `0.25em` | 两个项之间的空白：选项、小题、判断句、配对。 |

### 编号

`number`设定练习的题号。不带形状的题号用粗体、主色，后面跟一个句点；带形状的题号是主色的圆形、方形或圆角方形里的白色数字，后面不加符号。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `show` | `boolean` | `true` | 是否印出题号。不印时照样计数。 |
| `label` | `boolean \| string` | `false` | 题号前的词：`true`取文档语言的词（中文为“练习”，英文为Exercise，西班牙文为Ejercicio，德文为Übung，日文为“練習”，阿拉伯文为تمرين……），字符串就是这个词本身（`'活动'`）。 |
| `shape` | `'none' \| 'disc' \| 'square' \| 'rounded'` | `'none'` | 题号所在的形状。 |
| `color` | `ColorValue` | 有形状时为白色，否则为主色 | 题号的颜色。 |
| `background` | `ColorValue` | 主色 | 形状的填色。 |
| `fontFamily` | `string` | 周围文字的字体 | 题号的字体族。 |
| `fontSize` | `Dimension` | `1em` | 题号的字号，em以题目要求的字号为准。 |
| `fontWeight` | `number` | `700` | 600及以上排成粗体。 |
| `suffix` | `string` | `'.'`，有形状时不加 | 印在不带形状的题号及其前面的词之后：`'.'`、`')'`、`'、'`。 |
| `template` | `string` | `'{n}'` | 题号的内容：`{n}`是练习的计数，`{h1}`和`{h2}`是章和节的编号（`'{h1}.{n}'`印出3.4）。 |
| `resetOn` | `'never' \| 'h1' … 'h6'` | `'h1'` | 在哪一级标题处重新计数；`'never'`表示全书连续计数。 |
| `counter` | `string` | `'exercise'` | 本样式推进的计数器。指定同一个计数器的样式共用它；有自己计数器的样式（`'review'`）单独给它的练习编号。 |
| `format` | `ResourceCounterFormat` | `'decimal'` | `{n}`的数字写法，与资源计数器相同：`'roman-upper'`、`'alpha-lower'`、`'simp-chinese-informal'`（一、二）、`'circled-decimal'`（①、②）、`'arabic-indic'`……中文试卷的大题号“一、二、”用`'simp-chinese-informal'`加上`suffix: '、'`。 |

### 题目要求

`instruction`设定练习开头的段落。未设置的字段取正文的设置。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `bold` | `boolean` | `true` | 把题目要求排成粗体。 |
| `italic` | `boolean` | `false` | 排成斜体。 |
| `color` | `ColorValue` | 正文的颜色 | 它的颜色，包括其中的粗体文字。 |
| `fontFamily` | `string` | 正文的字体 | 它的字体族：正文用宋体、题目要求用黑体，是课本里常见的搭配。 |
| `fontSize` | `Dimension` | 正文的字号 | 它的字号。 |

### 选项

`options`设定选择题（`- [ ] …`）的选项。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `labels` | `ResourceCounterFormat \| 'none'` | 随语言而定 | 选项怎样编序号：中文用`'alpha-upper'`（A、B、C），英文等语言用`'alpha-lower'`（a、b、c），日文用`'katakana'`（ア、イ、ウ），阿拉伯文用`'abjad'`（أ、ب、ج）。也可以用`'decimal'`、`'katakana-iroha'`、`'circled-decimal'`……`'none'`不印序号。 |
| `prefix` | `string` | `''` | 印在序号前：`'('`得到(a)。 |
| `suffix` | `string` | 中文为`'.'`；其他语言为`')'`，日文不加 | 印在序号后。 |
| `marker` | `'none' \| 'box' \| 'circle'` | `'none'` | 每个选项前供勾选的方框或圆圈。设为`'none'`时，读者圈出序号。 |
| `layout` | `'stack' \| 'row'` | `'stack'` | `'stack'`：每行一个选项，转行的文字悬挂在选项文字下面。`'row'`：选项并排。起始行的`columns=n`也会让选项按行排。 |
| `columns` | `number` | 全部 | `'row'`版式中每行的选项数（最多6个）。 |
| `shuffle` | `boolean` | `false` | 打乱选项的顺序，各种输出和答案表中的顺序都一样。 |
| `indent` | `Dimension` | `1em` | 没有题干的题目中，选项距文字边缘的缩进。 |
| `bracket` | `boolean` | `false` | 在每个小题题干的末尾加一对括号`（　）`，让学生填写字母，中文和日文试卷就是这样印的。教师用书把字母写在括号里。 |

### 填空处

`blank`设定学生用书中`[[…]]`怎样印：留出与答案一样大的位置，画一条横线、一行点或一个方框，答案本身不印。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `look` | `'line' \| 'dots' \| 'box' \| 'none'` | `'line'` | 供书写的横线、点线、方框，或者只留空白。 |
| `width` | `'answer' \| 'longest' \| Dimension` | `'longest'` | `'longest'`：本练习的每个空都和最长的答案一样宽，任何一个空都不会泄露答案。`'answer'`：每个空和自己的答案一样宽。一个长度：所有空都用这个宽度。空自身的`{width=N}`优先于它。 |
| `extra` | `Dimension` | `1.5em` | 在答案宽度上增加的空白，以整em计。 |
| `minWidth` | `Dimension` | `3em` | 最窄的空的宽度。 |
| `color` | `ColorValue` | 黑色 | 横线、点或方框的颜色。设置后，它也用于供勾选的方框和圆圈，以及词库中各词的框，这些在未设置时用主色。 |
| `weight` | `Dimension` | `0.6pt` | 横线的粗细。 |

### 判断

`trueFalse`设定判断句末尾的答案。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `labels` | `[string, string]` | 随语言而定 | 两个答案：中文为√ ×；英文为`['T', 'F']`；西班牙文、加泰罗尼亚文、法文、意大利文和葡萄牙文为V F；德文为R F；日文为○ ×；阿拉伯文为صح خطأ。 |
| `look` | `'boxes' \| 'bracket'` | `'boxes'` | `'boxes'`：每个符号带一个供勾选的方框，排在行末。`'bracket'`：只留一个空，让学生写答案。 |

### 连线

`match`设定配对练习。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `look` | `'dots' \| 'letters'` | `'dots'` | `'dots'`：两栏，每一项旁边有一个圆点，供连线。`'letters'`：右栏标上字母，左栏每一项旁边留一个填字母的空。 |
| `gap` | `Dimension` | `4em` | 两栏之间的距离。 |
| `dotSize` | `Dimension` | `0.35em` | 圆点的直径。 |
| `color` | `ColorValue` | 主色 | 圆点的颜色，也是词库框的颜色。 |

### 词库

`bank`设定词库框，用于带`bank`或`::bank[…]`的填空题和所有分类题。写了`::bank`这一行时，框印在该行的位置；没写时印在题目要求下面。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `box` | `string` | 连线颜色的边框 | 词库框所用的`calloutStyles`中的id。 |
| `order` | `'shuffle' \| 'alpha' \| 'written'` | `'shuffle'` | 词语打乱顺序（用固定的随机种子）、按文档语言的字母顺序排列，或按书写顺序。 |
| `separator` | `string` | 一个全角空格 | 两个词之间的分隔。每个词排在一个带细边框的行内标签里。 |

### 书写区

`area`设定问答题下面、连词成句的句子下面和分类题各栏里的书写空间。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `kind` | `'lines' \| 'dots' \| 'grid' \| 'seyes' \| 'tianzige' \| 'box' \| 'none'` | `'lines'` | 横线、一行行的点、方格纸、法国的Seyès格线、田字格、空框，或者空白。起始行的`area`优先于它。 |
| `lines` | `number` | `3` | 有几行高。起始行的`lines`优先于它。 |
| `spacing` | `Dimension` | 正文行高的1.35倍（方格为1.2倍） | 两行之间的距离。 |
| `color` | `ColorValue` | 浅灰色 | 格线的颜色。 |
| `weight` | `Dimension` | `0.5pt` | 格线的粗细。 |

### 方格

`grid`设定找词游戏、填字游戏和竖式的格子。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `cell` | `Dimension` | `1.6em` | 格子的边长。 |
| `fontFamily` | `string` | 正文的字体 | 字母、汉字和数字的字体族。 |
| `fontSize` | `Dimension` | 格子边长的0.58 | 格中文字和数字的大小，em以正文为准。 |
| `color` | `ColorValue` | 正文的颜色 | 字母、汉字和数字的颜色。 |
| `rule` | `ColorValue` | 中灰色 | 格子线的颜色。 |
| `ruleWidth` | `Dimension` | `0.6pt` | 格子线的粗细。 |
| `blocked` | `ColorValue` | — | 填字游戏中没有词占用的格子的填充色。不设时，只印出各个词的格子。 |
| `uppercase` | `boolean` | `true` | 按文档语言的大小写规则，把找词游戏和填字游戏中的字母排成大写。汉字不受影响。 |

### 竖式

`arithmetic`设定竖式计算。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `division` | `'bracket' \| 'potence' \| 'inline'` | 随语言而定 | 除法竖式。`'bracket'`：除数在被除数左边，被除数上面是“厂”字形的除号，商写在最上方（中文、英文、日文、阿拉伯文，以及没有自己排法的语言）。`'potence'`：除数在被除数右边的L形线下，商写在除数下面（西班牙文、加泰罗尼亚文、法文、意大利文、葡萄牙文）。`'inline'`：`864 : 4 =`，商写在同一行，计算步骤写在下面（德文）。 |
| `columns` | `number` | `4` | 每行的算式数，栏太窄时减少。 |

### 难度

`level`设定起始行的`level`在题号后印出的记号，字号较小。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `glyph` | `string` | `'●'` | 达到的级别：`'★'`、`'■'`。 |
| `empty` | `string` | `'○'` | 未达到的级别；`''`表示不印。 |
| `max` | `number` | `3` | 最高级别：`level=2`配合`max: 3`印出●●○。 |
| `color` | `ColorValue` | 主色 | 记号的颜色。 |

### 图标

`icons`把id对应到一个活动图标（口头、书面、同桌合作、听力、计算器），起始行写了它时印在题号后面：`icon="pair"`。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `glyph` | `string` | — | 要印的字符：`'✎'`、`'🎧'`，或图标字体中的一个字形。 |
| `fontFamily` | `string` | — | 图标字体的字体族。 |
| `color` | `ColorValue` | — | 图标的颜色。 |
| `resourceId` | `string` | — | 用作图标的位图或SVG资源。 |
| `alt` | `string` | — | 图标的含义，供读屏软件和带标签的PDF使用。 |
| `size` | `number` | `0.75` | 图标高度，以题干的 em 计；默认为一个大写字母的高度。 |

图标作为行内符号印在题号之后：若`resourceId`指定了资源，就印该图片，否则用`fontFamily`和`color`（未设时用正文颜色）印`glyph`。图标立在题干的基线上，高`size`个 em，屏幕阅读器在原处读出它的`alt`。

### 答案

`answers`设定答案出现时的样子：教师用书、`example`练习中的示范题、圈和涂满的方框、配对之间画的线、格子里的字母和数字。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `color` | `ColorValue` | `#d6246e`，品红 | 答案的颜色，就像教师用书套印的那样。 |
| `fontFamily` | `string` | 正文的字体 | 答案的字体：常用手写体。 |
| `italic` | `boolean` | `false` | 把空里的答案排成斜体。 |

### 屏幕上的颜色

`digital`设定HTML阅读器和EPUB电子书怎样显示核对过的答案。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `correctColor` | `ColorValue` | 绿色（`#1e8e3e`） | 答对的答案。 |
| `wrongColor` | `ColorValue` | 红色（`#c5221f`） | 答错的答案。 |

## 全书设置

`exercises`属性保存整本书的设置：版本、答案印在哪里、所有打乱顺序所用的随机种子，以及屏幕版本。既没有设`exercises`也没有设`exerciseStyles`的书，排版结果和哈希值都与以前相同。

```ts
const config: PostextConfig = {
  exercises: {
    edition: 'student',
    solutions: { placement: 'chapterEnd', layout: 'key' },
    seed: 3,
    digital: { check: 'instant' },
  },
};
```

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `edition` | `'student' \| 'teacher'` | `'student'` | `'teacher'`用`answers`的颜色把每个答案印在它的位置上：由学生用书的文字得到教师用书。 |
| `solutions` | `ExerciseSolutionsConfig` | — | 答案印在哪里、怎样印。见[参考答案](https://postext.dev/zh/docs/configuration-exercises.md#参考答案)。 |
| `seed` | `number` | `1` | 所有打乱顺序的依据：选项、右栏、排序项、连词成句的词块、词库、找词方阵中的填充字。修改它可以得到同一份试卷的另一个版本；印刷版、屏幕版和答案表始终一致。 |
| `digital` | `object` | — | HTML阅读器和EPUB电子书。见[屏幕版本](https://postext.dev/zh/docs/configuration-exercises.md#屏幕版本)。 |

### 参考答案

`exercises.solutions`，以及样式中对本样式练习生效的`solutions`。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `placement` | `'none' \| 'after' \| 'inverted' \| 'chapterEnd' \| 'directive'` | `'none'` | `'none'`：印刷版不印答案。`'after'`：印在每道练习后面，字号较小。`'inverted'`：印在每道练习后面，倒过来印。`'chapterEnd'`：印在章末，放在`heading`下面。`'directive'`：印在`:::solutions`那一行所在的位置。 |
| `box` | `string` | 小字号的无框框 | 答案框所用的`calloutStyles`中的id，也用于一章答案的列表。 |
| `heading` | `string` | 文档语言的词 | 章末答案的标题：中文为“参考答案”，其他语言为Solutions、Soluciones、Solucions、Corrigés、Lösungen、Soluzioni、Gabarito、解答、الحلول。`:::solutions{title="…"}`一行可以另设标题。 |
| `layout` | `'key' \| 'full'` | `'full'` | `'key'`：只印答案（1 B · 2 水分）。`'full'`：先印答案，再印这道练习的`:::solution`。 |

### 屏幕版本

`exercises.digital`设定练习在HTML阅读器和EPUB电子书中的行为。

| 属性 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `interactive` | `boolean` | `true` | 读者可以作答的练习。`false`按印刷版的样子显示。 |
| `persist` | `boolean` | `true` | 把读者的答案按书保存在浏览器中。 |
| `check` | `'button' \| 'instant'` | `'button'` | `'button'`：读者要求时才核对答案。`'instant'`：每填一个答案就立即核对。 |

屏幕版本可以有自己的练习设置：`htmlViewer.overrides`也接受`exercises`和`exerciseStyles`，在HTML阅读器排版之前合并到书的设置上。这样，印刷版可以把答案放在章末，屏幕上则隐藏答案；屏幕版也可以去掉读者用不上的书写区。

```ts
const config: PostextConfig = {
  htmlViewer: {
    overrides: {
      exercises: { solutions: { placement: 'none' } },
      exerciseStyles: [{ id: 'exercise', area: { kind: 'none' }, blank: { minWidth: { value: 6, unit: 'em' } } }],
    },
  },
};
```
