r/CodingHelp • u/colnelali • 24d ago
[Python] How do I extract mathematical language accurately from a pdf using python
Tried alot, can't get to any solution. Special characters or diamond question marks appear etc but the accurate and understandable text doesn't. I'm looking for a library or a method which can address this, extract complex characters e.g. set notations or special characters in maths and fractions etc etc
if anybody can help,
thanks alot
APPRECIATE THAT
5
Upvotes
•
u/AutoModerator 24d ago
Thank you for posting on r/CodingHelp!
Please check our Wiki for answers, guides, and FAQs: https://coding-help.vercel.app
Our Wiki is open source - if you would like to contribute, create a pull request via GitHub! https://github.com/DudeThatsErin/CodingHelp
We are accepting moderator applications: https://forms.fillout.com/t/ua41TU57DGus
We also have a Discord server: https://discord.gg/geQEUBm
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/gofuckadick 24d ago
For mathematical notation, you can try looking into tools like these:
One thing worth keeping in mind is that PDFs don't necessarily store equations as structured mathematical expressions. Fractions, superscripts, and special symbols may be stored as separately positioned characters or glyphs, sometimes without proper Unicode mappings.
If you're getting replacement characters (
�) or other garbage, it could be a font encoding issue rather than a problem with the extraction library itself. Some PDFs use custom font encodings without proper Unicode mappings, so even though the characters display correctly, extracting them as text doesn't work.In cases like that, a math-aware OCR tool like Marker or Mathpix may give you better results, even if the PDF isn't scanned, since OCR can recognize the visible mathematical notation rather than relying on the PDF's underlying character encoding.
1
u/atamicbomb 23d ago
How is the PDF encoded? If it’s just images, you will need some kind of image recognition and it won’t be perfect.
A PDF is a binary file and I imagine you’re getting gibberish by having Python open it as a text file.