Skip to content

Generate LaTeX equations from images in your clipboard or vault

License

Notifications You must be signed in to change notification settings

lucasvanmol/obsidian-latex-ocr

Repository files navigation

Latex OCR for Obsidian

GitHub release (with filter) Obsidian Downloads Buy Me A Coffee

Generate Latex equations from images and screenshots inside your vault.

Features

  • Paste LaTeX equations directly into your notes using an image from your clipboard with a custom command (bind it to a hotkey like Ctrl+Alt+V if you use it often!).
  • Transform images in your vault to LaTeX equations by choosing a new "Generate Latex" option in their context menu.
  • Use either the HuggingFace inference API or run locally

Using Inference API

By default, this plugin uses the HuggingFace inference API. Here's how you get your API key:

  • Create an account or login at https://huggingface.co
  • Create a read access token in your Hugging Face profile settings. If you already have other access tokens I recommend creating one specifically for this plugin.
  • After enabling the plugin in Obsidian, head to the Latex OCR settings tab, and input the API key you generated.

Limitations

  • The inference API is a free service by huggingface, and as such it requires some time to be provisioned. Subsequent requests should be a lot faster.
  • If you would be interested in a low-cost subscription-based service that would get rid of this annoying waiting period, please react to the related issue here. I will consider building it if there is enough demand to pay for the server costs.

Run Locally

Alternatively, you can run the model locally. This requires installing an accompanying python package. Install it using pip (or, preferably pipx):

pip install latex-ocr-server

You can check if it is installed by running

python -m latex_ocr_server --version

Configuration

Open Obsidian and navigate to the Community Plugins section and enable the plugin. Then head to the LatexOCR settings tab, enable "Use local model" and configure it.

settings

You will first need to set the python path that the plugin will use to run the model in the LatexOCR settings. You can then check if it's working using the button below it. Once this is done, press "(Re)start Server".

Note that the first time you do this, the model needs to be downloaded from huggingface, and is around ~1.4 GB. You can check the status of this download in the LatexOCR settings tab by pressing "Check Status".

The status bar at the bottom will indicate the status of the server.

Status Meaning
LatexOCR ✅ server online
LatexOCR ⚙️ server loading
LatexOCR 🌐 downloading model
LatexOCR ❌ server unreachable

GPU support

You can check if GPU support is working by running:

python -m latex_ocr_server info --gpu-available

If you want GPU support, follow the instructions at https://pytorch.org/get-started/locally/ to install pytorch with CUDA. Note you may need to uninstall torch first. torchvision and torchaudio is not required.

Beta testing with BRAT

You can use BRAT to keep up to date with beta updates for this plugin. You'll get more frequent updates & improvements, but things may be slightly more likely to break.

Attribution

Massive thanks to NormXU for training and releasing the model.