plot icon indicating copy to clipboard operation
plot copied to clipboard

Feature request: Superscript/subscript support in text strings

Open ctessum opened this issue 9 years ago • 7 comments

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.

ctessum avatar Oct 05 '15 20:10 ctessum

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 avatar Oct 05 '15 23:10 eaburns

@eaburns, I was thinking similar things - this is probably related to @vdobler's CSS proposal.

kortschak avatar Oct 05 '15 23:10 kortschak

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.

ctessum avatar Oct 06 '15 00:10 ctessum

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.

eaburns avatar Oct 06 '15 10:10 eaburns

Sorry, I'm on my phone: s/find it right/doing it right/

eaburns avatar Oct 06 '15 10:10 eaburns

this could be addressed w/ https://github.com/gonum/plot/pull/616

sbinet avatar May 23 '20 16:05 sbinet

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).

Screenshot from 2022-01-05 16-44-59

Edit Just noticed the commits which reference this issue: any chance of using LaTeX to do superscripts?

soypat avatar Jan 05 '22 19:01 soypat