I think this is the wrong approach and will probably lead to problems in the long run. MathJax's support for CSS is limited, and this probably won't work in any but the HTML-CSS output, and not very well there. Since MathJax converts everything to MathML internally, a better solution would be to use MathML's mglyph tag to implement this, which is MathML's way of including images. Here is some code that adds an \img macro for inserting images into a MathJax expression. It takes 4 arguments: the URL for the image, the vertical alignment value, the width, and the height of the image. Any of the final there can be blank in order to use the default. WIth no vertical-align value, the image will sit on the baseline. With not width or height, the image will be its natural size. With one of the width or height specified, the image will be scaled to match that dimension while keeping the aspect ratio the same. If both are given, then image will be scaled to match both dimensions, without regard to the original aspect ratio.
<html>
<head>
<title>Add \img command</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
var TEX = MathJax.InputJax.TeX,
MML = MathJax.ElementJax.mml;
var CheckDimen = function (dimen) {
if (dimen === "" ||
dimen.match(/^\s*([-+]?(\.\d+|\d+(\.\d*)?))\s*(pt|em|ex|mu|px|mm|cm|in|pc)\s*$/))
return dimen.replace(/ /g,"");
TEX.Error("Bad dimension for image: "+dimen);
};
TEX.Definitions.macros.img = "myImage";
TEX.Parse.Augment({
myImage: function (name) {
var src = this.GetArgument(name),
valign = CheckDimen(this.GetArgument(name)),
width = CheckDimen(this.GetArgument(name)),
height = CheckDimen(this.GetArgument(name));
var def = {src:src};
if (valign) {def.valign = valign}
if (width) {def.width = width}
if (valign) {def.height = height}
this.Push(this.mmlToken(MML.mglyph().With(def)));
}
});
});
</script>
<script type="text/javascript" src="
http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
This is math with an image: \[x +
\img{
http://www.math.union.edu/~dpvc/math/courses/MTH015/JPG/Hyperboloids.jpg}{-2em}{}{4.5em}
+ y\]
</body>
</html>
To use this in your own site, take the first script tag an add it to your page just before the script that loads MathJax.js.
@pkra, perhaps this should be made into an extension for the contributed extensions repository?
Davide