Search code examples
pythonpython-sphinxversioningrestructuredtext

How to print the document version in the title?


I've just created a Sphinx doc using sphinx-quickstart.exe with alabaster theme.

And I would like to print the version of the document somewhere in the title.

I filled version and release variables in conf.py

# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.

# -- Project information -----------------------------------------------------

project = 'MWE'
copyright = '2019, and1er'
author = 'and1er'

# The short X.Y version
version = '2.4.12'
# The full version, including alpha/beta/rc tags
release = 'beta'

extensions = [
]

templates_path = ['_templates']
source_suffix = '.rst'

master_doc = 'index'
language = None
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
pygments_style = 'sphinx'

html_theme = 'alabaster'

html_static_path = ['_static']
htmlhelp_basename = 'MWEdoc'

index.rst

.. MWE documentation master file, created by
    sphinx-quickstart on Tue Feb  5 14:51:07 2019.
    You can adapt this file completely to your liking, but it should at least
    contain the root `toctree` directive.

Welcome to MWE's documentation!
===============================

.. toctree::
    :maxdepth: 2
    :caption: Contents:

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Resulting document does not have 2.4.12 or beta strings.

Resulting document


Solution

  • Does |version| substitution works for you?

    UPD An updated MWE

    index.rst

    .. MWE documentation master file, created by
       sphinx-quickstart on Tue Feb  5 14:51:07 2019.
       You can adapt this file completely to your liking, but it should at least
       contain the root `toctree` directive.
    
    Welcome to MWE's documentation!
    ===============================
    
    .. toctree::
       :maxdepth: 2
       :caption: Contents:
    
    Document version:
    |version|
    |release|
    
    
    Indices and tables
    ==================
    
    * :ref:`genindex`
    * :ref:`modindex`
    * :ref:`search`
    

    The expected result