Skip to content

Fix bug where only the first math expression on a line was being spoken/brailled#18526

Merged
seanbudd merged 9 commits into
nvaccess:masterfrom
NSoiffer:bug18386
Jul 23, 2025
Merged

Fix bug where only the first math expression on a line was being spoken/brailled#18526
seanbudd merged 9 commits into
nvaccess:masterfrom
NSoiffer:bug18386

Conversation

@NSoiffer

@NSoiffer NSoiffer commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Link to issue number:

This fixes #18386

Summary of the issue:

If there is more than one math expression on a line, only the first math expression is spoken/brailled. Any text or math after that is dropped.

Description of user facing changes:

Now the full line is read/brailled.

Description of developer facing changes:

None

Description of development approach:

The bug was in wordDocument.py. There was/is special code to avoid saying both the MathML and word's speech for the math. However that code seemed to assume that there was only one piece of math per line and did a single (large) deletion after looping through what was on the line.

The code now correctly deletes only Word's math speech string. It does this in the loop. Because deletion is done on the array as we are looping, the code has to be careful to make sure the index into the array tracks where we are after the deletion.

Testing strategy:

I created a sample Word doc. This doc has three expressions on the line to better test the problem. Before the change, everything after the first expression was dropped. Now the entire line is read, including all the math and the text around the math.

Known issues with pull request:

I accidentally created the branch from another bug fix. I did a git revert and should have pulled out the other commits, but I still see the commits mentioned. On the other hand, only two changed files are listed, and those have the appropriate changes.

Note: this is a pull request against master. However, this is a pretty bad bug that was reported elsewhere before finally being reported here. I strongly suggest this goes into 2025.2.beta. I have tried to build the beta, but it isn't working for me, so I can't test the fix there.

Update: I forgot to mention that I left in the original code that does a "level check": every controlStart bumps the level and every controlEnd end decreases the level. The code records the level of the controlStart of math and only does deletion of content if the controlEnd of the math matches that level. I don't believe this is needed, but I don't know why it was part of the original code and perhaps there are cases where it is needed. @michaelDCurran wrote the original code: do you remember why you did that (four years ago)?

Code Review Checklist:

  • Documentation:
    • Change log entry
    • User Documentation
    • Developer / Technical Documentation
    • Context sensitive help for GUI changes
  • Testing:
    • Unit tests
    • System (end to end) tests
    • Manual testing
  • UX of all users considered:
    • Speech
    • Braille
    • Low Vision
    • Different web browsers
    • Localization in other languages / culture than English
  • API is compatible with existing add-ons.
  • API is compatible with existing add-ons.
  • Security precautions taken.

@coderabbitai summary

NSoiffer added 7 commits July 19, 2025 14:32
…ce`. It isn't used in speech (although maybe it should trigger a pause if wide), but it is used in some braille notations as a signal that this is a "fill in the blank" space.

I also added the elementary math attributes used in MathPlayer. Neither MathCAT nor Access8Math currently support the elementary math notations, but it is on the list of things to implement for MathCAT.

Note: potentially this could go into the beta, but I can't get the beta to build on my machine so I can't test the fix there.
…n a line, everything after the first expression is not spoken/brailled. This includes text along with math.

This has been reported in a few contexts:
* MathCAT: daisy/MathCATForPython#44
* DAISY: daisy/math-a11y#24

The problem lies in code that tries to delete Word's speech. Both the MathML and Word's speech are exposed. The code to recognize this and delete Word's speech was buggy. In particular, it seemed to assume that there was a most one equation on a line. The deletion of Word's math was outside of the loop, so basically everything after the start was deleted. The `controlEnd` command actually pointed to the last MathML on the line, but the speech code only spoke the `controlStart` part, so that bug never showed up.

The fix cleans up the logic and deletes Word's math when it comes to the matching end of the opening MathML.
…pe()`"

Based this branch on the wrong branch

This reverts commit 6f88d5e.
…on `mspace`. It isn't used in speech (although maybe it should trigger a pause if wide), but it is used in some braille notations as a signal that this is a "fill in the blank" space."

This branch was based on the wrong branch

This reverts commit 6a6a2a8.
@NSoiffer NSoiffer requested a review from a team as a code owner July 22, 2025 01:19
@NSoiffer NSoiffer requested a review from SaschaCowley July 22, 2025 01:19
Comment thread user_docs/en/changes.md Outdated
@seanbudd seanbudd changed the title Fix bug18386: only the first math expression on a line was being spoken/brailled Fix bug where only the first math expression on a line was being spoken/brailled Jul 22, 2025
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
@michaelDCurran

Copy link
Copy Markdown
Member

@NSoiffer the level checks are just to ensure that the control starts and ends stay completely balanced. We can never completely guarantee that MS word doesn't expose something completely silly like math in math, though I admit that is very unlikely.

@michaelDCurran michaelDCurran left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for debugging this. Good fix.

@seanbudd seanbudd merged commit e03b7c6 into nvaccess:master Jul 23, 2025
20 checks passed
@SaschaCowley SaschaCowley added this to the 2025.3 milestone Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NVDA skips content between multiple inline Office Math expressions during keyboard navigation

4 participants