The MathJax Startup SequenceΒΆ
When you load MathJax.js into a web page, it configures itself and
immediately begins loading the components it needs. As MathJax starts
up, it uses its signaling mechanism
to indicate the actions that it is taking so that MathJax extensions
can tie into the initialization process, and so other applications
within the page can synchronize their actions with MathJax.
The startup process performs the following actions:
- It creates the
MathJaxvariable, and defines the following subsystems:MathJax.Object(object-oriented programming model)MathJax.Callback(callbacks, signals, and queues)MathJax.Ajax(file-loading and style-creation code)MathJax.HTML(support code for creating HTML elements)MathJax.Message(manages the menu line in the lower left)MathJax.Hub(the core MathJax functions)
- It then creates the base
MathJax.InputJax,MathJax.OutputJax, andMathJax.ElementJaxobjects.
- MathJax sets up the default configuration, and creates the signal objects used for the startup and hub actions.
- MathJax locates the
<script>tag that loaded theMathJax.jsfile, and sets theMathJax.Hub.config.rootvalue to reflect the location of the MathJax root directory.
- MathJax determines the browser being used and its version. It sets
up the
MathJax.Hub.Browserobject, which includes the browser name and version, plusisMac,isPC,isMSIE, and so on.
- MathJax set up the
MathJax.Hub.queuecommand queue, and populates it with the commands MathJax runs at startup. This includes creating theMathJax.Hub.Startup.onloadonload handler that is used to synchronize MathJax’s action with the loading of the page.
Once the MathJax.Hub.queue is created, the following actions are
pushed into the queue:
- Post the
Beginstartup signal
- Perform the configuration actions:
- Post the
Begin Configstartup signal - Load any configuration files specified via
config=as a script parameter - Execute the content of the
<script>that loaded MathJax, if it is not empty - Wait for the
delayStartupUntilcondition to be met, if one was specified - Execute any
text/x-mathjax-configscript blocks - load the files listed in the
MathJax.Hub.config.configarray - Post the
End Configstartup signal
- Post the
- Load the cookie values:
- Post the
Begin Cookiestartup signal - Load the menu cookie values
- Use the cookie to set the renderer, if it is set
- Post the
End Cookiestartup signal
- Post the
- Define the MathJax styles:
- Post the
Begin Stylesstartup signal - Load the stylesheet files from the
MathJax.Hub.config.stylesheetsarray - Define the stylesheet described in
MathJax.Hub.config.styles - Post the
End Stylesstartup signal
- Post the
- Initialize the Message system (the grey information box in the lower left)
- Load the jax configuration files:
- Post the
Begin Jaxstartup signal - Load the jax config files from the
MathJax.Hub.config.jaxarray- The jax will register themselves when they are loaded
- Post the
End Jaxstartup signal
- Post the
- Load the extension files:
- Post the
Begin Extensionsstartup signal - Load the files from the
MathJax.Hub.config.extensionsarray- Most extensions will post a
[name] ReadyorExtension [name] Readystartup message when they are loaded (where[name]is the name of the extension)
- Most extensions will post a
- Post the
End Extensionsstartup signal
- Post the
- Set the MathJax menu’s renderer value based on the jax that have been loaded
- Wait for the onload handler to fire (in MathJax v2.0 this can
occur on the
DOMContentLoadedevent rather than the page’sonloadevent, so processing of mathematics can start earlier)
- Set
MathJax.isReadytotrue
- Perform the typesetting pass (preprocessors and processors)
- Post the
Begin Typesetstartup signal - Post the
Begin PreProcesshub signal - Run the registered preprocessors
- Post the
End PreProcesshub signal - Clear the hub signal history
- Post the
Begin Processhub signal - Process the math script elements on the page
- There are a number of Hub signals generated during math
processing, including a signal that a
Mathaction is starting (with a parameter indicating what action that is),BeginandEnd Math Inputmessages, andBeginandEnd Math Outputsignals. - Each new math element generates a
New Mathhub signal with the math element’s ID
- There are a number of Hub signals generated during math
processing, including a signal that a
- Post the
End Processhub signal - Post the
End Typesetstartup signal
- Post the
- Jump to the location specified in the URL’s hash reference, if any.
- Initiate timers to load the zoom and menu code, if it hasn’t already been loading in the configuration (so it will be ready when the user needs it).
- Post the
Endstartup signal
The loading of the jax and extensions in steps 5 and 6 are now done in parallel, rather than sequentially. That is, all the jax and extensions are requested simultaneously, so they load concurrently. That means they can load in any order, and that the begin and end signals for the jax and extensions can be intermixed. (In general, you will get Begin Jax followed by Begin Extensions, but the order of End Jax and End Extensions will depend on the files being loaded.) Both 5 and 6 must complete, however, before 7 will be performed.
See the test/sample-signals.html file to see the signals in action.