如何在 sphinx 中将使用自动摘要创建的某些存根文件显示为目录中的副标题?
我在sphinx中使用autosummary
来创建存根文件,并通过index.rst
文件进行记录。我有一个模块文件夹,其中有一些Python文件。我希望这些python文件是在生成PDF中的模块标题下创建的。
这是我的目录结构:
optimate
├── doc
| ├── source
| | ├── index.rst
| | ├── conf.py
| | └── ...
| └── Makefile
├── optimate
| ├── core
| │ ├── __init__.py
| | └── optimizer.py
| └── ...
└── ...
以下是我的conf.py
:
# -- Path setup --------------------------------------------------------------
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('../../optimate'))
sys.path.insert(0, os.path.abspath('../../optimate/core'))
# -- Project information -----------------------------------------------------
import optimate
import re
project = 'optimate'
copyright = '2022, Muhammad Mohsin Khan'
author = 'Muhammad Mohsin Khan'
version = re.sub(r'(\d+\.\d+)\.\d+(.*)', r'\1\2', optimate.__version__)
version = re.sub(r'(\.dev\d+).*?$', r'\1', version)
# The full version, including alpha/beta/rc tags.
release = optimate.__version__
# -- General configuration ---------------------------------------------------
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx.ext.intersphinx',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinxcontrib.bibtex',
'recommonmark'
]
templates_path = ['_templates']
source_suffix = ['.rst', '.md']
# source_suffix = '.rst'
# The root toctree document.
root_doc = 'index'
language = None
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_static_path = ['_static']
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'localtoc.html',
'sourcelink.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html'
]
}
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'optimatedoc'
# -- Options for LaTeX output ---------------------------------------------
numfig = True
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '11pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
'figure_align': 'h',
# Leaves no blank page after every section
#
'extraclassoptions': 'openany,oneside'
}
latex_documents = [
(root_doc, 'index.tex', 'Optimate Documentation',
'Muhammad Mohsin Khan', 'manual'),
]
# -- Options for manual page output ---------------------------------------
man_pages = [
(root_doc, 'optimate', 'Optimate Documentation',
[author], 1)
]
# -- Options for Texinfo output -------------------------------------------
texinfo_documents = [
(root_doc, 'optimate', 'Optimate Documentation',
author, 'Optimate', 'One line description of project.',
'Miscellaneous'),
]
# Autosummary
autosummary_generate = True
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
以下是我的index.rst
:
Optimate - Automatic parameter optimizer for different material models
======================================================================
.. image:: /images/optimate_logo.jpg
:align: center
About
=====
.. autosummary::
:toctree: modules
optimate
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
.. autosummary::
:toctree: modules/submodules
optimate.core.optimizer
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
我在pdf文件中作为目录(toc), 时,当我在doc/
文件夹中进行latexpdf 。
1 About 2
1.1 optimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Modules
2.1 optimate.core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 optimate.core.optimizer . . . . . . . . . . . . . . . . . . . . . . . 3
当我在doc/
文件夹中运行在pdf中我想要的目录(toc)是:
1 About 2
1.1 optimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Modules
2.1 optimate.core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 optimate.core.optimizer . . . . . . . . . . . . . . . . . . . . 3
i 尝试更改index.rst
as:
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
Submodules
----------
.. autosummary::
:toctree: modules/submodules
optimate.core.optimizer
我还用#
作为下划线的自定义模板,然后将其传递到autosummary
as
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
.. autosummary::
:toctree: modules/submodules
:template: mytemplate.rst
optimate.core.optimizer
: optimate.core.optimizer.rst
用#
作为下划线的存根文件标题,但似乎不起作用,我仍然得到上述结果。有人知道解决方案吗?还是提出另一种方法来做到这一点?
I am using autosummary
in sphinx to create stub files and document them through the index.rst
file. I have a module folder and have some Python files in it. I wanted these Python files to be created as a subheading under the module heading in the generated pdf.
This is my directory structure:
optimate
├── doc
| ├── source
| | ├── index.rst
| | ├── conf.py
| | └── ...
| └── Makefile
├── optimate
| ├── core
| │ ├── __init__.py
| | └── optimizer.py
| └── ...
└── ...
Following is my conf.py
:
# -- Path setup --------------------------------------------------------------
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('../../optimate'))
sys.path.insert(0, os.path.abspath('../../optimate/core'))
# -- Project information -----------------------------------------------------
import optimate
import re
project = 'optimate'
copyright = '2022, Muhammad Mohsin Khan'
author = 'Muhammad Mohsin Khan'
version = re.sub(r'(\d+\.\d+)\.\d+(.*)', r'\1\2', optimate.__version__)
version = re.sub(r'(\.dev\d+).*?
and following is my index.rst
:
Optimate - Automatic parameter optimizer for different material models
======================================================================
.. image:: /images/optimate_logo.jpg
:align: center
About
=====
.. autosummary::
:toctree: modules
optimate
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
.. autosummary::
:toctree: modules/submodules
optimate.core.optimizer
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
What I get in the pdf file as Table of Contents (TOC), when I run make latexpdf
in the doc/
folder, is:
1 About 2
1.1 optimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Modules
2.1 optimate.core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 optimate.core.optimizer . . . . . . . . . . . . . . . . . . . . . . . 3
What I want as Table of Contents (TOC) in the pdf is:
1 About 2
1.1 optimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Modules
2.1 optimate.core . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 optimate.core.optimizer . . . . . . . . . . . . . . . . . . . . 3
I tried changing the index.rst
as:
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
Submodules
----------
.. autosummary::
:toctree: modules/submodules
optimate.core.optimizer
I also made a custom template with #
as an underline and passed it to the autosummary
as:
Modules
=======
.. autosummary::
:toctree: modules
optimate.core
.. autosummary::
:toctree: modules/submodules
:template: mytemplate.rst
optimate.core.optimizer
which creates optimate.core.optimizer.rst
stub file heading with #
as underline but it doesn't seem to work and I still get the above-undesired result. Does anybody know a solution to this? Or propose an alternative way to do this?
, r'\1', version)
# The full version, including alpha/beta/rc tags.
release = optimate.__version__
# -- General configuration ---------------------------------------------------
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx.ext.intersphinx',
'sphinx.ext.imgmath',
'sphinx.ext.viewcode',
'sphinx.ext.napoleon',
'sphinxcontrib.bibtex',
'recommonmark'
]
templates_path = ['_templates']
source_suffix = ['.rst', '.md']
# source_suffix = '.rst'
# The root toctree document.
root_doc = 'index'
language = None
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_static_path = ['_static']
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'localtoc.html',
'sourcelink.html',
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html'
]
}
# -- Options for HTMLHelp output ------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'optimatedoc'
# -- Options for LaTeX output ---------------------------------------------
numfig = True
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
'papersize': 'a4paper',
# The font size ('10pt', '11pt' or '12pt').
#
'pointsize': '11pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
'figure_align': 'h',
# Leaves no blank page after every section
#
'extraclassoptions': 'openany,oneside'
}
latex_documents = [
(root_doc, 'index.tex', 'Optimate Documentation',
'Muhammad Mohsin Khan', 'manual'),
]
# -- Options for manual page output ---------------------------------------
man_pages = [
(root_doc, 'optimate', 'Optimate Documentation',
[author], 1)
]
# -- Options for Texinfo output -------------------------------------------
texinfo_documents = [
(root_doc, 'optimate', 'Optimate Documentation',
author, 'Optimate', 'One line description of project.',
'Miscellaneous'),
]
# Autosummary
autosummary_generate = True
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
and following is my index.rst
:
What I get in the pdf file as Table of Contents (TOC), when I run make latexpdf
in the doc/
folder, is:
What I want as Table of Contents (TOC) in the pdf is:
I tried changing the index.rst
as:
I also made a custom template with #
as an underline and passed it to the autosummary
as:
which creates optimate.core.optimizer.rst
stub file heading with #
as underline but it doesn't seem to work and I still get the above-undesired result. Does anybody know a solution to this? Or propose an alternative way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论