Let's say I have opened the following equation in Pages in its Equation Editor:
\mathrm{G(\mathit{z})} = \mathit{e}^{ln\,G(z)}
= \mathrm{exp}
\mathopen\bigg{(}\sum\limits_{k\,\ge{\,1}}\frac{S_kz^k}{k}
\mathclose\bigg{)} = \prod_{k\,\ge{\,1}} e^{S_kz^k/k}
and I copy it to the clipboard.
Here is that rendered equation image:

Here is the source to a Python3 script that gets the LaTeX syntax from the clipboard, prepends some other features to it, and then sends it off to a website that converts the LaTeX into an image (here a png) that it returns to be written in the same directory as the Python script was run.
#!/usr/bin/env python3
# reference: https://editor.codecogs.com/docs/4-LaTeX_rendering.php
# requires: pypy.org Requests library installed as: pip3 install -U requests
# There must be an intelligible LaTeX equation on the clipboard
# some of the code was sourced and tested from Google AI results
# Python 3.14.2 was installed from Python.org (/usr/local/bin/python3, /usr/local/bin/pip3)
# and tested on Sequoia 15.7.3
import subprocess
import requests
import urllib.parse
import sys
def get_clipboard_content():
try:
# Run the 'pbpaste' command and capture its output
process = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
stdout, stderr = process.communicate()
if process.returncode == 0:
return stdout.strip()
else:
print(f"Error executing pbpaste: {stderr}")
return None
except FileNotFoundError:
print("The 'pbpaste' command was not found. Are you sure you are on macOS?")
return None
except Exception as e:
print(f"An unexpected error occurred: {e}")
return None
def main():
content = get_clipboard_content()
if content is not None:
print("Content from clipboard:")
latex_source = r"\large\fg{40826D}\dpi{300}" + content
# print(f"{latex_source}")
else:
sys.exit("No LaTeX source on clipboard")
#latex_source = r"\large\fg{00FF3F}\dpi{300}\frac{x}{y^2} + \sqrt{z}"
encoded_latex = urllib.parse.quote(latex_source)
url = f"https://latex.codecogs.com/png.image?{encoded_latex}"
# Make the request and save the image
response = requests.get(url, auth=None)
if response.status_code == 200:
with open("equation.png", "wb") as f:
f.write(response.content)
print("Image saved as equation.png")
else:
print(f"Error: {response.status_code}")
if __name__ == '__main__':
sys.exit(main())
I named this Python3 source as latexsvc.py. From the Terminal:
chmod +x ./latexsvc.py
# open Pages equation object and copy its source to the clipboard
./latexsvc.py