[Python] GUI for inserting TeX format into PowerPoint with 2 clicks [PowerPoint]


Can you type in the button menu to create slide materials that make heavy use of mathematical formulas? is what I think. However, trying to use TeX with PowerPoint takes a lot of wasted effort and is troublesome.

Let's solve such a problem ** by making a very simple tool **. (Only compatible with Windows)

What was made



from urllib.parse import quote
from urllib.request import urlopen
import os
import tkinter
from tkinter import ttk
import pyperclip as ppc
import win32com.client
app = None
ppt = None
T = False

def setup():
    global app, ppt, T
    app = win32com.client.GetObject(Class="PowerPoint.Application")
        ppt = app.ActivePresentation
        if nop.get():
            ).TextFrame.TextRange.Text = "Ⓣ"
            T = True
            T = False
        return True
        ppt = None
        return False

def isOpen():
        return True
        return False

def insertTeX():
    global index, texs
    math = tex.get("1.0", "end -1c")
    if not math or not isOpen():
    if not T or not ppt or app != win32com.client.GetObject(
        if not setup(): return
    if nop.get():
        ).TextFrame.TextRange.Text = " ".join(math.splitlines())
        with urlopen(
        ) as svg:
            with open(
                    os.path.dirname(os.path.abspath(__file__)) + r"\tmp.svg",
                    "wb") as f:
            os.path.dirname(os.path.abspath(__file__)) + r"\tmp.svg", False,
            True, 0, 0)
        os.remove(os.path.dirname(os.path.abspath(__file__)) + r"\tmp.svg")
    if not texs or texs[-1] != math:
        index += 1

def setTeX():
    tex.delete("1.0", "end -1c")
    tex.insert("1.0", ppc.paste())

def prev():
    global index
    if texs:
        index = max(index - 1, 0)
        tex.delete("1.0", "end -1c")
        tex.insert("1.0", texs[index])

def next_():
    global index
    if texs:
        index = min(index + 1, len(texs) - 1)
        tex.delete("1.0", "end -1c")
        tex.insert("1.0", texs[index])

main_win = tkinter.Tk()
main_win.minsize(main_win.winfo_width(), 95)

main_frm = ttk.Frame(main_win)
main_frm.grid(column=0, row=0, sticky=tkinter.NSEW, padx=5, pady=10)

index = -1
texs = []
tex = tkinter.Text(main_frm)
paste_btn = ttk.Button(main_frm, text="paste", command=setTeX)
insert_btn = ttk.Button(main_frm, text="Insert", command=insertTeX)
prev_btn = ttk.Button(main_frm, text="∧", command=prev, width=2)
next_btn = ttk.Button(main_frm, text="∨", command=next_, width=2)
nop = tkinter.IntVar()
rb1 = ttk.Radiobutton(main_frm, text='Formula', value=1, variable=nop)
rb2 = ttk.Radiobutton(main_frm, text='image', value=0, variable=nop)

tex.grid(column=0, row=0, sticky='nsew', rowspan=10, columnspan=10, padx=5)
paste_btn.grid(column=11, row=8, columnspan=2)
insert_btn.grid(column=11, row=9, columnspan=2)
prev_btn.grid(column=10, row=7)
next_btn.grid(column=10, row=9)
rb1.grid(column=11, row=7, sticky=tkinter.SE)
rb2.grid(column=12, row=7, sticky=tkinter.SE)

main_win.columnconfigure(0, weight=1)
main_win.rowconfigure(0, weight=1)
main_frm.columnconfigure(1, weight=1)
main_frm.rowconfigure(1, weight=1)
main_win.attributes("-topmost", True)

How to use

-Enter TeX format formula in the text box -Select whether to insert as a PowerPoint formula or to insert as an image ・ Click the insert button


Desmos When you copy a formula, it is in TeX format, so it is convenient to enter it in Desmos and copy → insert (rather it) Made for).

Recommended Posts

[Python] GUI for inserting TeX format into PowerPoint with 2 clicks [PowerPoint]
INSERT into MySQL with Python [For beginners]
Automatically format Python code into PEP8-compliant code with Emacs
Note for formatting numbers with python format function
Automatically paste images into PowerPoint materials with python + α
Summary of tools for operating Windows GUI with Python
[GUI with Python] PyQt5-Layout management-
Stylish technique for pasting CSV data into Excel with Python
Format json with Vim (with python)
[GUI with Python] PyQt5 -Preparation-
String format with Python% operator
[GUI with Python] PyQt5 -Paint-
[GUI with Python] PyQt5 -Widget II-
Let's make a GUI with python.
Getting Started with Python for PHPer-Classes
[GUI with Python] PyQt5-The first step-
[GUI with Python] PyQt5-Drag and drop-
[GUI with Python] PyQt5 -Custom Widget-
Getting Started with Python for PHPer-Functions
[Python] Format when to_csv with pandas
Edit Slide (PowerPoint for Google) with Python (Low-cost RPA case with Google API and Python)
Easy keyword extraction with TermExtract for Python
Creating a simple PowerPoint file with Python
WEB scraping with Python (for personal notes)
Manually ssh registration for coreserver with python
Use DeepL with python (for dissertation translation)
Memo to ask for KPI with python
Amplify images for machine learning with python
Tips for dealing with binaries in Python
Put protocol buffers into sqlite with python
Tips for using python + caffe with TSUBAME
[Shakyo] Encounter with Python for machine learning
Process multiple lists with for in Python
Getting Started with Python for PHPer-Super Basics
Debug for mysql connection with python mysql.connector
[Python] Read images with OpenCV (for beginners)
WebApi creation with Python (CRUD creation) For beginners
Happy GUI construction with electron and python
Preparation for scraping with python [Chocolate flavor]
[For beginners] Try web scraping with Python
Divide each PowerPoint slide into a JPG file and output it with python