hbaromega
hbaromega

Reputation: 2374

Loading latex package in Python (particularly for variants of a symbol/letter)

Is it possible to load a Latex package (like using \usepackage) inside a python code? For example, I want to generate a variant font of the Greek letter \tau.

Detexify suggests loading upgreek package in Latex and then using \uptau for the symbol.

If it is not possible, what could be an alternative way?

Upvotes: 0

Views: 590

Answers (2)

Roland Smith
Roland Smith

Reputation: 43523

Modern TeX engines support fonts in TrueType (ttf) and OpenType (otf) format.

Using the Python bindings (example) to the cairo and pango libraries, you should be able to use these fonts.

Alternatively, you could use freetype-py. This will load characters from fonts as bitmaps.

Which one works best for your purpose is hard to say without further information on what you want to do with the fonts. If you want to output small amoumts of text in PDF or SVG format, cairo would be the way to go.

To the best of my knowledge, neither Python (nor cairo) can deal with MetaFont fonts.

A third way would be for your script to output (La)TeX code, and let the TeX engine render it. This would be my choice if you had to render a large amount of text because TeX can then deal with things like formatting, line breaking hyphenation and other typesetting related issues.

Upvotes: 0

Ari Cooper-Davis
Ari Cooper-Davis

Reputation: 3515

What do you want to do with those characters?

As far as I'm aware python won't natively support this, as it's not able to print those characters to the shell. It only natively supports unicode. There are some greek characters available.

If you want to display them then matplotlib might be a good place to start.

Upvotes: 1

Related Questions