Trying to do something similar, I found a path similar to but different from user877329's answer. There's also a link to some code that takes tex files and produces svgs.
You can create a tex file, convert it to a dvi file, and convert that to an svg, which blender can import via bpy.ops.import_curve.svg()
. The result will be a collection of curve objects rather than text objects, so you'll have to do any text-related styling from the tex file itself, but if you're working with scripts, that might be easier anyway.
As a starting point for doing this in python, I used functions defined around line 300 of this github file (related to quite a nice math animation YT channel, incidentally). The functions themselves just pass commands to other utilities that do the actual work, but they show a process that could be used to get from tex to svg. tex_to_svg()
is the core function, from which you can follow the flow to other functions as you make sense of things and adapt to your needs.
The needed utilities are pdfTex (for tex->dvi) and dvisvgm (for dvi->svg).