Install LaTeX-OCR recognition tool on M1
date
Feb 25, 2023
slug
install-latex-ocr-on-apple-silicon-m1
status
Published
summary
tags
Engineering
AI
Data Analysis
Python
Productivity
type
Post
LaTeX-OCR is a well-known, open-source, and free OCR recognition tool that is widely used as an alternative to Mathpix.
However, due to compatibility issues with cross-platform modules such as pytorch and qt, installing this tool on an
arm64
host requires certain operations.Solution
- Install compiled qt library through brew
- Install pytorch through conda
Steps in details
pip install "pix2tex[gui]"
the module
brew install pyqt@5
the GUI dependency
sudo cp -r /opt/homebrew/Cellar/pyqt@5/5.15.7_2/lib/python3.9/site-packages/* /Users/rey/miniconda3/lib/python3.9/site-packages/
* since you cannot find a compatible version on the official forge of pip or conda
pip install pynput screeninfo
required by the package
conda install pytorch torchvision
conda will try to install a better version of pytorch on arm 64
Usage
- Start
python -m pix2tex latexocr
- Screenshot the LaTeX image to be recognized to the clipboard
- Wait for the terminal to display the recognized text, and the LaTeX text has been automatically copied to the clipboard.
Recognition effect
For the chained probability formula in the Stanford CS324 Large Language Model lecture notes:
Recognized as LaTeX code:
{\\mathbf{p}}(\\mathbf{x}*{1,\\mathrm{L}})=\\mathbf{p}(\\mathbf{x}*{1})\\mathbf{p}(\\mathbf{x}*{2}\\mid\\mathbf{x}*{1})\\mathbf{p}(\\mathbf{x}*{3}\\mid\\mathbf{x}*{1},\\mathbf{x}*{2})\\cdots\\mathbf{p}(\\mathbf{x}*{\\mathrm{L}}\\mid\\mathbf{x}*{1,\\mathrm{L}-1})=\\prod*{\\mathrm{i=1}}^{\\mathrm{L}}\\mathbf{p}(\\mathbf{x}*{\\mathrm{i}}\\mid\\mathbf{x}*{1,\\mathrm{i,t-1}).
Rendered equivalent to:
You can see that there are some small errors, but it can save a lot of time.
Reference
[1] Related issue: https://github.com/lukas-blecher/LaTeX-OCR/issues/234
[2] Official installation tutorial: https://github.com/lukas-blecher/LaTeX-OCR