Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX: \titleformat last argument in sphinx.sty should be bracketed, not braced (and is anyhow not needed) #8788

Closed
jfbu opened this issue Jan 30, 2021 · 0 comments · Fixed by #8789

Comments

@jfbu
Copy link
Contributor

jfbu commented Jan 30, 2021

Describe the bug
This is a prehistoric bug which gets back as far as I can tell to bd50766

The \titleformat from titlesec has only 5 mandatory arguments, the last one is optional and should be bracketed. But our style file uses:

% Augment the sectioning commands used to get our own font family in place,
% and reset some internal data items (\titleformat from titlesec package)
\titleformat{\section}{\Large\py@HeaderFamily}%
{\py@TitleColor\thesection}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\subsection}{\large\py@HeaderFamily}%
{\py@TitleColor\thesubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\subsubsection}{\py@HeaderFamily}%
{\py@TitleColor\thesubsubsection}{0.5em}{\py@TitleColor}{\py@NormalColor}
% By default paragraphs (and subsubsections) will not be numbered because
% sphinxmanual.cls and sphinxhowto.cls set secnumdepth to 2
\titleformat{\paragraph}{\py@HeaderFamily}%
{\py@TitleColor\theparagraph}{0.5em}{\py@TitleColor}{\py@NormalColor}
\titleformat{\subparagraph}{\py@HeaderFamily}%
{\py@TitleColor\thesubparagraph}{0.5em}{\py@TitleColor}{\py@NormalColor}

As a result the macro \py@NormalColor is executed during the PDF build already during loading of package sphinx.sty. As its definition is \color{black} this causes no harm and got undetected.

I hit against the error while refactoring the LaTeX style files, and accidentally moved definition of \py@NormalColor to after it is used in \titleformat.

I was surprised by an undefined control sequence error on pdf build. Indeed TeX is a macro expansion language so at first I did not understand why \py@NormalColor was expanded (at a time it is undefined). Turns out it should have been

...[\py@NormalColor]

As it is braced, \titleformat leaves it in the token input stream and it gets executed. Which causes no harm when it has a definition such as \color{black} as done in sphinx.sty on an earlier line.

To Reproduce
Well, this does not cause a build error, and as all is internal to sphinx.sty loading one can not force one, but it is wrong nevertheless.

Expected behavior
Use \titleformat according to documentation

We see that we don't need that \py@NormalColor anyhow as it got executed at the wrong time...

  • Sphinx version: all...
  • Sphinx extensions: [e.g. sphinx.ext.autodoc, recommonmark]
  • Extra tools: TeXLive
@jfbu jfbu added this to the 3.5.0 milestone Jan 30, 2021
jfbu added a commit to jfbu/sphinx that referenced this issue Jan 30, 2021
The {\py@NormalColor} was wrong it should have been [\py@NormalColor].

It got executed by latex during document preamble and never got
integrated as part of the heading...

Closes: sphinx-doc#8788
jfbu added a commit to jfbu/sphinx that referenced this issue Jan 30, 2021
The {\py@NormalColor} was wrong it should have been [\py@NormalColor].

It got executed by latex during document preamble and never got
integrated as part of the heading...

Closes: sphinx-doc#8788
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant