File: html.rst

package info (click to toggle)
mathjax-docs 2.7+20171212-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,100 kB
  • sloc: sh: 22; python: 19; makefile: 8
file content (142 lines) | stat: -rw-r--r-- 4,450 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
.. _api-html:

***********************
The MathJax.HTML Object
***********************

The ``MathJax.HTML`` object provides routines for creating HTML
elements and adding them to the page, and in particular, it contains
the code that processes MathJax's :ref:`HTML snippets <html-snippets>`
and turns them into actual DOM objects.  It also implements the
methods used to manage the cookies used by MathJax.


Properties
==========

.. describe:: Cookie.prefix: "mjx"

    The prefix used for names of cookies stored by MathJax.

.. describe:: Cookie.expires: 365

    The expiration time (in days) for cookies created by MathJax.


Methods
=======

.. method:: Element(type[,attributes[,contents]])

    Creates a DOM element of the given type.  If `attributes` is
    non-``null``, it is an object that contains `key:value` pairs of
    attributes to set for the newly created element.  If `contents` is
    non-``null``, it is an :ref:`HTML snippet <html-snippets>` that
    describes the contents to create for the element.  For example

    .. code-block:: javascript

        var div = MathJax.HTML.Element(
	  "div",
	  {id: "MathDiv", style:{border:"1px solid", padding:"5px"}},
	  ["Here is math: \\(x+1\\)",["br"],"and a display $$x+1\\over x-1$$"]
	);

    :Parameters:
        - **type** --- node type to be created
        - **attributes** --- object specifying attributes to set
        - **contents** --- HTML snippet representing contents of node
    :Returns: the DOM element created    

.. method:: addElement(parent,type[,attributes[,content]])

    Creates a DOM element and appends it to the `parent` node
    provided.  It is equivalent to

    .. code-block:: javascript

        parent.appendChild(MathJax.HTML.Element(type,attributes,content))

    :Parameters:
        - **parent** --- the node where the element will be added
        - **attributes** --- object specifying attributes to set
        - **contents** --- HTML snippet representing contents of node
    :Returns: the DOM element created    

.. method:: TextNode(text)

    Creates a DOM text node with the given text as its content.

    :Parameters:
        - **text** --- the text for the node
    :Returns: the new text node

.. method:: addText(parent,text)

    Creates a DOM text node with the given text and appends it to the
    `parent` node.

    :Parameters:
        - **parent** --- the node where the text will be added
        - **text** --- the text for the new node
    :Returns: the new text node

.. method:: setScript(script,text)

    Sets the contents of the ``script`` element to be the given 
    ``text``, properly taking into account the browser limitations and 
    bugs.

    :Parameters:
        - **script** --- the script whose content is to be set
        - **text** --- the text that is to be the script's new content
    :Returns: ``null``

.. method:: getScript(script)

    Gets the contents of the ``script`` element, properly taking into
    account the browser limitations and bugs.

    :Parameters:
        - **script** --- the script whose content is to be retrieved
    :Returns: the text of the ``script``

.. describe:: Cookie.Set(name,data)

    Creates a MathJax cookie using the ``MathJax.HTML.Cookie.prefix``
    and the `name` as the cookie name, and the `key:value` pairs in
    the `data` object as the data for the cookie.  For example,

    .. code-block:: javascript

        MathJax.HTML.Cookie.Set("test",{x:42, y:"It Works!"});

    will create a cookie named "mjx.test" that stores the values of
    ``x`` and ``y`` provided in the `data` object.  This data can be
    retrieved using the :meth:`MathJax.HTML.Cookie.Get()` method
    discussed below.

    :Parameters:
        - **name** --- the name that identifies the cookie
        - **data** --- object containing the data to store in the cookie
    :Returns: ``null``

.. describe:: Cookie.Get(name[,obj])

    Looks up the data for the cookie named `name` and merges the data
    into the given `obj` object, or returns a new object containing
    the data.  For instance, given the cookie stored by the example
    above, 

    .. code-block:: javascript

        var data = MathJax.HTML.Cookie.Get("test");

    would set ``data`` to ``{x:42, y:"It Works!"}``, while

    .. code-block:: javascript

        var data = {x:10, z:"Safe"};
	MathJax.HTML.Cookie.Get("test",data);

    would leave ``data`` as ``{x:42, y:"It Works!", z:"Safe"}``.