Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML/CSS layout number to the power of expression (a^x)

Tags:

html

css

I need to layout some math expressions in a web page, cant use latex or mathML, just plain HTML (not HTML5)

I have an expression to the power of a different expression, for example (a+b+sqrt(c))^(2x+b)

The second expression should be to the right of the first expression a bit smaller and above it.

Sound simple enough but I can't seem to get it right.

Any help is the styling and layout would be great, thanks.

like image 226
Aviran Avatar asked Oct 13 '12 18:10

Aviran


People also ask

How do you write a number to a power in HTML?

The <sup> tag defines superscript text. Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used for footnotes, like WWW.

How do you do to the power of 2 in HTML?

Superscript: The <sup> tag is used to add a superscript text to the HTML document. The <sup> tag defines the superscript text.

How do you superscript in CSS?

In HTML, there is the use of <sub> and <sup> tags to define the subscript and superscript text. The superscript text appears in a smaller font and the half character above the normal line. It is generally used to write mathematical equations (like x2 + y2 = r2), footnotes, and many more.

How do you put math symbols in HTML?

Many mathematical, technical, and currency symbols, are not present on a normal keyboard. To add such symbols to an HTML page, you can use the entity name or the entity number (a decimal or a hexadecimal reference) for the symbol.


2 Answers

HTML is rather limited when it comes to mathematical expressions. In principle, HTML specifications suggest that you use sup element for superscripts, so the sample expression would be

(<i>a</i> + <i>b</i> + √<i>c</i>)<sup>2<i>x</i> + <i>b</i></sup> 

However, the implementations of sup in browsers are inconsistent and generally poor (causing e.g. uneven line spacing), so it is pragmatically better to use the span element with a class instead:

(<i>a</i> + <i>b</i> + √<i>c</i>)<span class=sup>2<i>x</i> + <i>b</i></span> 

with CSS code like

.sup {   position: relative;   bottom: 1ex;    font-size: 80%; } 

Some reasons are explained on my page Math in HTML (and CSS). Also consider JavaScript-based libraries for pages containing complicated math expressions:

  • KaTeX
  • MathJax
  • jqMath

The sample expression is a borderline case; it would look mathematically more correct if the square root were represented using a square root symbol with vinculum and not just √c, and trying to construct a vinculum using HTML and CSS gets rather dirty, but otherwise it can be reasonably handled with HTML and CSS.

like image 139
Jukka K. Korpela Avatar answered Sep 18 '22 16:09

Jukka K. Korpela


HTML defines a <sup> tag for superscript. For example:

a<sup>x</sup> 

of which you can alter the margins and vertical alignment with CSS.

like image 36
icio Avatar answered Sep 19 '22 16:09

icio