Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to read math in PDF documents #17276

Merged
merged 21 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f816e6
Mostly revert commit #fbfcd14b5f14609fba7a919c67431a1912b0da51 ("Adob…
NSoiffer Oct 10, 2024
e923065
Pre-commit auto-fix
pre-commit-ci[bot] Oct 10, 2024
be541bd
Add MathML support in PDF change.
NSoiffer Oct 12, 2024
9588e13
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 12, 2024
11e2128
Pre-commit auto-fix
pre-commit-ci[bot] Oct 12, 2024
1485fdf
Apply suggestions from code review
seanbudd Oct 16, 2024
b95c078
Pre-commit auto-fix
pre-commit-ci[bot] Oct 16, 2024
0a62929
Clean up comments and log.debug statements
NSoiffer Oct 17, 2024
e626dae
Improve the change comment
NSoiffer Oct 17, 2024
62926e2
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 17, 2024
909423d
Made each sentence be on its own line as requested by @codeofdusk.
NSoiffer Oct 17, 2024
c6d85d6
Fix multiline debug "fix" -- actually tested the code this time...
NSoiffer Oct 17, 2024
a8c59f2
Pre-commit auto-fix
pre-commit-ci[bot] Oct 17, 2024
c2f6529
Update user_docs/en/changes.md
SaschaCowley Oct 17, 2024
ba3803a
Add documentation string.
NSoiffer Oct 19, 2024
b4a7a41
Merge branch 'SupportMathML' of github.com:NSoiffer/nvda into Support…
NSoiffer Oct 19, 2024
de5e89c
Update user_docs/en/changes.md
NSoiffer Oct 19, 2024
188119d
Merge branch 'master' into SupportMathML
NSoiffer Oct 19, 2024
c77a07e
Update user_docs/en/changes.md
NSoiffer Oct 22, 2024
6d92dc4
Update user_docs/en/changes.md
NSoiffer Oct 22, 2024
4edc60d
Update user_docs/en/changes.md
SaschaCowley Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions source/NVDAObjects/IAccessible/adobeAcrobat.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,36 @@ def _getNodeMathMl(self, node):
yield "</%s>" % tag

def _get_mathMl(self) -> str:
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
"""Return the MathML associated with a Formula tag"""
if self.pdDomNode is None:
log.debugWarning("_get_mathMl: self.pdDomNode is None!")
raise LookupError
# There could be other stuff before the math element. Ug.
mathMl = self.pdDomNode.GetValue()
log.debug(
f'\n_get_mathMl: math recognized: {mathMl.startswith("<math")}, child count={self.pdDomNode.GetChildCount()}',
f"\nname={self.pdDomNode.GetName()}\nvalue={self.pdDomNode.GetValue()}",
)
if log.isEnabledFor(log.DEBUG):
log.debug(
(
f"_get_mathMl: math recognized: {mathMl.startswith('<math')}, "
f"child count={self.pdDomNode.GetChildCount()},"
f"\n name='{self.pdDomNode.GetName()}', value='{mathMl}'"
),
)
# this test and the replacement doesn't work if someone uses a namespace tag (which they shouldn't, but..)
if mathMl.startswith("<math"):
return mathMl.replace('xmlns:mml="http://www.w3.org/1998/Math/MathML"', "")
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
# Alternative for tagging: all the sub expressions are tagged -- gather up the MathML
for childNum in range(self.pdDomNode.GetChildCount()):
try:
child = self.pdDomNode.GetChild(childNum).QueryInterface(IPDDomElement)
except COMError:
log.debugWarning(f"COMError trying to get childNum={childNum}")
continue
log.debug(f"\tget_mathMl: tag={child.GetTagName()}")
if log.isEnabledFor(log.DEBUG):
log.debug(f"\tget_mathMl: tag={child.GetTagName()}")
if child.GetTagName() == "math":
return "".join(self._getNodeMathMl(child))
# fall back to return the contents, which is hopefully to be alt text
log.debug("_get_mathMl: didn't find MathML -- returning value as mtext")
# fall back to return the contents, which is hopefully alt text
if log.isEnabledFor(log.DEBUG):
log.debug("_get_mathMl: didn't find MathML -- returning value as mtext")
return f"<math><mtext>{self.pdDomNode.GetValue()}</mtext></math>"


Expand Down
9 changes: 7 additions & 2 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
### New Features
SaschaCowley marked this conversation as resolved.
Show resolved Hide resolved

* Support for math in PDFs has been added.
This works for formulas that have MathML in an Associated File.
Tagged formulas are supported in newer versions of TeX/LaTeX (#9288, @NSoiffer)
This works for Formulas with associated MathML mark-up, such as some files generated by newer versions of TeX/LaTeX.
NSoiffer marked this conversation as resolved.
Show resolved Hide resolved
Currently this is only supported in Foxit Reader & Foxit Editor. (#9288, @NSoiffer)
* The volume of other applications can be adjusted by `NVDA+alt+pageUp` and `NVDA+alt+pageDown`. In order to use this feature, application volume adjuster needs to be enabled in Audio pane of NVDA settings. (#16052, @mltony)
* Added command to mute or unmute all other applications, assigned to `NVDA+alt+delete`.
In order to use this feature, the application volume adjuster needs to be enabled in the Audio category of NVDA settings. (#16052, @mltony)
* Commands to adjust the volume of other applications besides NVDA have been added.
To use this feature, "allow NVDA to control the volume of other applications" must be enabled in the audio settings panel. (#16052, @mltony, @codeofdusk)
* `NVDA+alt+pageUp`: Increase the volume of all other applications.
* `NVDA+alt+pageDown`: Decrease the volume of all other applications.
* `NVDA+alt+delete`: Mute the volume of all other applications.
* When editing in Microsoft PowerPoint text boxes, you can now move per sentence with `alt+upArrow`/`alt+downArrow`. (#17015, @LeonarddeR)
* In Mozilla Firefox, NVDA will report the highlighted text when a URL containing a text fragment is visited. (#16910, @jcsteh)
* NVDA can now report when a link destination points to the current page. (#141, @LeonarddeR, @nvdaes)
Expand Down