Open ctessum opened 9 years ago
This will require some research. I think that it's more complex than simply drawing smaller characters that are either raised or lowered. With smallcaps, for example, fonts have entire separate glyph sets. Simply drawing smaller versions of normal capital letters is wrong and looks bad. I suspect that superscripts and subscripts are the same. If so, we should do them right.
@eaburns, I was thinking similar things - this is probably related to @vdobler's CSS proposal.
I think doing it right requires using fonts that include superscript and subscript glyphs. The unicode standard supports superscript and subscript for a small subset of characters (https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts). These characters will already work in the vg backends except pdf (which doesn't seem to support unicode). Some fonts include more characters but I don't know how common it is.
So I think the common strategy is to use the correct glyphs if available, and fall back to an adjustment of size, alignment, and (maybe) thickness if they are not available: https://en.wikipedia.org/wiki/Subscript_and_superscript#Desktop_publishing
It might make sense to implement the fallback first, because it doesn't require knowledge of the opentype standard and will be required anyway, and then implement the "professional" solution later.
My guess is that, if we implement the fallback first, we'll never go back and do it the correct way. That doesn't mean that we shouldn't. However, it would be nice if this was all in its own package (using vg to draw markdown or something), where someone was dedicated to maintaining it and find it right. Also, that way, the package could be used for more than just gonum/plot.
Sorry, I'm on my phone: s/find it right/doing it right/
this could be addressed w/ https://github.com/gonum/plot/pull/616
Pinging this issue in support of supporting superscript symbols. I need to label the units of the quantity I am plotting (mass flow in kilograms per second) and I find that the Superscript Minus: U+207B - , is not displaying properly (see attachment).
Edit Just noticed the commits which reference this issue: any chance of using LaTeX to do superscripts?
Useful for plots that include chemical names, variables, etc. (example: R2).
A possible way to implement this would be to support a subset of Markdown or HTML syntax (for subscript and superscript, and possibly but less importantly bold and italics). There already exist Go parsers for both, so the tricky part would be implementing the text sizing and offsetting in all of the vg backends.
A more powerful alternative would be to support Latex syntax, but I feel like the difficulty to usefulness ratio would be too high.