Changelog
0.101.2 2024-11-15
\mathop{}
command.renderMathInElement()
some white space was occasionally
incorrectly removed.\rightarrow
instead of \rarr
in the virtual keyboard.MathfieldElement.fractionNavigationOrder
was not respected
when navigating in a fraction with the arrow keys.Changelog
0.101.1 2024-10-15
placeholder
attribute would not be displayed when the
mathfield was empty.Changelog
0.101.0 2024-07-17
mathVirtualKeyboard.actionKeycap
,
mathVirtualKeyboard.shiftKeycap
, mathVirtualKeyboard.backspaceKeycap
,
and mathVirtualKeyboard.tabKeycap
have been removed. Use the more general
mathVirtualKeyboard.setKeycap()
method to customize these keycaps, that
is mathVirtualKeyboard.setKeycap('[action]', {...})
etc...Macros can now be specified with renderMathInElement()
and renderMathInDocument()
using the macros
option. For example:
renderMathInElement(element, {macros: {RR: '\\mathbb{R}'}})
Performance improvements for pages with many mathfields. The initial rendering can be up to 2x as fast.
Some keycaps in the virtual keyboard can be customized without having to define an entire virtual keyboard layout.
The mathVirtualKeyboard.getKeycap()
give access to the definition of
special keycaps and mathVirtualKeyboard.setKeycap()
can be used to
change that definition.
The keycaps are one of these special shortcuts:
[left]
, [right]
, [up]
, [down]
, [return]
, [action]
,[space]
, [tab]
, [backspace]
, [shift]
,[undo]
, [redo]
, [foreground-color]
, [background-color]
,[hide-keyboard]
,[.]
, [,]
,[0]
, [1]
, [2]
, [3]
, [4]
,[5]
, [6]
, [7]
, [8]
, [9]
,[+]
, [-]
, [*]
, [/]
, [^]
, [_]
, [=]
, [.]
,[(]
, [)]
For example, to change the LaTeX inserted when the multiplication key is pressed use:
mathVirtualKeyboard.setKeycap('[*]', {latex: '\\times'});
es-419
), the context menu would
not be displayed.MathfieldElement.isFunction
handler is updated, re-render all
the mathfields on the page to take it into account.contextmenu
event any time the context menu is about to be
displayed. This allows the event to be canceled.alphabeticLayout
, the current keyboard would not
be updated in some cases.\lnot p
would serialize as \lnotp
.\mathbb{}
command were not styled
correctly.math-virtual-keyboard-command
event was not dispatched when a
mathfield was focused and a keycap was pressed.--keycap-glyph-size
--keycap-glyph-size-lg
--keycap-glyph-size-xl
beforeinput
event was canceled, the text would still
be inserted when using the physical keyboard.{\placeholder{}}
, the placeholder was not automatically selected.Changelog
0.100.0 2024-06-12
#2396 Pressing the arrow keys in the virtual keyboard would not move the selection in the mathfield and display a runtime error in the console.
#2395 Added a dispatchEvent
command which can be attached to a
custom keycap.
#2392 Pressing the backspace key after typing several digits would delete all the digits.
Its first argument is the name of the dispatched event, and the second
argument is an object with the detail
property, which is the data
associated with the event.
{
label: "✨",
command: "dispatchEvent('customEvent', {detail: 'some data'})"
}
To handle the event, add an event listener to the mathfield element:
mf.addEventListener('customEvent', (ev) => {
console.log(ev.detail);
});
Changelog
0.99.0 2024-06-10
The mf.offsetFromPoint()
method has been renamed mf.getOffsetFromPoint()
The mf.setCaretPoint()
method has been replaced with mf.position = mf.getOffsetFromPoint()
The mf.scriptDepth()
and mf.hitboxFromOffset()
methodds have been
replaced with mf.getElementInfo()
.
The getElementInfo()
method provides more information including any id
that may have been applied with \htmlId{}
.
It is useful from within a click
handler to get more information about the
element that was clicked, e.g.
mf.getElementInfo(mf.getOffsetFromPoint(ev.clientX, ev.clientY))
The info returned is an object with the following properties:
export type ElementInfo = {
/** The depth in the expression tree. 0 for top-level elements */
depth?: number;
/** The bounding box of the element */
bounds?: DOMRect;
/** id associated with this element or its ancestor, set with `\htmlId` or
`\cssId`
*/
id?: string;
/** HTML attributes associated with element or its ancestores, set with
* `\htmlData`
*/
data?: Record<string, string | undefined>;
/** The mode (math, text or LaTeX) */
mode?: ParseMode;
/** A LaTeX representation of the element */
latex?: string;
/** The style (color, weight, variant, etc...) of this element. */
style?: Style;
};
The way bold is handled in LaTeX is particularly confusing, reflecting limitations of the text rendering technology of the time.
Various attempts have been made over the years to improve the rendering of bold, but this has resulted in inconsistent behavior. Furthermore, various implementations of LaTeX and LaTeX-like systems have implemented bold in different ways.
This release introduces a more consistent and intuitive handling of bold, although it may result in different rendering of some formulas compared to some implementations of LaTeX.
The original bold command in LaTeX is \mathbf
. This command renders its
argument using a bold variant of the current font. However, only letters and
numbers can be rendered by this command. It does not affect symbols, operators,
or greek characters.
For example, \mathbf{a+b}
will render as 𝐚+𝐛
, with the a
and b
in bold,
but the +
in normal weight. Characters rendered by \mathbf
are rendered
upright, even if they would have been rendered as italic otherwise.
The \boldsymbol
command is an alternative to \mathbf
that affects more
characters, including Greek letters and symbols. It does not affect
the style of the characters, so they remain italic if they were italic before.
However, the inter-character spacing and italic correction may not be rendered correctly.
The \bm
command from the bm
package is a more modern alternative that
affects even more characters. It also preserves the style of the characters,
so they remain italic if they were italic before. The inter-character spacing
and italic correction are handled correctly.
The \bm
command is recommended over \boldsymbol
and \mathbf
. However,
it is not part of the standard LaTeX distribution, so it may not always be available.
When serializing to LaTeX, MathLive will now use \mathbf
when possible, and
fall back to \bm
when not. This should result in more consistent rendering
of bold text.
When parsing, MathLive will interpret both \mathbf
, \boldsymbol
and \bm
as
bold.
The bold style is now consistently inherited by sub-expressions.
Similarly, when applying a bold style using mf.applyStyle({weight: "bold"})
,
the bold attribute is applied to the entire selection, not just the letters
and numbers.
switch-mode
command has two optionals arguments, a prefix
and suffix. The prefix is inserted before the mode switch, and the suffix
after. The command was behaving incorrectly. It now behaves as expected.\frac{a}{b}
and pressing alt+shift+T
will convert the
selection to (a)/(b)
. Pressing alt+shift+T
again will convert it back to
\frac{a}{b}
.\href
The \href{url}{content}
command, a MathJax extension that allows a link
to be associated with some content, is now supported.
Clicking on the content will open the link. By default, the link is opened
in a new window, and only links with a HTTP, HTTPS or FILE protocol are
allowed. This can be controlled by the new MathfieldElement.openUrl
property. This property is a function with a single argument, the URL to
be opened, that is called when the content of the \href
command is clicked on.
Tooltip appearance
Added CSS variables to control the appearance of the toolip displayed with
\mathtip
and \texttip
:
--tooltip-border
--tooltip-color
--tooltip-background-color
--tooltip-box-shadow
--tooltip-border-radius
.The maxMatrixCols
property has been added that specifies the maximum number
of columns that a matrix may have. The default value is 10, which follows the
default value from the amsmath package. The property applies to all of
the matrix environments (matrix
, pmatrix
, bmatrix
, etc.). This property is
also accessible via the max-matrix-cols
attribute.
The virtual keyboard now supports variants for shifted-keys. This includes
support for Swedish specific characters such as å
, ä
, and ö
and their
uppercase variants.
Accept "true"
and "false"
as values for on/off attributes in the
<math-field>
element, for example <math-field smart-fence="true">
.
Added a target
property (a MathfieldElement
) to the onMenuSelect
arguments.
#2337 Added an option MathfieldElement.restoreFocusWhenDocumentFocused
to control whether a mathfield that was previously focused regains focus
when the tab or window regains focus. This is true by default and matches
the previous behavior, and the behavior of the <textarea>
element.
An alternate syntax for selectors with arguments. Selectors are used for
example to associate actions with a keycap, such as switchKeyboardLayer
.
The previous syntax was command: ["switchKeyboardLayer", "alt-layer"]
,
the new syntax is command: 'switchKeyboardLayer("alt-layer")'
. This is more
concise and easier to read.
keydown
and input
event is now consistent
with the <textarea>
element.123{,}4(1)
),
do not use a \left...\right
command in order to get the proper spacing.\int
was incorrect.\textit{}
), the content could
sometimes be serialized with an unnecessary \text{}
command, i.e.
\text{\textit{...}}
.smart-fence
was off, the {
and }
keys would not insert
braces.\sqrt[#?]{1}
from the #?
position, a runtime exception would occur.before-virtual-keyboard-toggle
and
virtual-keyboard-toggle
events are now dispatched on the
window.mathVirtualKeyboard
object of the iframe. This can be used to detect
a request (and prevent) for the virtual keyboard to be displayed.\mathcal{C}
it would not be displayed correctly in the "Solve for" menu.\mathrlap
command was incorrectly rendering like \mathllap
.Changelog
0.98.6 2024-01-27
StaticRenderOptions.TeX.className
to specify that an element with the
specified class name should be rendered as a LaTeX formula.--keycap-width
CSS variable to specify the width of a
keycap in a virtual-keyboard. By default, if the CSS variable is not
specified, the width of the keycap is calculated based on the width of the
parent container. However, this requires browser that support the cq
CSS
unit. If the browser does not support the cq
CSS unit, this CSS variable can
be used to specify the width of the keycap. (See #2028, #2133)gather*
environmentrenderToMarkup()
or renderToMathML()
in a
server-side environment, a runtime error would occur.²
or ℂ
are now
interpreted as their LaTeX equivalent only when in math mode.\iff
now renders correctlymf.value
property would not always update the value
of the mathfield.renderMathToElement()
or renderMathInDocument()
, coalesce
adjacent text nodes.\cfrac
optional alignment argument\bf
, \bfseries
, \mdseries
, \upshape
, \itshape
,
\slshape
, \scshape
, \rmfamily
, \sffamily
, \ttfamily
are now
interpreted correctly.\operatorname
is now spoken correctlyChangelog
0.98.5 2023-12-27
When a font size command is inside a \left...\right
command, apply the font
size to the content of the command. As a result
\frac34 + \left( \scriptstyle \frac12 \right)
will now render as expected.
#2214 When using Linux or Windows with a German keyboard layout, typing
the ^
key will now switch to superscript.
#2214 When typing Unicode characters such as ²
or ℂ
, correctly
interpret them as their LaTeX equivalent. This also affects parsing of the
value
property.
#2000, #2063 A mathfield with multiple lines now generate correct
LaTeX using the \displaylines
command.
When a superscript or subscript is attached to a function, correctly position
a following \left...\right
command closer to the function.
When typing a superscript after f
, g
or some other function, correctly
interpret the superscript as an exponent, not as a function argument.
#787, #1869 The f
, g
and h
symbols are no longer hardcoded as
symbols representing functions.
Whether a symbol is considered a function affects the layout of a formula, specifically the amount of space between the symbol and a subsequent delimiter such as a parenthesis.
Now whether a symbol should be treated as a function is determined by the
MathfieldElement.isFunction
hook.
By the default, this hook uses the MathfieldElement.computeEngine
to
determine if the domain of a symbol is a function.
This can be customized by setting the isFunction
property of the mathfield
or by declaring a symbol as a function using the declare()
method of the
compute engine. For example:
MathfieldElement.computeEngine.declare("f", "Functions");
In addition, a new isImplicitFunction
hook has been added which can be used
to indicate which symbols or commands are expected to be followed by an
implicit argument. For example, the \sin
function can be followed by an
implicit argument without parentheses, as in \sin \frac{\pi}{2}
. This
affects the editing behavior when typing a /
after the function. If an
implicit function, the /
will be interpreted as an argument to the function,
otherwise it will be interpreted as a fraction with the function as the
numerator.
The "phi" keycap in the virtual keyboard was incorrectly displaying the
\varphi
symbol. It now displays the \phi
symbol.
#2227 Updating the content of the mathfield with mf.innerText
will now
correctly update the value of the mathfield.
#2225 For consistency with <textarea>
, when setting the value change the
selection to be at the end of the mathfield.
Changelog
0.98.3 2023-12-07
Improved contrast calculation for the checkmarks over color swatches, now using APCA.
In some situations, the virtual keyboard would not be displayed when the
mathfield was focused and the mathVirtualKeyboardPolicy
was set to "auto"
.
Changelog
0.98.2 2023-12-06
In some rare cases, the menu was not positioned correctly or would not display at all.
When dynamically changing the layout of the mathfield, for example when using a font-size attribute based on viewport units, correctly redraw the selection
Selection while dragging would stop after a few milliseconds
The "contains highlight" indicator is no longer displayed when the mathfield is not focused or when the indicator is outside of a prompt.
#2194 Ignore long press events when the pointer is a mouse.
#2195 If the mathfield had a variable width the selection would not be displayed correctly.
#2190 Under some circumstances, commands selected from the menu could be executed twice.