Feature Creep 2026, 35 - LaTeX Extractor

I haven't been writing code for private stuff recently, because I knew I would have to clean up my OS and was dreading the back-up. Now that I've done that, and I can fetch everything I would want to keep from git repos (a practice that I have always struggled to keep up with), I should really get back to it. Or rather, start doing it properly. Either way, this is take two.

I wrote a script to get my latex snippets for the physics/math study notes I take, before they go into the upload for the website. At present, I have to identify each of the LaTeX snippets and write them into an inputfile for the script to read. Since I will probably always have to do some copy/pasting, not the least, because the website builder is a fussy piece of software that doesn't even have hotkey bindings for inserting new sections, I would at least like the handling of my own script to be as smooth as possible. Since I write the notes in markdown, I don't have direct access to the text in a way that would make it easily identifiable or convenient to command-line. That means I will stick to the copy/pasting into an inputfile as well. I do, however, want to add two features this time around:

  1. Argparsing the filenames involved with set defaults. This one is just good practice, but at the time I just wanted it to be a quick and dirty solution. This won't take long in its basic form and I don't mind throwing it into this post.
  2. Making it so the script can filter LaTeX snippets from the entire markdown text on its own. That way I can simply copy/paste the entire thing and don't need to scan the text with my own eyes.

The first part is fairly easy, and a standard bit of code.

import argparse as argp

parser = argp.ArgumentParser(
    prog='Quick LaTeX',
    description='LaTeX .svg automation')
parser.add_argument('-i', '--inputfile', default="input.txt")
parser.add_argument('-o', '--output_dir', default="out")

args = parser.parse_args()

the rest is minor changes in the code which I won't go over. The second part is writing a parser of my own, which I'm decently practiced at, but is still always a matter of needing to think a little bit.

snippets = []

with open(args.inputfile, 'r') as inputfile:
  con = inputfile.read().split("\$")
  snippets = [con[i] for i in range(1, len(con), 2)]

for s in snippets:
  s = "\\begin{align}" + s + "\\end{align}" if not "begin{align}" in s else s
Next
Next

Feature Creep 2026, 12 - Bookle (Title WIP) - Selector