vega / vega

A visualization grammar.
https://vega.github.io/vega
BSD 3-Clause "New" or "Revised" License
11.14k stars 1.5k forks source link

Support for Superscript and Subscript text #1289

Open malramsay64 opened 6 years ago

malramsay64 commented 6 years ago

While complete support for LaTeX text in #898 is difficult to implement, I was wondering if support for just super/sub scripted characters is simpler to implement. Many of the characters required for mathematical expression are available through Unicode characters, except for super and subscript characters which don't even cover the lowercase latin alphabet.

I am primarily interested if there might be an alternate (simpler) method of implementing this that doesn't involve LaTeX.

jheer commented 6 years ago

I agree that it would be nice to support this, and it is certainly easier to achieve than general LaTeX support. However, this would still require custom support, changing Vega's text mark from a single string that can be drawn with one rendering call (or SVG element) to a multi-component setup involving alternative text baselines, appropriate spacing calculation, and also bounds calculation across the various parts. Plus, we'd need to determine an appropriate syntax with suitable escaping (e.g., to render text that would otherwise indicate super or sub-script).

This feature is not part of our current planning. That said, if someone is potentially interested in implementing this, I'm happy to help discuss and provide guidance. A good starting point would be to familiarize oneself with the text mark handling in vega-scenegraph: https://github.com/vega/vega-scenegraph/blob/master/src/marks/text.js

mattijn commented 6 years ago

To define certain text as super- and subscript in the vega specification might be nice indeed, but there is already a certain support for super and subscript, which might be sufficient for your need. I made this spec a while ago and it shows the capability of super and subscript

super_subscript
tmori3y2 commented 4 years ago

I investigated whether it was possible to incorporate JsonML notation of svg tspan, which is WaveDrom's approach, in the title and text of vega.

https://wavedrom.com/

In WaveDrom, rich text using tspan can be embedded in the header and footer.

https://observablehq.com/@drom/wavedrom

WaveDrom seems to use packages called tspan and onml for this process, so I created a demo.

https://observablehq.com/@tmori3y2/tspan-demo

tmori3y2 commented 4 years ago

I agree with the use of MathJax or KaTex as suggested by #898.

The reason for presenting comments and demos was because I was interested in the question: “What json format is better for math notation?”

The answer I derived from the demo is that inline html particles should not be used for security, and svg's jsonML is not good.