Display Good-looking Math Formula in Android

前端 未结 6 732
無奈伤痛
無奈伤痛 2020-12-02 11:35

It is sad to see that science and math is never given enough attention in Android platform. Maybe this is an easy problem, but I\'m a total dude in javascript so I\

6条回答
  •  天命终不由人
    2020-12-02 11:52

    Instead of using javascript and javascript libraries to render the LaTeX client-side, why not do the following?

    1. Write a server-side function that takes some LaTeX string and produces an image file. You can do this with the "out of the box" standard LaTeX command line tool. (It seems like this is something you're capable of doing, and that the problem is in getting the rendering to take place client-side.)

    2. Create an endpoint on your web site/service that looks like the following:
      GET /latex?f={image format}&s={latex string}

    3. On your web pages, use a simple HTML tag to render your LaTeX. For example:

      will render the f(x)=x^2 equation as a JPEG.

    4. (optional) Create a simple server-side cache for (f,s) pairs so that you only render a particular LaTeX string on the first request ever made for that particular string (by any client). As a first prototype, you could just have a server directory in which you have files named {hash(s)}.{f}, where hash is just some hash function like SHA1.

    This relieves you from trying to make everything work client-side with javascript. And, I would argue (although some may disagree), that this is a lot cleaner. All you're sending to the client is:

    1. the HTML tag
    2. the actual image contents when the browser resolves the src attribute

    Very lightweight and fast!

提交回复
热议问题