1*4882a593Smuzhiyun.. _sphinxdoc: 2*4882a593Smuzhiyun 3*4882a593SmuzhiyunIntroduction 4*4882a593Smuzhiyun============ 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunThe Linux kernel uses `Sphinx`_ to generate pretty documentation from 7*4882a593Smuzhiyun`reStructuredText`_ files under ``Documentation``. To build the documentation in 8*4882a593SmuzhiyunHTML or PDF formats, use ``make htmldocs`` or ``make pdfdocs``. The generated 9*4882a593Smuzhiyundocumentation is placed in ``Documentation/output``. 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun.. _Sphinx: http://www.sphinx-doc.org/ 12*4882a593Smuzhiyun.. _reStructuredText: http://docutils.sourceforge.net/rst.html 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunThe reStructuredText files may contain directives to include structured 15*4882a593Smuzhiyundocumentation comments, or kernel-doc comments, from source files. Usually these 16*4882a593Smuzhiyunare used to describe the functions and types and design of the code. The 17*4882a593Smuzhiyunkernel-doc comments have some special structure and formatting, but beyond that 18*4882a593Smuzhiyunthey are also treated as reStructuredText. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunFinally, there are thousands of plain text documentation files scattered around 21*4882a593Smuzhiyun``Documentation``. Some of these will likely be converted to reStructuredText 22*4882a593Smuzhiyunover time, but the bulk of them will remain in plain text. 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun.. _sphinx_install: 25*4882a593Smuzhiyun 26*4882a593SmuzhiyunSphinx Install 27*4882a593Smuzhiyun============== 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunThe ReST markups currently used by the Documentation/ files are meant to be 30*4882a593Smuzhiyunbuilt with ``Sphinx`` version 1.3 or higher. 31*4882a593Smuzhiyun 32*4882a593SmuzhiyunThere's a script that checks for the Sphinx requirements. Please see 33*4882a593Smuzhiyun:ref:`sphinx-pre-install` for further details. 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunMost distributions are shipped with Sphinx, but its toolchain is fragile, 36*4882a593Smuzhiyunand it is not uncommon that upgrading it or some other Python packages 37*4882a593Smuzhiyunon your machine would cause the documentation build to break. 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunA way to avoid that is to use a different version than the one shipped 40*4882a593Smuzhiyunwith your distributions. In order to do so, it is recommended to install 41*4882a593SmuzhiyunSphinx inside a virtual environment, using ``virtualenv-3`` 42*4882a593Smuzhiyunor ``virtualenv``, depending on how your distribution packaged Python 3. 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun.. note:: 45*4882a593Smuzhiyun 46*4882a593Smuzhiyun #) Sphinx versions below 1.5 don't work properly with Python's 47*4882a593Smuzhiyun docutils version 0.13.1 or higher. So, if you're willing to use 48*4882a593Smuzhiyun those versions, you should run ``pip install 'docutils==0.12'``. 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun #) It is recommended to use the RTD theme for html output. Depending 51*4882a593Smuzhiyun on the Sphinx version, it should be installed in separate, 52*4882a593Smuzhiyun with ``pip install sphinx_rtd_theme``. 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun #) Some ReST pages contain math expressions. Due to the way Sphinx work, 55*4882a593Smuzhiyun those expressions are written using LaTeX notation. It needs texlive 56*4882a593Smuzhiyun installed with amdfonts and amsmath in order to evaluate them. 57*4882a593Smuzhiyun 58*4882a593SmuzhiyunIn summary, if you want to install Sphinx version 1.7.9, you should do:: 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun $ virtualenv sphinx_1.7.9 61*4882a593Smuzhiyun $ . sphinx_1.7.9/bin/activate 62*4882a593Smuzhiyun (sphinx_1.7.9) $ pip install -r Documentation/sphinx/requirements.txt 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunAfter running ``. sphinx_1.7.9/bin/activate``, the prompt will change, 65*4882a593Smuzhiyunin order to indicate that you're using the new environment. If you 66*4882a593Smuzhiyunopen a new shell, you need to rerun this command to enter again at 67*4882a593Smuzhiyunthe virtual environment before building the documentation. 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunImage output 70*4882a593Smuzhiyun------------ 71*4882a593Smuzhiyun 72*4882a593SmuzhiyunThe kernel documentation build system contains an extension that 73*4882a593Smuzhiyunhandles images on both GraphViz and SVG formats (see 74*4882a593Smuzhiyun:ref:`sphinx_kfigure`). 75*4882a593Smuzhiyun 76*4882a593SmuzhiyunFor it to work, you need to install both GraphViz and ImageMagick 77*4882a593Smuzhiyunpackages. If those packages are not installed, the build system will 78*4882a593Smuzhiyunstill build the documentation, but won't include any images at the 79*4882a593Smuzhiyunoutput. 80*4882a593Smuzhiyun 81*4882a593SmuzhiyunPDF and LaTeX builds 82*4882a593Smuzhiyun-------------------- 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunSuch builds are currently supported only with Sphinx versions 1.4 and higher. 85*4882a593Smuzhiyun 86*4882a593SmuzhiyunFor PDF and LaTeX output, you'll also need ``XeLaTeX`` version 3.14159265. 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunDepending on the distribution, you may also need to install a series of 89*4882a593Smuzhiyun``texlive`` packages that provide the minimal set of functionalities 90*4882a593Smuzhiyunrequired for ``XeLaTeX`` to work. 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun.. _sphinx-pre-install: 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunChecking for Sphinx dependencies 95*4882a593Smuzhiyun-------------------------------- 96*4882a593Smuzhiyun 97*4882a593SmuzhiyunThere's a script that automatically check for Sphinx dependencies. If it can 98*4882a593Smuzhiyunrecognize your distribution, it will also give a hint about the install 99*4882a593Smuzhiyuncommand line options for your distro:: 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun $ ./scripts/sphinx-pre-install 102*4882a593Smuzhiyun Checking if the needed tools for Fedora release 26 (Twenty Six) are available 103*4882a593Smuzhiyun Warning: better to also install "texlive-luatex85". 104*4882a593Smuzhiyun You should run: 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun sudo dnf install -y texlive-luatex85 107*4882a593Smuzhiyun /usr/bin/virtualenv sphinx_1.7.9 108*4882a593Smuzhiyun . sphinx_1.7.9/bin/activate 109*4882a593Smuzhiyun pip install -r Documentation/sphinx/requirements.txt 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun Can't build as 1 mandatory dependency is missing at ./scripts/sphinx-pre-install line 468. 112*4882a593Smuzhiyun 113*4882a593SmuzhiyunBy default, it checks all the requirements for both html and PDF, including 114*4882a593Smuzhiyunthe requirements for images, math expressions and LaTeX build, and assumes 115*4882a593Smuzhiyunthat a virtual Python environment will be used. The ones needed for html 116*4882a593Smuzhiyunbuilds are assumed to be mandatory; the others to be optional. 117*4882a593Smuzhiyun 118*4882a593SmuzhiyunIt supports two optional parameters: 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun``--no-pdf`` 121*4882a593Smuzhiyun Disable checks for PDF; 122*4882a593Smuzhiyun 123*4882a593Smuzhiyun``--no-virtualenv`` 124*4882a593Smuzhiyun Use OS packaging for Sphinx instead of Python virtual environment. 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun 127*4882a593SmuzhiyunSphinx Build 128*4882a593Smuzhiyun============ 129*4882a593Smuzhiyun 130*4882a593SmuzhiyunThe usual way to generate the documentation is to run ``make htmldocs`` or 131*4882a593Smuzhiyun``make pdfdocs``. There are also other formats available, see the documentation 132*4882a593Smuzhiyunsection of ``make help``. The generated documentation is placed in 133*4882a593Smuzhiyunformat-specific subdirectories under ``Documentation/output``. 134*4882a593Smuzhiyun 135*4882a593SmuzhiyunTo generate documentation, Sphinx (``sphinx-build``) must obviously be 136*4882a593Smuzhiyuninstalled. For prettier HTML output, the Read the Docs Sphinx theme 137*4882a593Smuzhiyun(``sphinx_rtd_theme``) is used if available. For PDF output you'll also need 138*4882a593Smuzhiyun``XeLaTeX`` and ``convert(1)`` from ImageMagick (https://www.imagemagick.org). 139*4882a593SmuzhiyunAll of these are widely available and packaged in distributions. 140*4882a593Smuzhiyun 141*4882a593SmuzhiyunTo pass extra options to Sphinx, you can use the ``SPHINXOPTS`` make 142*4882a593Smuzhiyunvariable. For example, use ``make SPHINXOPTS=-v htmldocs`` to get more verbose 143*4882a593Smuzhiyunoutput. 144*4882a593Smuzhiyun 145*4882a593SmuzhiyunTo remove the generated documentation, run ``make cleandocs``. 146*4882a593Smuzhiyun 147*4882a593SmuzhiyunWriting Documentation 148*4882a593Smuzhiyun===================== 149*4882a593Smuzhiyun 150*4882a593SmuzhiyunAdding new documentation can be as simple as: 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun1. Add a new ``.rst`` file somewhere under ``Documentation``. 153*4882a593Smuzhiyun2. Refer to it from the Sphinx main `TOC tree`_ in ``Documentation/index.rst``. 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun.. _TOC tree: http://www.sphinx-doc.org/en/stable/markup/toctree.html 156*4882a593Smuzhiyun 157*4882a593SmuzhiyunThis is usually good enough for simple documentation (like the one you're 158*4882a593Smuzhiyunreading right now), but for larger documents it may be advisable to create a 159*4882a593Smuzhiyunsubdirectory (or use an existing one). For example, the graphics subsystem 160*4882a593Smuzhiyundocumentation is under ``Documentation/gpu``, split to several ``.rst`` files, 161*4882a593Smuzhiyunand has a separate ``index.rst`` (with a ``toctree`` of its own) referenced from 162*4882a593Smuzhiyunthe main index. 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunSee the documentation for `Sphinx`_ and `reStructuredText`_ on what you can do 165*4882a593Smuzhiyunwith them. In particular, the Sphinx `reStructuredText Primer`_ is a good place 166*4882a593Smuzhiyunto get started with reStructuredText. There are also some `Sphinx specific 167*4882a593Smuzhiyunmarkup constructs`_. 168*4882a593Smuzhiyun 169*4882a593Smuzhiyun.. _reStructuredText Primer: http://www.sphinx-doc.org/en/stable/rest.html 170*4882a593Smuzhiyun.. _Sphinx specific markup constructs: http://www.sphinx-doc.org/en/stable/markup/index.html 171*4882a593Smuzhiyun 172*4882a593SmuzhiyunSpecific guidelines for the kernel documentation 173*4882a593Smuzhiyun------------------------------------------------ 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunHere are some specific guidelines for the kernel documentation: 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun* Please don't go overboard with reStructuredText markup. Keep it 178*4882a593Smuzhiyun simple. For the most part the documentation should be plain text with 179*4882a593Smuzhiyun just enough consistency in formatting that it can be converted to 180*4882a593Smuzhiyun other formats. 181*4882a593Smuzhiyun 182*4882a593Smuzhiyun* Please keep the formatting changes minimal when converting existing 183*4882a593Smuzhiyun documentation to reStructuredText. 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun* Also update the content, not just the formatting, when converting 186*4882a593Smuzhiyun documentation. 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun* Please stick to this order of heading adornments: 189*4882a593Smuzhiyun 190*4882a593Smuzhiyun 1. ``=`` with overline for document title:: 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun ============== 193*4882a593Smuzhiyun Document title 194*4882a593Smuzhiyun ============== 195*4882a593Smuzhiyun 196*4882a593Smuzhiyun 2. ``=`` for chapters:: 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun Chapters 199*4882a593Smuzhiyun ======== 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun 3. ``-`` for sections:: 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun Section 204*4882a593Smuzhiyun ------- 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun 4. ``~`` for subsections:: 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun Subsection 209*4882a593Smuzhiyun ~~~~~~~~~~ 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun Although RST doesn't mandate a specific order ("Rather than imposing a fixed 212*4882a593Smuzhiyun number and order of section title adornment styles, the order enforced will be 213*4882a593Smuzhiyun the order as encountered."), having the higher levels the same overall makes 214*4882a593Smuzhiyun it easier to follow the documents. 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun* For inserting fixed width text blocks (for code examples, use case 217*4882a593Smuzhiyun examples, etc.), use ``::`` for anything that doesn't really benefit 218*4882a593Smuzhiyun from syntax highlighting, especially short snippets. Use 219*4882a593Smuzhiyun ``.. code-block:: <language>`` for longer code blocks that benefit 220*4882a593Smuzhiyun from highlighting. For a short snippet of code embedded in the text, use \`\`. 221*4882a593Smuzhiyun 222*4882a593Smuzhiyun 223*4882a593Smuzhiyunthe C domain 224*4882a593Smuzhiyun------------ 225*4882a593Smuzhiyun 226*4882a593SmuzhiyunThe **Sphinx C Domain** (name c) is suited for documentation of C API. E.g. a 227*4882a593Smuzhiyunfunction prototype: 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun.. code-block:: rst 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun .. c:function:: int ioctl( int fd, int request ) 232*4882a593Smuzhiyun 233*4882a593SmuzhiyunThe C domain of the kernel-doc has some additional features. E.g. you can 234*4882a593Smuzhiyun*rename* the reference name of a function with a common name like ``open`` or 235*4882a593Smuzhiyun``ioctl``: 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun.. code-block:: rst 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun .. c:function:: int ioctl( int fd, int request ) 240*4882a593Smuzhiyun :name: VIDIOC_LOG_STATUS 241*4882a593Smuzhiyun 242*4882a593SmuzhiyunThe func-name (e.g. ioctl) remains in the output but the ref-name changed from 243*4882a593Smuzhiyun``ioctl`` to ``VIDIOC_LOG_STATUS``. The index entry for this function is also 244*4882a593Smuzhiyunchanged to ``VIDIOC_LOG_STATUS``. 245*4882a593Smuzhiyun 246*4882a593SmuzhiyunPlease note that there is no need to use ``c:func:`` to generate cross 247*4882a593Smuzhiyunreferences to function documentation. Due to some Sphinx extension magic, 248*4882a593Smuzhiyunthe documentation build system will automatically turn a reference to 249*4882a593Smuzhiyun``function()`` into a cross reference if an index entry for the given 250*4882a593Smuzhiyunfunction name exists. If you see ``c:func:`` use in a kernel document, 251*4882a593Smuzhiyunplease feel free to remove it. 252*4882a593Smuzhiyun 253*4882a593Smuzhiyun 254*4882a593Smuzhiyunlist tables 255*4882a593Smuzhiyun----------- 256*4882a593Smuzhiyun 257*4882a593SmuzhiyunWe recommend the use of *list table* formats. The *list table* formats are 258*4882a593Smuzhiyundouble-stage lists. Compared to the ASCII-art they might not be as 259*4882a593Smuzhiyuncomfortable for 260*4882a593Smuzhiyunreaders of the text files. Their advantage is that they are easy to 261*4882a593Smuzhiyuncreate or modify and that the diff of a modification is much more meaningful, 262*4882a593Smuzhiyunbecause it is limited to the modified content. 263*4882a593Smuzhiyun 264*4882a593SmuzhiyunThe ``flat-table`` is a double-stage list similar to the ``list-table`` with 265*4882a593Smuzhiyunsome additional features: 266*4882a593Smuzhiyun 267*4882a593Smuzhiyun* column-span: with the role ``cspan`` a cell can be extended through 268*4882a593Smuzhiyun additional columns 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun* row-span: with the role ``rspan`` a cell can be extended through 271*4882a593Smuzhiyun additional rows 272*4882a593Smuzhiyun 273*4882a593Smuzhiyun* auto span rightmost cell of a table row over the missing cells on the right 274*4882a593Smuzhiyun side of that table-row. With Option ``:fill-cells:`` this behavior can 275*4882a593Smuzhiyun changed from *auto span* to *auto fill*, which automatically inserts (empty) 276*4882a593Smuzhiyun cells instead of spanning the last cell. 277*4882a593Smuzhiyun 278*4882a593Smuzhiyunoptions: 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun* ``:header-rows:`` [int] count of header rows 281*4882a593Smuzhiyun* ``:stub-columns:`` [int] count of stub columns 282*4882a593Smuzhiyun* ``:widths:`` [[int] [int] ... ] widths of columns 283*4882a593Smuzhiyun* ``:fill-cells:`` instead of auto-spanning missing cells, insert missing cells 284*4882a593Smuzhiyun 285*4882a593Smuzhiyunroles: 286*4882a593Smuzhiyun 287*4882a593Smuzhiyun* ``:cspan:`` [int] additional columns (*morecols*) 288*4882a593Smuzhiyun* ``:rspan:`` [int] additional rows (*morerows*) 289*4882a593Smuzhiyun 290*4882a593SmuzhiyunThe example below shows how to use this markup. The first level of the staged 291*4882a593Smuzhiyunlist is the *table-row*. In the *table-row* there is only one markup allowed, 292*4882a593Smuzhiyunthe list of the cells in this *table-row*. Exceptions are *comments* ( ``..`` ) 293*4882a593Smuzhiyunand *targets* (e.g. a ref to ``:ref:`last row <last row>``` / :ref:`last row 294*4882a593Smuzhiyun<last row>`). 295*4882a593Smuzhiyun 296*4882a593Smuzhiyun.. code-block:: rst 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun .. flat-table:: table title 299*4882a593Smuzhiyun :widths: 2 1 1 3 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun * - head col 1 302*4882a593Smuzhiyun - head col 2 303*4882a593Smuzhiyun - head col 3 304*4882a593Smuzhiyun - head col 4 305*4882a593Smuzhiyun 306*4882a593Smuzhiyun * - column 1 307*4882a593Smuzhiyun - field 1.1 308*4882a593Smuzhiyun - field 1.2 with autospan 309*4882a593Smuzhiyun 310*4882a593Smuzhiyun * - column 2 311*4882a593Smuzhiyun - field 2.1 312*4882a593Smuzhiyun - :rspan:`1` :cspan:`1` field 2.2 - 3.3 313*4882a593Smuzhiyun 314*4882a593Smuzhiyun * .. _`last row`: 315*4882a593Smuzhiyun 316*4882a593Smuzhiyun - column 3 317*4882a593Smuzhiyun 318*4882a593SmuzhiyunRendered as: 319*4882a593Smuzhiyun 320*4882a593Smuzhiyun .. flat-table:: table title 321*4882a593Smuzhiyun :widths: 2 1 1 3 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun * - head col 1 324*4882a593Smuzhiyun - head col 2 325*4882a593Smuzhiyun - head col 3 326*4882a593Smuzhiyun - head col 4 327*4882a593Smuzhiyun 328*4882a593Smuzhiyun * - column 1 329*4882a593Smuzhiyun - field 1.1 330*4882a593Smuzhiyun - field 1.2 with autospan 331*4882a593Smuzhiyun 332*4882a593Smuzhiyun * - column 2 333*4882a593Smuzhiyun - field 2.1 334*4882a593Smuzhiyun - :rspan:`1` :cspan:`1` field 2.2 - 3.3 335*4882a593Smuzhiyun 336*4882a593Smuzhiyun * .. _`last row`: 337*4882a593Smuzhiyun 338*4882a593Smuzhiyun - column 3 339*4882a593Smuzhiyun 340*4882a593SmuzhiyunCross-referencing 341*4882a593Smuzhiyun----------------- 342*4882a593Smuzhiyun 343*4882a593SmuzhiyunCross-referencing from one documentation page to another can be done by passing 344*4882a593Smuzhiyunthe path to the file starting from the Documentation folder. 345*4882a593SmuzhiyunFor example, to cross-reference to this page (the .rst extension is optional):: 346*4882a593Smuzhiyun 347*4882a593Smuzhiyun See Documentation/doc-guide/sphinx.rst. 348*4882a593Smuzhiyun 349*4882a593SmuzhiyunIf you want to use a relative path, you need to use Sphinx's ``doc`` directive. 350*4882a593SmuzhiyunFor example, referencing this page from the same directory would be done as:: 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun See :doc:`sphinx`. 353*4882a593Smuzhiyun 354*4882a593SmuzhiyunFor information on cross-referencing to kernel-doc functions or types, see 355*4882a593SmuzhiyunDocumentation/doc-guide/kernel-doc.rst. 356*4882a593Smuzhiyun 357*4882a593Smuzhiyun.. _sphinx_kfigure: 358*4882a593Smuzhiyun 359*4882a593SmuzhiyunFigures & Images 360*4882a593Smuzhiyun================ 361*4882a593Smuzhiyun 362*4882a593SmuzhiyunIf you want to add an image, you should use the ``kernel-figure`` and 363*4882a593Smuzhiyun``kernel-image`` directives. E.g. to insert a figure with a scalable 364*4882a593Smuzhiyunimage format use SVG (:ref:`svg_image_example`):: 365*4882a593Smuzhiyun 366*4882a593Smuzhiyun .. kernel-figure:: svg_image.svg 367*4882a593Smuzhiyun :alt: simple SVG image 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun SVG image example 370*4882a593Smuzhiyun 371*4882a593Smuzhiyun.. _svg_image_example: 372*4882a593Smuzhiyun 373*4882a593Smuzhiyun.. kernel-figure:: svg_image.svg 374*4882a593Smuzhiyun :alt: simple SVG image 375*4882a593Smuzhiyun 376*4882a593Smuzhiyun SVG image example 377*4882a593Smuzhiyun 378*4882a593SmuzhiyunThe kernel figure (and image) directive support **DOT** formated files, see 379*4882a593Smuzhiyun 380*4882a593Smuzhiyun* DOT: http://graphviz.org/pdf/dotguide.pdf 381*4882a593Smuzhiyun* Graphviz: http://www.graphviz.org/content/dot-language 382*4882a593Smuzhiyun 383*4882a593SmuzhiyunA simple example (:ref:`hello_dot_file`):: 384*4882a593Smuzhiyun 385*4882a593Smuzhiyun .. kernel-figure:: hello.dot 386*4882a593Smuzhiyun :alt: hello world 387*4882a593Smuzhiyun 388*4882a593Smuzhiyun DOT's hello world example 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun.. _hello_dot_file: 391*4882a593Smuzhiyun 392*4882a593Smuzhiyun.. kernel-figure:: hello.dot 393*4882a593Smuzhiyun :alt: hello world 394*4882a593Smuzhiyun 395*4882a593Smuzhiyun DOT's hello world example 396*4882a593Smuzhiyun 397*4882a593SmuzhiyunEmbed *render* markups (or languages) like Graphviz's **DOT** is provided by the 398*4882a593Smuzhiyun``kernel-render`` directives.:: 399*4882a593Smuzhiyun 400*4882a593Smuzhiyun .. kernel-render:: DOT 401*4882a593Smuzhiyun :alt: foobar digraph 402*4882a593Smuzhiyun :caption: Embedded **DOT** (Graphviz) code 403*4882a593Smuzhiyun 404*4882a593Smuzhiyun digraph foo { 405*4882a593Smuzhiyun "bar" -> "baz"; 406*4882a593Smuzhiyun } 407*4882a593Smuzhiyun 408*4882a593SmuzhiyunHow this will be rendered depends on the installed tools. If Graphviz is 409*4882a593Smuzhiyuninstalled, you will see an vector image. If not the raw markup is inserted as 410*4882a593Smuzhiyun*literal-block* (:ref:`hello_dot_render`). 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun.. _hello_dot_render: 413*4882a593Smuzhiyun 414*4882a593Smuzhiyun.. kernel-render:: DOT 415*4882a593Smuzhiyun :alt: foobar digraph 416*4882a593Smuzhiyun :caption: Embedded **DOT** (Graphviz) code 417*4882a593Smuzhiyun 418*4882a593Smuzhiyun digraph foo { 419*4882a593Smuzhiyun "bar" -> "baz"; 420*4882a593Smuzhiyun } 421*4882a593Smuzhiyun 422*4882a593SmuzhiyunThe *render* directive has all the options known from the *figure* directive, 423*4882a593Smuzhiyunplus option ``caption``. If ``caption`` has a value, a *figure* node is 424*4882a593Smuzhiyuninserted. If not, a *image* node is inserted. A ``caption`` is also needed, if 425*4882a593Smuzhiyunyou want to refer it (:ref:`hello_svg_render`). 426*4882a593Smuzhiyun 427*4882a593SmuzhiyunEmbedded **SVG**:: 428*4882a593Smuzhiyun 429*4882a593Smuzhiyun .. kernel-render:: SVG 430*4882a593Smuzhiyun :caption: Embedded **SVG** markup 431*4882a593Smuzhiyun :alt: so-nw-arrow 432*4882a593Smuzhiyun 433*4882a593Smuzhiyun <?xml version="1.0" encoding="UTF-8"?> 434*4882a593Smuzhiyun <svg xmlns="http://www.w3.org/2000/svg" version="1.1" ...> 435*4882a593Smuzhiyun ... 436*4882a593Smuzhiyun </svg> 437*4882a593Smuzhiyun 438*4882a593Smuzhiyun.. _hello_svg_render: 439*4882a593Smuzhiyun 440*4882a593Smuzhiyun.. kernel-render:: SVG 441*4882a593Smuzhiyun :caption: Embedded **SVG** markup 442*4882a593Smuzhiyun :alt: so-nw-arrow 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun <?xml version="1.0" encoding="UTF-8"?> 445*4882a593Smuzhiyun <svg xmlns="http://www.w3.org/2000/svg" 446*4882a593Smuzhiyun version="1.1" baseProfile="full" width="70px" height="40px" viewBox="0 0 700 400"> 447*4882a593Smuzhiyun <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px"/> 448*4882a593Smuzhiyun <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)"/> 449*4882a593Smuzhiyun </svg> 450