Replies: 1 comment
-
I have set up a font baker with stb_truetype and stb_rect_pack which loads the glyphs from the OpenType math table, and got a few otf fonts that have the math table. I'm trying to do a simple exercise: render a square root symbol whose size can grow vertically and horizontally (thus it will be made of several glyphs that make the corresponding parts). Because I don't like to reinvent the wheel, I googled for stb_truetype used for math glyphs, but got no results. Then I asked ChatGPT, and it pointed me to a supposedly blog series that explained how to render math with stb_truetype... but I feel I got ChatGPT in "creative mode" because that blog series doesn't seem to exist. Then it even told me about a tutorial here: "https://github.com/nothings/stb/blob/master/docs/stb_truetype_math_rendering.md", which doesn't exist either. It's funny when it invents things just to impress you. Back to the point, has anybody seen some code that renders with stb_truetype math symbols made of several parts? (square roots, parentheses, integrals, etc) |
Beta Was this translation helpful? Give feedback.
-
I know the issue for requesting new libs is closed, but do you know of any relatively small C code that I could use for getting the coordinates of the rectangles of all glyphs in a math formula, like, for example
\frac{x_{pt} + a^{2}}{sqrt{b^{3}+\frac{a}{b}}
, so that I can then use stb_truetype with stb_rect_pack for rendering it? I know, I know, I wrote it in LaTeX, and that would require a parser, but defining the formula directly in C structs would be equally fine for my purposes.I have done a lot of web searches for this over the years, because some of my C programs rely on the user installing a whole LaTeX distribution just for the sake of nice math expressions output, while my ideal solution would be to display maths without such a huge dependency. And, yes, I found some possibilities, but none of them can be labeled as "small C code": In Python, you have Matplotlib; in iOS and Mac, you have iOSMath, which is ObjectiveC but heavily dependent on Apple Frameworks, so it's not easily portable; in Javascript, you have lots of stuff because of MathJax and related technologies, but embedding a Javascript interpreter in your C program just for this is even more overkill than using a system-installed LaTeX distribution...
A few months ago, I found MicroTeX, which is perhaps the closest fit I found so far, but for me it has the problem of not only being C++, but C++17, and requiring linking with the standard C++ library, a dependency I'd like to avoid in my programs.
I suppose I'm not the only one who has wished to render math from C programs, so before I decide myself to either port MicroTeX to C, or to use troff instead, or to write my own math typesetting code, I have to ask if anybody here knows a solution I didn't think of.
By the way, if you don't have a solution, but you can point me to a concise and easy to follow description of a complete layout algorithm for math formulas, just give me the URL: Implementing it from scratch might be quicker than porting MicroTeX or adapting other code.
Beta Was this translation helpful? Give feedback.
All reactions