# Printing special characters and latex using python script for geometrical diagram labeling

I am trying to create figures such as this:

Or this:

This clearly requires text to be linked to objects. In addition, there is a large requirement of special characters which would most easily be handled if latex could be used to render the font used to make the text object.

I have found the following links which point me towards a direction:

SE python script text

Latex python text

However, the latex solution does not appear to work for me. I am unable to find the settings php file they claim is installed under the root folder in my ubunutu desktop, and windows is unclear as to where this file may be.

The second, perhaps minor requirement is that I would like to do this using a python script, such that the figure can be recreated easily without the ble der file, and some text performs all of the required steps.

• would you need this to be dynamic? ie, if you annotate a graph, the text stays rotates towards the view/camera ... not just a single overlay to be used as a final composite step on top of a render. – zeffii Oct 29 '15 at 10:03
• I would like it to be dynamic if possible. That way if you would like to distort the object in any fashion - such as moving the 2D image into the 3rd dimension - the labels will follow the portion of the object with which they are associated. – chase Oct 29 '15 at 14:14
• Unfortunately the is no LaTeX mode for the TextEditor to spit out Mathematical notation. Best and least work I can think of is still quite involved (calling nodejs from python to render latex as svg files and importing those). Then there's the dynamic update part which is a bit easier would be custom script until you get enough examples to think about writing a module for reuse... I totally understand why you might want this btw, and have experimented with similar myself. -- but I'm not aware of any ready made solutions. – zeffii Oct 29 '15 at 14:24
• blender isn't matplotlib, but it could definitely approach the same feature set if enough people cared out loud. – zeffii Oct 29 '15 at 14:26
• :( OK. I did see that special characters can be put in with chr() in python here: blender.stackexchange.com/questions/4801/… Is there a way to do greek letters like that? I have been searching for a table that would map the desired letter to the number required, but idk if it exists. – chase Oct 29 '15 at 14:54

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.