Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render images as MathJax #1266

Closed
ghost opened this issue Sep 15, 2015 · 16 comments
Closed

Render images as MathJax #1266

ghost opened this issue Sep 15, 2015 · 16 comments
Labels
Expected Behavior This is how MathJax works

Comments

@ghost
Copy link

ghost commented Sep 15, 2015

I'm looking for someone to kindly provide a userscript for this.

I've noticed that websites have latex in the alt text of their maths images, so I thought that it could be possible for someone to make a userscript that converts that latex to MathJax.

I really hate those blurry maths png images, that's why!

The advantage of such a userscript is that it would work on virtually almost all sorts of websites, instead of having to make a special userscript for every single website.

The only thing though is that if the alt text turns out to be not latex, then the unserscript should be able to understand that, and not break the page trying to convert an ordinary image into MathJax.

Thanks a lot! :)

@pkra
Copy link
Contributor

pkra commented Sep 16, 2015

Here's an old bookmarklet I once created for Wikipedia images. It should give you a good point to start. The trouble with Wikipedia (and other sites) are custom macros. Keep in mind that some sites like mathworld use ascii-like syntax (though not actual asciimath, it usually renders ok).

@pkra pkra added the Expected Behavior This is how MathJax works label Sep 16, 2015
@ghost
Copy link
Author

ghost commented Sep 16, 2015

Thanks.

@ghost
Copy link
Author

ghost commented Sep 16, 2015

Is it possible to make the default zoom 200%?

I hate having to set it for every website.

@dpvc
Copy link
Member

dpvc commented Sep 17, 2015

There is also a Greasemonkey script (the second one in that section) that does the same sort of thing, but that doesn't use jQuery (I worry about inserting jQuery into an arbitrary page, as it might interfere with the page's own copy of jQuery, especially if it is a different version of jQuery).

You could have the script add configuration that sets the zoom scaling to 200. Adding MathJax.Hub.Config({menuSettings:zoom:200}) would do it, I think.

@ghost
Copy link
Author

ghost commented Sep 17, 2015

I actually tried that script before and it didn't work.

@ghost
Copy link
Author

ghost commented Sep 17, 2015

Most websites have latex in the image alt, not as a<math> element, and the latter is what the userscript is trying to do.

@ghost
Copy link
Author

ghost commented Sep 17, 2015

I don't know how to make a proper userscript to convert image alts to latex.

It'd have to ignore non-latex image alts, and again, I have no idea how to do that.

@pkra
Copy link
Contributor

pkra commented Sep 17, 2015

It'd have to ignore non-latex image alts, and again, I have no idea how to do that.

Yes, that's a problem you can only work around with additional information (such as a specific class in the case of Wikipedia).

@dpvc
Copy link
Member

dpvc commented Sep 17, 2015

Most websites have latex in the image alt, not as a <math> element, and the latter is what the userscript is trying to do.

I think you may be looking at the wrong user script. There are two in that section, and it is the second one. That one looks for image tags and takes the TeX out of the alt attribute.

@ghost
Copy link
Author

ghost commented Sep 17, 2015

@dpvc I didn't look at the wrong one, I'm not that stupid bro.

I looked at specifically, this one, and it didn't work.

@ghost
Copy link
Author

ghost commented Sep 17, 2015

@pkra But most websites don't have a specific class. They just have an ordinary image alt.

If a userscript was made to convert that image alt to MathJax, then it would work on plenty of websites.

I just absolutely hate those pixelated, blurry, png images.

Sometimes they're even gifs, which makes things a lot worse.

@dpvc
Copy link
Member

dpvc commented Sep 17, 2015

I didn't look at the wrong one, I'm not that stupid bro.

Since you said the user script was trying to "do" <math> elements, I didn't see how you were looking at the right one, since the second one makes no mention of math elements in any way. It is looking at <img> tags and inserting the <script> tags that MathJax uses. There are no <math> tags involved.

The script tags are set to contain the LaTeX from the image alt attributes and the MIME type is set so that MathJax will process them as TeX. That sounds very close to what you are trying to do.

It is true that the user script is designed for use only on Wikipedia, so it looks for the images with className of "tex", which is how they were marked at the time the script was written (I haven't checked lately). The @include directive also is set so that the user script only runs on the English Wikipedia site. So you certainly will have to make modifications. It was only intended as a starting point, not a finished solution for you.

Also, "it didn't work" is not a very specific comment. You have not indicated what you tried, or in what way it failed, or what types of error message you may have gotten, or any real information at all. So I'm not sure what you expect from us.

If a userscript was made to convert that image alt to MathJax, then it would work on plenty of websites.

If the alt attribute is in (La)TeX form, then the script you link to should be easily modified to do what you ask. It already inserts the DOM elements needed by MathJax. It is only the className test that would need to be removed. Of course, if you are asking for a way to distinguish LaTeX alt attributes from other alt text, I do not know of a reasonable way to do that. If you have a means of doing that, by all means, go ahead and add that to the script.

@Herst
Copy link

Herst commented Sep 30, 2015

For you and anyone else who might be interested in such bookmarklets, have a look at: http://www.informatik-forum.at/showthread.php?t=107276 (site is German but the code should be pretty self-explanatory)
Unlike the other bookmarklet this here properly registers a PreProcessor.

@ghost
Copy link
Author

ghost commented Oct 3, 2015

@Herst, thanks.

It doesn't work on any website, though, :(

@Herst
Copy link

Herst commented Oct 5, 2015

Of course not, this one is very specific, I meant that you can use it as a basis for your own bookmarklet.

@ghost
Copy link
Author

ghost commented Oct 5, 2015

@Herst Okay, then. I'll see what I can do with it.

@pkra pkra closed this as completed Oct 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Expected Behavior This is how MathJax works
Projects
None yet
Development

No branches or pull requests

3 participants