book/tools/scripts/content/README_INDEX_PLACEMENT.md
The check_index_placement.py script validates that LaTeX \index{} commands are properly placed in QMD files. When \index{} appears on the same line as structural elements (headings, callouts, divs), it breaks Quarto rendering.
### Heading {#id}\index{Topic!subtopic}
\index{Topic!subtopic}::: {.callout-warning}
::: {.callout-note} \index{Topic!subtopic}
### Heading {#id}
\index{Topic!subtopic}Content starts here...
::: {.callout-warning}
\index{Topic!subtopic}Content starts here...
# Check single file
python check_index_placement.py file.qmd
# Check multiple files
python check_index_placement.py file1.qmd file2.qmd
# Check directory recursively
python check_index_placement.py -d book/quarto/contents/vol1/
# Quiet mode (summary only)
python check_index_placement.py -d book/quarto/contents/ --quiet
Automatically runs via pre-commit:
# Run all checks
pre-commit run --all-files
# Run only this check
pre-commit run book-check-index-placement --all-files
\index{} must not appear on same line as # ## ### #### headings\index{} must not appear on same line as ::: {.callout-...}\index{} must not appear directly before or after :::\index{} inside code blocks (...) are ignored (false positives)\index{} inside figure captions (fig-cap="...") are allowed0: No issues found1: Issues foundThe script:
~~~) under the problematic \index{}.pre-commit-config.yamlbook-check-index-placement