Fix % comment-stripping inside verbatim-family environments - #270
Open
rohith500 wants to merge 2 commits into
Open
Fix % comment-stripping inside verbatim-family environments#270rohith500 wants to merge 2 commits into
rohith500 wants to merge 2 commits into
Conversation
…/lstlisting/minted)
_visible_tex_content() treated % as a LaTeX comment unconditionally, but
verbatim-family environments don't parse comments -- % is literal text
there. This silently hid TODOs, \label{}, and \cite{} inside code listings
from validate_tex_draft() and check_citation_bib_coherence(). Worse: once
the closing-tag match failed to pop the verbatim state, everything after
it in the document went dark too, not just the one line.
Verified via isolated repro and a live build_paper() run with a real
citation in the bib and a fake one hidden inside a listing.
📝 WalkthroughWalkthroughThe LaTeX validator now handles ChangesVerbatim-aware LaTeX validation
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Line 7: Update the changelog entry describing validate_tex_draft() so hidden
\label{} content is said to affect label-validation findings, not
blocker-severity checks. Preserve the existing description of empty and
duplicate labels as major-severity findings.
In `@src/gpd/core/paper_quality.py`:
- Around line 869-877: The environment scan currently includes tokens after a
verbatim opener, causing false nested environment findings. In
src/gpd/core/paper_quality.py#L869-L877, update the logic around
_visible_tex_line and begin_match to retain full stripped as scan_text but use
stripped[:begin_match.end()] as env_scan_text when an opener is found; update
tests/core/test_paper_quality.py#L917-L931 to assert the result contains only
("placeholder_marker", 4).
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 334f99c3-e80d-41bc-843f-1c458afbc56c
📒 Files selected for processing (4)
CHANGELOG.mdsrc/gpd/core/paper_quality.pytests/core/test_paper_quality.pytests/test_citation_coherence.py
…GELOG severity wording
<your one-line summary of what this does>
<paragraph: the begin-line bug CodeRabbit caught — text after a verbatim
opener on the same line was leaking into the env-balance view, so a
literal-lookalike \begin{lstlisting} appearing after a real
\begin{verbatim} on one line got treated as a genuine second open.
Same class of bug as the closing-side fix already in this PR, just
never mirrored to the opening side.>
<one line: CHANGELOG wording also corrected — \label{} findings are
major severity, not blocker, per CodeRabbit's note>
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.
What broke
_visible_tex_content()treats%as a comment character everywhere, but insideverbatim,lstlisting, andmintedenvironments,%is not a comment in real LaTeX — it's literal text. So a%inside a code listing was silently deleting everything after it from the manuscript text that gets checked for problems.Why it's worse than it looks
Once the code hits a real closing
\end{...}tag that it fails to recognize, the "I'm inside a listing" state never turns off — so every line for the rest of the document gets treated as a comment too, not just the one line. For example: a MATLAB code listing that uses%as its real comment character, containing something like\end{document}shown as sample text, would silently turn off citation and TODO checking for the entire rest of the paper.Fix
_visible_tex_content()now tracks whether it is currently inside a verbatim-family environment, line by line, and stops stripping%while inside one. A separate check used for\begin{}/\end{}balance tracking also ignores literal LaTeX-looking text shown as example code inside a listing, so it doesn't get mistaken for a real environment marker.Verification
\label{}and TODO markers were vanishing from the scanned text when placed inside a listingbuild_paper()with one real citation in the.bibfile and one fake citation hidden inside a code listing — before the fix, the fake citation was never flagged as unresolved; after the fix, it correctly isuv run pytest tests/ -q: 12,948 passed, 15 skipped, 0 failedpre-commit run --all-files: cleanChecklist
## vNEXT