
Interactivity on LaTeX2Web part 2
Interaction with the user may go beyond what the browser offers locally.
As a generality, the LaTeX2Web user interacts with the server in the following way :
- the user clicks on a link, or a menu item
- the browser sends a request to the server
- the server handles the request and returns a web page. For instance, if a LaTeX2Web user clicks on a link that points to a document, the link actually sends a request with parameters to the server. The ID of the document is included in the request parameters.
The server looks in its database for a document that matches the query, and, if all goes well, a web page is returned to the browser, which renders it.
A more interesting workflow is used when the user clicks on a LaTeX reference. There are two possibilities.
The reference exists inside the web page
In this usual case, the ID of the reference matches the ID of a LaTeX2Web object inside the web page. This is what happens if the document comes from vanilla LaTeX code.
Then the browser copies the content and displays it as close as possible to the reference caller. All of this happens locally with JavaScript code.
The reference does not exist inside the web page
Things get really interesting when the reference does not point to a local LaTeX2Web object. The JavaScript code that is in charge of rendering the reference then fails to find it within the web page.
What the code does next, is make a request to the server, which basically says :
Can you get me the content for this reference?
The server receives the reference info, which includes notably the ID of the document in the database. If the document exists, it parses the internal model that is attached to the document, in order to find a matching object reference.
If the server finds a match, it does essentially two things :
- it extracts the object from the document model
- it produces the HTML code that renders it, and returns the code to the browser
Meanwhile, a JavaScript process has been waiting for the server response. When the response arrives and is valid, the JavaScript code treats it as if it had found a reference within the web page and inserts it in the right location. The only difference with the nominal case is that the equations must be rendered by MathJax, because they were not rendered at page load.
Now, what happens if the reference content which has been fetched previously contains other references ?
Well, it actually has all the necessary info encoded in it to be able to render embedded references as well. Of special interest are classical LaTeX references that reside within the remote document... which you can also fetch and display locally.
This boils down to this: LaTeX2Web is able to manage site-wide references.
Note of interest : when some content is fetched from another document, a link to the original document is added to the reference content, mentioning the title and the authors.
Give me an example of the second case!
Actually, the usage of external references will be covered in future posts, but I can give you a simple application.
It turns out that LaTeX2Web is able to create the "digest" of a document on the fly. This is done by collecting from the document model all theorem-like objects and rendering the result into a web page. This is useful for courses with mathematical content, for instance.
What happens is that theorems can refer to content that lies outside these theorems. For instance, a theorem can refer to an equation that lies in the usual flow of the document.
Since cross-site references are managed, the reader will be able to see the said equation (which belongs to the main document) from the digest itself !