Guidedog 手册 0.6.3
语言
本页内容
Guidedog / 文档 0.6.3

制作一本小书

网站允许读者通过链接自由浏览;书籍则需要明确的顺序、章节编号、页眉和前置页。

Guidedog 用目录指令 toctree 连接两种形式:同一棵树既构成网页侧栏,也决定 PDF 的线性章节顺序。

根文档的 toctree 在网页中形成交互导航和面包屑,在打印版中形成编号章节。
图 4 同一个 toctree 同时决定网页导航和书籍章节顺序。

1. 添加新章节

在 notes 项目中创建 measurement.rst:

代码 1 notes/measurement.rst
Measurement
===========

A scientific measurement consists of a numerical magnitude and an explicit unit.
Always report both. A bare number leaves the reader guessing.

.. _measurement-units:

Units of measurement
--------------------

Maintain a single, consistent unit system within every comparison.

When working with the International System of Units (SI):

* Length is expressed in meters (m).
* Mass is expressed in kilograms (kg).
* Time is expressed in seconds (s).

Prefixes scale units by powers of ten, simplifying very large or small values.

注意标题上方的 .. _measurement-units:。标签定义交叉引用目标,在网页和打印版中均有效。

2. 组织阅读顺序

打开 notes/index.rst,声明目录:

代码 2 notes/index.rst
Field Notes
===========

These notes explain how to perform reliable physical measurements and document
them clearly.

.. toctree::
   :maxdepth: 2
   :numbered:

   measurement

Next steps:

* Begin with :doc:`measurement`.
* Review the standard unit conventions in :ref:`measurement-units`.

toctree 选项说明:

  • :maxdepth: 2 设置目录中展示的子标题深度。
  • :numbered: 开启分层章节编号,如“1. Measurement”和“1.1 Units of measurement”。
  • measurement 引用文档名,不带 .rst 扩展名。

交叉引用语法:

  • :doc:`measurement` 按文档路径链接到章节。
  • :ref:`measurement-units` 链接到带标签的节。PDF 显示节标题;书籍模板还能通过 page-ref 添加页码,可用示例见 制作项目主题。

3. 添加 Graphviz 图示

图示能说明复杂关系。Guidedog 原生集成 Graphviz,为网页生成 SVG,为打印版嵌入矢量图,无须外部浏览器渲染器。

在 notes/measurement.rst 中添加图示:

Comparison workflow
-------------------

Before comparing two experimental values, convert both to a shared base unit:

.. graphviz::
   :class: graphviz-adaptive
   :caption: Converting values to a common base unit before comparison.
   :alt: Raw experimental values are converted to a shared unit before comparison.

   digraph comparison {
     graph [rankdir=LR, bgcolor="transparent", pad="0.2"];
     node [shape=box, style="rounded,filled", fillcolor="#edf5f2",
           color="#216553", fontname="Helvetica", fontcolor="#16382f", fontsize=12];
     edge [color="#216553"];

     "Raw values" -> "Unit conversion" -> "Common unit" -> "Comparison";
   }

:caption: 提供图注。需要编号时,在 notes/conf.toml 加入 numfig = true。:alt: 为屏幕阅读器提供替代文本。

4. 构建并检查书籍

重新构建项目:

guidedog build html notes -W
guidedog build pdf notes -W

分别检查两种输出:

  • HTML 网站: 打开 notes/_build/html/index.html。侧栏显示编号章节层级,点击“1. Measurement”可打开含面包屑和 SVG 图示的新页面。
  • PDF 书籍: 打开 notes/_build/pdf/field-notes-en.pdf。目录列出章节和页码,图示保持矢量形式,文档交叉引用链接到对应位置。

5. 下一步

理解两种输出后,可继续阅读专题: