Skip to content

WhatsApp bot that renders LaTeX equations into images and sends them back to the user

Notifications You must be signed in to change notification settings

totallynotdavid/BoTeX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BoTeX

CodeQL lint-and-testing

BoTeX is a WhatsApp bot that renders LaTeX equations into images. I created this project while learning Go, drawing inspiration from how matterbridge implements WhatsApp integration using the whatsmeow library. While it currently has a limited set of commands (!latex for rendering equations and !help for viewing available commands), it serves as a simple example of building a WhatsApp bot in Go.

Getting Started

Setting up BoTeX requires a few tools: Go for running the bot, TeX Live for rendering equations, and ImageMagick for image processing. Let's walk through the setup process.

First, you'll need Go installed (we're using version 1.24.5). If you don't have it already, here's how to get it running:

curl -OL https://go.dev/dl/go1.24.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.24.5.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profile

Note

These commands download the Go tarball, extract it to /usr/local, and add the Go binary directory to your PATH. You can check the installation with go version.

Next up is TeX Live, which handles the actual equation rendering. The installation takes a while, but it's straightforward:

sudo apt-get install perl
cd /tmp
curl -L -o install-tl-unx.tar.gz https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xzf install-tl-unx.tar.gz
cd install-tl-*
sudo perl ./install-tl --no-interaction
echo 'export PATH=$PATH:/usr/local/texlive/2024/bin/x86_64-linux' >> ~/.profile
source ~/.profile

Note

You may need to install LaTeX packages using tlmgr install <package>. For our purposes:

tlmgr install amsmath amsfonts physics standalone preview bm

Finally, let's get the bot up and running. You'll need some build tools and the bot code itself:

# Install required system packages
sudo apt-get install gcc build-essential imagemagick webp

# Get the bot (either clone with git or download ZIP from GitHub)
git clone https://github.com/totallynotdavid/BoTeX
cd BoTeX

# Run the bot
make dev # equivalent to `go run .`

Using the Bot

Once you've got everything installed, using the bot is simple. Run it with go run . and you'll see a QR code in your terminal - scan this with WhatsApp to link the bot. After that, you can start rendering equations by sending messages in this format:

!latex <your_equation>

For example, try these:

!latex x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

or

!latex \int_{a}^{b} f(x)\,dx = F(b) - F(a)

When things go wrong

If something's not working, it's usually one of three things:

  1. The installation didn't complete properly - run pdflatex --version and convert --version to check if TeX Live and ImageMagick are installed correctly.
  2. whatsmeow have known issues regarding some messages showing up only on WhatsApp web but not on a phone. If you're not seeing messages, try seeing if they show up on WhatsApp web1.
  3. The Go dependencies need updating - try go clean -modcache followed by go get -u.

If you're running into an issue that isn't solved by checking these, feel free to open an issue on GitHub. I'm always happy to help get things running smoothly.

This project is open source, so feel free to use it, modify it, or suggest improvements. Thanks to the teams behind whatsmeow and matterbridge for their excellent work that made this project possible!

Footnotes

  1. Update (2025-07-05): This issue appears to be fixed in the latest version of whatsmeow. If you're still encountering it, make sure you're using the most recent release of the library.

About

WhatsApp bot that renders LaTeX equations into images and sends them back to the user

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 3

  •  
  •  
  •