Extract text from .docx files with support for inserted equations
Project description
docxlatex
A python library for extracting text from .docx files with LaTeX support
Influenced by python-docx and python-docx2txt. This project aims to expand the above libraries' functionality by allowing you to extract the equations in a .docx file and converts them to valid LaTeX, primarily for use with MathJax.
docxlatex DOES NOT convert the entire .docx file to a LaTeX source file.
Installation
Install using pip
pip install docxlatex
Usage
Import the Document
class from docxlatex
from docxlatex import Document
Create a Document
object, giving it the path to the .docx file, and call the get_text()
method
doc = Document("path/to/document")
text = doc.get_text()
You can also set some settings on the Document
object to customize behaviour, like setting the delimiters that will go before and after an equation,
and flags to extract header and footer text.
doc.get_header_text = True # False by default
doc.get_footer_text = True # False by default
doc.inline_delimiter = "%" # "$" by default
doc.block_delimiter = "%%" # "$$" by default
Limitation
docxlatex currently requires all the mathematical equations in the .docx document to be converted into linear format to extract successfully. I am adding support for equations in the professional format right now. Soon you will be able to use it without having to use this workaround, but for now, open the .docx file in Word, click on any equation, click on the right context menu > All - linear.
TODOs
- Extract all images present in the file and return them as file-like objects
- Add support for equations in professional formatting
- Clean up equations in linear format that do not directly convert to valid LaTeX
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for docxlatex-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cd4056a071748422b3aef556614cc25821c43946eea1e3282b18ef70496fb71 |
|
MD5 | f57e2bd98f7495c06a983a2bc790f834 |
|
BLAKE2b-256 | d1b2404b4280f8fa42bf87182fe4040a7db5a1fbb00c5f289da369c49e7eda1d |