How to hide the sidebar using Sphinx RTD theme when making htmlhelp
Asked Answered
E

3

7

Is it possible to hide the sidebar when using Sphinx with the ReadTheDocs theme?

Extending the question a bit more, can I have it include the sidebar when issuing a command:

$ make html

and not include it issuing a command:

$ make htmlhelp

without altering code? Maybe add something in the layout.html.

Eelpout answered 13/11, 2017 at 6:17 Comment(0)
P
2

First of all, it is poor form to ask two questions in one post. Next time, create a separate question.

For your first question, I am not sure what the option collapse_navigation actually does, but its name implies that it does what you seek. The default value is False, so toggle it to True and see what happens. See other Read the Docs theme configuration options.

For your second question, there are at least two methods.

You can use the -D option of sphinx-build and override settings in your conf.py.

You can have multiple conf.py files (named as you see fit), and use the -c option to select the appropriate file for the output you want.

Procreate answered 13/11, 2017 at 6:38 Comment(3)
thanks Steve however collapse_navigation adds/removes the expand/collapse icon on the sidebar TOC at the top level, not what I'm after, appreciate the answer though.Eelpout
Bummer. In that case, you can create a new configuration option to show/hide the sidebar, and edit your theme templates accordingly. I'd point you to Sphinx and Jinja2 documentation for how to add conditional logic.Procreate
Bummer indeed, ended up as you say, adding conditional logic around the navigation in the theme templates, stripping it out: {% if 'htmlhelp' not in builder %}Eelpout
I
10

In the alabaster theme, I was able to remove the TOC/sidebar by adding the following to my conf.py file:

html_theme_options = {
    # Disable showing the sidebar. Defaults to 'false'
    'nosidebar': True,
}

I tested this in the sphinx_rtd_theme and it did not work. However, I add this as an answer here as it might be helpful for others trying to remove the sidebar in other themes (as was the case for me).

Immunity answered 8/11, 2018 at 16:52 Comment(0)
P
2

First of all, it is poor form to ask two questions in one post. Next time, create a separate question.

For your first question, I am not sure what the option collapse_navigation actually does, but its name implies that it does what you seek. The default value is False, so toggle it to True and see what happens. See other Read the Docs theme configuration options.

For your second question, there are at least two methods.

You can use the -D option of sphinx-build and override settings in your conf.py.

You can have multiple conf.py files (named as you see fit), and use the -c option to select the appropriate file for the output you want.

Procreate answered 13/11, 2017 at 6:38 Comment(3)
thanks Steve however collapse_navigation adds/removes the expand/collapse icon on the sidebar TOC at the top level, not what I'm after, appreciate the answer though.Eelpout
Bummer. In that case, you can create a new configuration option to show/hide the sidebar, and edit your theme templates accordingly. I'd point you to Sphinx and Jinja2 documentation for how to add conditional logic.Procreate
Bummer indeed, ended up as you say, adding conditional logic around the navigation in the theme templates, stripping it out: {% if 'htmlhelp' not in builder %}Eelpout
L
2

For building matlab documentation (which I believe is similar to HTMLHelp), I found that it is possible to hide the side-bar using a additional CSS:

.wy-nav-side {
  display: none;
}

.wy-nav-content-wrap {
  margin-left: 0;
}

Then in the conf.py file I added the CSS file:

html_static_path = ['_static']

html_css_files = [
    'css/matlabdoc.css',
]

This doesn't remove the side-bar, but at least it hides it. Might help.

Looking through the RTD theme, it might also be possible to remove the side-bar by changing the search.html and localtoc.html default files in conf.py by setting them with html_sidebars = {}.

Lodestone answered 14/10, 2019 at 8:2 Comment(1)
in modern sphinx, custom css is added like this: [code] # Custom css def setup(app): app.add_stylesheet('theme_overrides.css') [code]Theca

© 2022 - 2024 — McMap. All rights reserved.