Add ability to read math in PDF documents#17276
Conversation
…e Reader: support alternative text on formulas in PDFs (nvaccess#16067)") This change doesn't allow MathML in formula tags. That was ok before, but now pdftex puts out MathML in an associated file and FoxIt reader makes it the content of a formula tag. Adobe is generally on board with this idea but hasn't implemented handling of associated files yet. Currently Adobe Reader does not know about Associated Files. So the contents are the alternative text. This is handled by making it an `mtext` element. Note: if the alt text is LaTeX, then it has lots of "punctuation" such as `{` and `\`. This typically would _not_ be read by NVDA. MathCAT currently passes this along unchanged to NVDA, but I have marked this as a bug and will have MathCAT produce speech that won't be discarded, so the experience will be an improved one over just speaking the alt text.
|
This sounds so beautiful! |
|
@NSoiffer Just curious, is this new support part of the base |
|
As for "change log entry", add a new item in It looks like NV Access might need to manually start CI for this PR. Be sure that existing unit and system tests pass. |
This is separate, although it does include support for the amsmath package. It is a project that has been worked on for 4(?) years, funded by Adobe that is nearing completion of phase V (their last listed phase). Here is a relatively recent paper on their work. It (currently) requires adding some metadata at the start of the file: The first part of the metadata will be required as it states some important things that go into PDF's metadata. I suspect the "testphase" part will not be required at some point in the future. More info about the project is on their web page and also in their repo (it is a little out of date -- a month ago or so they started automatically generating MathML from TeX). |
|
@codeofdusk: thanks. I've added something to the userDoc file. As for testing, the only code that I changed is PDF related. As far as I can find, there are no tests for PDF files. Because the code does COM calls, I don't see a way to do Unit tests. I don't know how to do PDF system tests because one needs a PDF processor running (AdobeReader, Foxit Reader, ...). The need for a PDF processor probably makes system testing hard (impossible?). If someone can tell me how to do some tests, I'll add some. Otherwise, I think the checklist is complete. |
|
Having not heard any suggestions about how I could do testing, I've checked the box off. That means there are no tasks left. I think this is ready for review. |
Added info about PDF processors that support this.
See test results for failed build of commit b6a64ad505 |
SaschaCowley
left a comment
There was a problem hiding this comment.
Thanks @NSoiffer. Just a few small documentation requests.
|
To be honest I wouldn't be opposed to documenting some technical details on how to use this feature in the user guide. Even if they look somewhat professional. |
Also, make a comment a bit clearer.
Co-authored-by: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com>
Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Co-authored-by: Luke Davis <8139760+XLTechie@users.noreply.github.com>
|
GitHub says that @SaschaCowley requested updates. I must be missing something -- as far as I can see there are no unresolved requests. Can someone clarify for me what is not resolved? Thanks. |
This is just because I have not yet submitted an approving review. My apologies for the delay, I've been off sick for the last four days. |
See test results for failed build of commit b46a1cde7a |
Blocked by #17984 Summary of the issue: In #17276, NVDA now treats the value of formular nodes in Adobe Acrobat as mathml, with out any real validation. In PDF 2.0 documents, this is no doubt an okay assumption, but for PDF 1.7 documents generated by Microsoft Word, this is now causing Microsoft word generated math speech alternative text to be processed by mathCAT, resulting in broken or junk navigation, as Microsoft Word is exposing its math speech text as the value of the node. However, at the same time Microsoft has also introduced a new custom mathml attribute it is exposing on formula nodes in PDFs generated from Microsoft Word, that contains real mathMl which is suitable for MathCAT. NVDA should make use of this new custom attribute if it exists. Description of user facing changes In Adobe Acrobat, NVDA can now read and interact with Math equations in PDF documents generated by Microsoft word. Description of development approach AcrobatNode NVDAObject's mathml property: first try and fetch Microsoft Office's custom mathMl custom attribute if it exists. Otherwise fallback to using the node's value or descendants.
### Link to issue number: Fixes #18133 ### Summary of the issue: In #17276, support was added for alt text in a formula (a fallback when MathML is not detected) by wrapping the alt text inside of MathML's mtext tag. That text might have `<` and `&` characters which should be "escaped" but were not. The PDF support was added to 2025.1 beta. The fix is trivial: `<` -> `<` and `&` -> `&` (in that order). In #18133 I said that the punctuation was not being spoken, but it turns out that MathCAT actually does convert the punctuation in strings, so LaTeX is spoken sensibly (but it is still hard to understand when read quickly). ### Description of user facing changes In Adobe Acrobat, NVDA now properly reads alt text inside of Formula tags when no MathML is present (in various forms). ### Description of development approach Simple string `replace()` calls to do the substitutions. ### Testing strategy: I opened the test file [alt.pdf](https://github.com/user-attachments/files/20325821/alt.pdf) and listened what it said. I checked that in the speech viewer. ### Known issues with pull request: None ### Code Review Checklist: - [ ] Documentation: - Change log entry - User Documentation - Developer / Technical Documentation - Context sensitive help for GUI changes - [x] Testing: - Unit tests - System (end to end) tests - Manual testing - [x] UX of all users considered: - Speech - Braille - Low Vision - Different web browsers - Localization in other languages / culture than English - [x] API is compatible with existing add-ons. - [x] Security precautions taken. <!-- Please keep the following --> @coderabbitai summary --------- Co-authored-by: Sascha Cowley <16543535+SaschaCowley@users.noreply.github.com> Co-authored-by: Sean Budd <seanbudd123@gmail.com>
Link to issue number:
Fixes #9288
Summary of the issue:
PDF 2.0 added Associated Files (AF). It also describes a method for Formula tags to make use of AF that contain MathML. The LaTeX Project (the group that maintains LaTeX) has released an update to LaTeX that uses this technique. Hence, there will soon be a large body of PDF documents generated from LaTeX (pdflatex and lualatex) that contain MathML.
In conjunction with Foxit and an informal agreement with someone at Adobe, we agreed on a method to expose the MathML in an AF without a change to the PDF accessibility interface: the Formula tag gets role=Math (in windows, ROLE_SYSTEM_EQUATION) and the contents of tag is the MathML.
Note: this does not change the legality of the previous method of fully tagging the PDF math with children elements pointing to subexpressions in the PDF. However, that method has proved difficult to implement for PDF generators. This method seems to be much simpler and hence will be used.
The latest release of Foxit contains the support of AF with MathML. So far, Adobe has not made a change but with Foxit and NVDA supporting this, there will be more of an impetuses to do so. According to the Foxit implementer, it only took 1-2 days to implement.
Description of user facing changes
The math in documents will be spoken and brailled just as it is done for HTML documents. It will also be navigable. This should work with any of the MathML add-ons.
Description of development approach
Support required only about 3 lines to be added to the AdobeAcobat.py file. I changed a few more lines to add debug warnings when various COM interfaces were not found.
There was a commit in January 2024 that wiped out the MathML support in PDF in favor of alt text. This was in the .cpp file that is part of this PR. This PR mostly reverts that change. Alt text is still supported via the creation of a MathML
<mtext>element. Potentially, this is a better solution because sometimes the alt text is LaTeX and LaTeX contains lots of punctuation characters that are not spoken by NVDA by default. Pushing this to the Math handler gives them the ability to override this behavior and speak all the characters. Currently MathCAT just passes themtextcontent directly to NVDA, but I will look into making it smarter about that.Because Adobe Reader currently does not handle AFs, the alt text will get read if a formula has both an AF and alt text.
Testing strategy:
Here are two PDF files for testing:
Known issues with pull request:
None
Code Review Checklist:
I need some guidance on what to do, if anything, about "change log entry" and unit or system tests.
@coderabbitai summary