Guidedog / ドキュメント
1.0.0-beta.16
小さな本を作る¶
Web サイトはリンクでつながったページの網で、読者は好きな順に読み進めます。書籍には、番号付きの章、柱、前付けを備えた、意図された読む順序が必要です。
Guidedog では、目次ディレクティブ(toctree)が両方の形式を担います。1 つの toctree で、文書を Web 用のサイドバーのツリーにも、PDF 書籍の章の並びにもまとめられます。
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: に注目してください。ラベルは相互参照のターゲットになります。Web でも印刷物でも同じように機能します。
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 エンジンを組み込んでおり、ベクター図を Web ページ用には SVG、印刷用には PDF の図として描画します。外部のレンダラーは不要です。
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 の Web サイト:
notes/_build/html/index.htmlを開きます。サイドバーに番号付きの章が表示されます。「1. Measurement」をクリックすると、パンくずリストと SVG の図を含む新しいページが開きます。 - PDF:
notes/_build/pdf/field-notes-en.pdfを開きます。目次は章とページを示し、図はベクターのまま、文書参照は対象へリンクします。
5. 次に進む¶
これで、1 つのソースから 2 つの出力が作られる仕組みがわかりました。トピックの章ではさらに詳しく扱います。
- マークアップ、リスト、表については 文書を書く を参照してください。
- 数式については 数学と証明 を参照してください。
- Graphviz と Typst の図については Graphviz と Typst による図 を参照してください。
- 独自のスタイルと書籍用フォントについては 読みやすい組版 を参照してください。