Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subscripts and superscripts in SVG

Tags:

svg

I am trying to display sub- and superscripts with SVG using the following code from this site

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
    <text x = "10" y = "25" font-size = "20">
        <tspan>
            e = mc 
            <tspan baseline-shift = "super">2</tspan>
        </tspan>
        <tspan x = "10" y = "60">
            T 
            <tspan baseline-shift = "sub">i+2</tspan>
            =T 
            <tspan baseline-shift = "sub">i</tspan>
            + T 
            <tspan baseline-shift = "sub">i+1</tspan>
        </tspan>
    </text>
</g>

but the sub/superscripts do not display in IE or Firefox. Is this unimplemented or is there another problem? [Are you able to see the subscripts displayed properly?]

like image 628
peter.murray.rust Avatar asked Sep 08 '12 16:09

peter.murray.rust


People also ask

What are superscripts and subscripts explain with examples?

Superscripts are characters set above the normal line of type (e.g., in 2ⁿᵈ) and subscripts are characters set below (e.g., in Cᵥₑₓ). There are many reasons to use them in charts — for example, in footnotes or for chemical and physical formulas.

How do you insert superscript and subscript?

To make text appear slightly above (superscript) or below (subscript) your regular text, you can use keyboard shortcuts. Select the character that you want to format. For superscript, press Ctrl, Shift, and the Plus sign (+) at the same time. For subscript, press Ctrl and the Equal sign (=) at the same time.

What are super and subscripts?

A superscript or subscript is a number, figure, symbol, or indicator that is smaller than the normal line of type and is set slightly above it (superscript) or below it (subscript).

What is superscript styling usually used for?

One of the common applications of superscript formatting in mathematical writing is to show an exponent, or a number to the power of another number. Examples include squaring (22 = 4) or cubing (53 = 125) a number.


1 Answers

Baseline-shift is not supported in IE9, IE10, and Firefox, see:

http://msdn.microsoft.com/en-us/library/gg558060(v=vs.85).aspx https://bugzilla.mozilla.org/show_bug.cgi?id=308338

If you're acually trying to display formulas, a better fit would be MathML embedded within SVG, see:

http://www.maths-informatique-jeux.com/international/mathml_with_other_standards/index.php

If you want a quickfix for the example you provided, you can emulate baseline-shift with dy...

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<g>
    <text x = "10" y = "25" font-size = "20">
        <tspan>
            e = mc 
            <tspan dy ="-10">2</tspan>
        </tspan>
        <tspan x = "10" y = "60">
            T 
            <tspan dy="10">i+2</tspan>
            <tspan dy="-10">=T </tspan>
            <tspan dy="10">i</tspan>
            <tspan dy="-10">+ T</tspan> 
            <tspan dy="10">i+1</tspan>
        </tspan>
    </text>
    </g>
</svg>

​http://jsfiddle.net/UQ5Dp/

like image 106
methodofaction Avatar answered Sep 24 '22 19:09

methodofaction