LaTeX type rendering with pygame - python

I am trying to read text with LaTeX formatting and render it using pygame. I am a novice to pygame and any help will be appreciated.
I looked into Glyph package. The problem is that I would have to rewrite all my .txt files in Glyph formatting for them to be useful. If I try and define macros I would essentially have to build a LaTeX translator. Both these options don't seem very practical considering the number of text files I have.

You could render LaTeX via matplotlib and use these figures in PyGame as sprites.
http://matplotlib.sourceforge.net/users/usetex.html

Check out pylasem (yes, it says MathML rendering library, but it also supports a subset of Latex) or lasem itself via gobject-introspection.

Related

How to convert text to svg path in Python

I'm looking for a way to convert the text in a specific font face (.ttf or .otf) into an SVG path. So that I can continue working with the path in vector graphics as drawSvg (or a similar Library)
I don't know if you want it inside a python script only, but an alternative would be use cnc-text-tool or even text tool of Inkscape and then save it as plain SVG.

TXF fonts in windows?

Windows 10 has a preview function for TTF fonts.
Does there exist a program that does sorta the same but for TXF fonts?
Or does anyone know of a python function that can load such a font so I can write such a program myself, PILLOW didn't seem to support it.
Note: I tried showtxf.exe, but it show an image in too low resolution cannot really make out how the font looks.
I know I'm a little late. But I found this question AND the solution when searching for the answer to the same question.
txf seems to be a private file format for a bitmapped texture font which was/can be used in the context of GLUT by Marc Kilgard, an OpenGL toolkit in the late nineties.
The sourcecode and makefile are still around, along with a little instruction and a tool to generate(!) txf files from ttf font files. Also included is a txf-file viewer (source) where you are supposed to see all glyphs crammed into one coherent bitmap image, IIRC.
I found the source package at this link:
http://chateau-logic.com/content/ttf-txf-font-conversion

How to create a layout for use with pisa (xhtml2pdf)?

I'm creating PDFs using pisa. The layouts I'm trying to convert to PDF have some absolute positioning which seems to be ignored by pisa. I could work around this limitation by using tables for layout. Are there any alternatives to this?
One way to do absolute positioning is to use the xhtml2pdf specific #frame blocks. See the documentation for details.

PyQt: how to show math equations in QTextEdit

Merged with How to show math equations in QTextEdit?.
Does anyone know how to show mathematical equations in QTextEdit written in any format (TXT, MathML, MML, LaTeX, HTML, XML or anything) using only Python, that is without using 3rd party packages like Latex itself.? I tried to find the MathML Widget from Qt but it disappeared from their web site and I couldn't find it anywhere.
I'm not fussed about the equation source (either a string or a file). I just can't figure out how to show them nicely (the same way as they appear on a web page, e.g. http://en.wikipedia.org/wiki/MathML).
My QTextEdit currently gets an HTML string. I tried embedding the MathML example from that Wikipedia article, but it doesn't show it properly, it ignores all those MathML tags.
Will really appreciate your help. Thank you.

Is there any good python library for generating and rendering text in image format?

I'm developing a CMS like application where the user should be able to create the menu the way he wants. Ideally, each menu object wouldn't be a text with a background but rather an image of the text. I envision this in either of these 2 ways:
a) By rendering a font in a/several image file/s with every letter and a script that given a word would give me either the sequence of images to string together or a single image file with the combination of all letters. I understand this could be done manually, but I feel there's probably a library to help with this.
b) With some kind of imaging library that would be able to render text with several blending effects such as gradient color, shadows, glow, etc. While I believe this one's a bit harder, maybe there's something that suits this need.
Any tips on any library that does this or anything similar?
Thanks in advance!
Bruno
We are using Imagemagick.
http://www.imagemagick.org/Usage/text/#attributes
This will render a simple button with text:
convert -background white -fill dodgerblue -font Candice -strokewidth 2 -stroke blue -undercolor lightblue -size 165x70 -gravity center label:Anthony label_color.gif
Wrapping this into a Python module is straight forward.
Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.
The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.
(it does use PIL underneath)
Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)
Check out pycairo, bindings for the cairo rendering package. It can render text as well as graphics.
Well, with modern CSS techniques, the issue of nonmatching client-side fonts is less of a problem these days. Still there's demand for text-to-image tools.
PIL is often given as the answer to this question, but personally, I would give a good, hard look at pythonmagick as well. Pick the one that works best for you.
Actually the pygtk also has a pango renderer, as well.

Categories