Fix recursive \printindex causing blank/duplicate index sections in PDF build#319
Merged
Fix recursive \printindex causing blank/duplicate index sections in PDF build#319
Conversation
- Remove recursive \\renewcommand{\\printindex} from indices.rst that
caused runaway recursion and ~4000 blank pages of index output
- Replace with a simple \\printindex under '.. only:: latex'
- Add latex_elements['printindex'] = '' to conf.py to suppress
Sphinx's auto-appended index at end of PDF, preventing duplicate
index sections
Co-authored-by: briantoby <9433704+briantoby@users.noreply.github.com>
Agent-Logs-Url: https://github.com/AdvancedPhotonSource/GSAS-II/sessions/b201939b-1f9d-4150-ac96-e5a3be236dd6
Copilot
AI
changed the title
[WIP] Fix PDF index generation for larger developer manual
Fix recursive \printindex causing blank/duplicate index sections in PDF build
Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs/source/indices.rstcontained a self-referential\renewcommand{\printindex}that called itself recursively, producing two index sections in the PDF — one with ~2 blank pages and another with ~4000 blank pages.Changes
docs/source/indices.rst: Replace the recursive\renewcommandblock with a plain\printindexunder.. only:: latex:docs/source/conf.py: Add'printindex': ''tolatex_elementsto suppress Sphinx's automatic index insertion at the end of the document — preventing the second duplicate index section that Sphinx appends by default:HTML output is unaffected; the
.. only:: htmlblock inindices.rstis unchanged.Original prompt
Create a new PR in
AdvancedPhotonSource/GSAS-IIto fix PDF index generation for the larger developer manual (docs underdocs/source/).Context / current behavior:
40584678e4d10cf7ceda37e0f2865e1db2e1ebf2onmain,docs/source/indices.rstagain contains a recursive LaTeX redefinition of\printindex:docs/source/*) for now.Inputs (current files on main):
docs/source/index.rstincludesindices.rstin its main toctree.docs/source/indices.rstcurrently has the recursive\renewcommand{\printindex}{...\printindex...}block (bad).docs/source/conf.pycurrently does NOT setlatex_elements['printindex'](it was removed by revert PR Revert "Fix empty index in PDF docs for both developer and scripting manuals" #318).Goal:
\printindex.Required changes:
docs/source/indices.rst, remove the recursive\renewcommand{\printindex}{...}and replace with a simple explicit index print for LaTeX builds:.. only:: latexand.. raw:: latexwith a single\printindexline.docs/source/conf.py, setlatex_elements['printindex'] = ''with a comment explaining this suppresses Sphinx’s auto-added\printindexat end, so that the index is printed only whereindices.rstplaces it.\printindexinsertions underdocs/source/that would cause duplicate indices.genindexindocs/source/index.rstso LaTeX builder reliably generates the index. If this is added, keep it hidden so HTML navigation is unchanged.Validation:
make latexpdf(or RTD PDF build) results in one index section and does not explode in size.Out of scope:
docs/scripting/*in this PR.docs/environment.yml.Reference:
40584678e4d10cf7ceda37e0f2865e1db2e1ebf2.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please continue the work on #317 with PR #318 but note that the index is not being created correctly as noted at the end of the previous session
Assistant: I can’t continue yet because there’s a pending confirmation/authorization step from the previous session that has to be accepted (or rejected) before I’m able to apply any further changes to PR #318 or update the docs to fix the index-generation problem.
User: @copilot Dismissed Confirmation: Are you sure?
Assistant: Got it — that dismissed call would also have made the situation worse: setting
latex_elements['printindex']toTrueis not a valid/usable value for Sphinx (it must be a LaTeX string, and in GSAS-II we intentionally set it to''to prevent Sphinx from auto-inserting\\printindexat the end).User: I still would like to generate an index in the .pdf document. For now lets concentrate on the larger manual from the files in doc/source
Assistant: To get a non-empty index in the PDF for the larger manual (
docs/source/*), you want two things to be true at the same time:.idx/.indcontent viamakeindex/xindy) and populate them (this happens whengenindexis enabled and there are indexable terms).\printindex), and it must not be suppressed or accidentally turned into a no-op.Right now, on
main(commita6eb29bc...), you already have the right overall structure for #2:docs/source/index.rstincludesindices.rstin the toctree.docs/source/indices.rstincludes a.. only:: latexblock that does\printindex.docs/source/conf.pysetslatex_elements['printindex'] = ''which suppresses Sphinx’s automatic “print the index at the end of the PDF”, but still allows your explicit\printindexinsideindices.rstto control placement.So if the PDF index is still “not being created correctly”, the likely failure is #1: the index is being printed, but it contains no entries because
genindexisn’t being generated/populated for LaTeX, or because makeindex/xindy isn’t being run.What I recommend changing (docs/source only)
A) Explici...
This pull request was created from Copilot chat.
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.