Bot releases are hidden (Show)
Published by arnog 4 months ago
#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: "displatchEvent('customEvent', {detail: 'some data'})"
}
To handle the event, add an event listener to the mathfield element:
mf.addEventListener('customEvent', (ev) => {
console.log(ev.detail);
});
The mf.offsetFromPoint()
method has been renamed 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\frac{a}{b}
and pressing alt+shift+T
will convert the(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<textarea>
element.123{,}4(1)
),\left...\right
command in order to get the proper spacing.\int
\textit{}
), the content could\text{}
command, i.e.\text{\textit{...}}
.smart-fence
was off, the {
and }
keys would not insert\sqrt[#?]{1}
from the #?
before-virtual-keyboard-toggle
andvirtual-keyboard-toggle
events are now dispatched on thewindow.mathVirtualKeyboard
object of the iframe. This can be used to detect\mathcal{C}
\mathrlap
command was incorrectly rendering like \mathllap
.StaticRenderOptions.TeX.className
to specify that an element with the--keycap-width
CSS variable to specify the width of acq
CSScq
CSS unit, this CSS variable cangather*
environmentrenderToMarkup()
or renderToMathML()
in a²
or ℂ
are now\iff
now renders correctlymf.value
property would not always update the valuerenderMathToElement()
or renderMathInDocument()
, coalesce\cfrac
optional alignment argument\bf
, \bfseries
, \mdseries
, \upshape
, \itshape
,\slshape
, \scshape
, \rmfamily
, \sffamily
, \ttfamily
are now\operatorname
is now spoken correctlyWhen 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.
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"
.
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.
mf.showMenu()
method to programmatically show the context menu.Correctly position the menu when the document has been scrolled.
When serializing, do not generate a \text
command around a \texttt
command.
The mf.setPromptContent()
method has been renamed to mf.setPromptValue()
for consistency with the mf.getPromptValue()
method.
The mf.stripPromptContent()
method has been removed. Its functionality can
be achieved with:
const prompts = mf.getPrompts();
const values = prompts.map(id => mf.getPromptValue(id));
prompts.forEach(id => mf.setPromptValue(id, ""));
mf.getPromptRange()
method returns the selection range of a prompt.mf.focus();
mf.selection = mf.getPromptRange(id);
The Color, Background Color and Variant menus correctly toggle the colors and
variant, and reflect their state with a checkmark or mixedmark.
Setting the mf.menuItems
property before the mathfield is inserted in the
DOM will now correctly update the menu items.
Correctly display tooltips in the menu when invoked via the menu icon.
Localized menu items in the context menu.
#348 Added a placeholder
attribute, similar to the placeholder
attribute of a <textarea>
element. This specifies a short hint as a LaTeX
string that describes the expected value of the mathfield. When the mathfield
is empty, the placeholder text is displayed. The placeholder text can be
styled with the math-field::part(placeholder)
CSS selector.
#2162 Added a "latex-without-placeholders"
format to the getValue()
method. This format is similar to the "latex"
format, but does not include
the placeholders (for "fill-in-the-blanks").
#2169 Changing the selection programatically will now correctly update the
mathfield.
#2189 If the decimal separator is set to ,
, the virtual keyboard will
now correctly display the decimal separator as a comma.
#2139 On some keyboard layouts, ALT+/ would insert a
\/
command, which is not standard. Now, the simple /
is inserted.
.row
class was defined, it would be applied to the virtualmf.queryStyle()
method to query the style of a selection or theThe mode-change
event is now dispatched more consistently when the mode
changes.
When the mathfield loses focus, if some of the content is in LaTeX mode, it
remains in LaTeX mode. Previously, it would switch to math mode when losing
focus.
Changing the user-select
CSS property before inserting the mathfield in the
DOM would not always be respected.
Use the DOM Popover API when available, which should ensure menus are
displayed on top of other elements more consistently.
Added support for accented characters in the virtual keyboard (press and hold
a vowel on an alphabetic keyboard to get accented variants), including a
modified AZERTY layout (SHIFT+digits to get common accented
characters).
Improved rendering of the menu for CJK and LTR languages.
If there were multiple mathfield elements on the page, only the last one would
display tooltips.
#2184 Pressing the TAB key when in a prompt (fill-in-the-blank)
would not move to the next prompt
#2183 The MathML serialization of factorial was incorrect.
#2181 The MathML serialization of limits was incorrect.
#2180 Allow the context menu to get turned off by setting
mf.menuItems = []
Fixed a layout issue with the positioning of the context menu in some cases.
Improved dark mode appearance of context menu
Context Menu Right-clicking on a mathfield or clicking the menu icon next
to the virtual keyboard icon will bring up a context menu.
The keyboard shortcut ALT+SPACE will also bring up the
context menu. This keyboard shortcut previously toggled the virtual keyboard.
This keyboard shortcut to toggle the virtual keyboard is now
ALT+SHIFT+SPACE.
The menu includes commands to:
The content of the menu may change in future versions, and feedback is
welcome.
The menu can be customized by setting the mf.menuItems
property of the
mathfield. The value of this property is an array of menu items. See
the documentation for details.
\pmod5
is now correctly parsed as \pmod{5}
. Macros thatMathfieldELement.locale
or MathfieldElement.strings
mf.locale
insteadMathfieldElement.locale
) will now throw an error.smartFence
was on, an inline shortcut that conflicted with a\mapsfrom
.user-select
CSS property.none
, the mathfield will not be selectable.mf.registers.arraystretch = 1.5
instead of mf.registers = {...mf.registers,\renewcommand
, for example\renewcommand{\arraystretch}{1.5}
[up]
and [down]
to move the selection up or down in\left...\right
was vertically offset.[hide-keyboard]
virtual keycap would cause a runtimegeometrychange
event isserializeMathJsonToLatex()
has been renamed toconvertMathJsonToLatex()
for consistency.(f(x))
would be parsed as (f(x)
.(
was interpreted as \lparen`. This could cause some\operatorname
command, some of the commands could fail to render. ForverbatimLatex
associated with thevalue
property of the atom is correctly serialized.moveToMathfieldEnd
command, the selection was not changedmoveToMathfieldStart
.mathtools
, actuarialangle
,colonequals
, statmath
and amsopn
packageslongdiv
enclosure (\mathenclose{longdiv}{...}
).
) in the virtual keyboard was displayed as ashift +
in the numeric keyboard was inserting a sum,
key now produces a semicolon when\cdot
\times
. Use shift to produce \times
.\displaystyle
and \textstyle
to MathML7
key was the variant panel for 4
.sen[backspace][backspace]in
will be corrected to \\sin
.\operator*{}
command\class{}{}
command in a mathfield was not working correctly.prompt
CSS part to the mathfield element. This allows styling ofw40
keycap class (4-wide)renderMathInElement()
preserve the LaTeX as a data-
attribute\imaginaryI
, \imaginaryJ
, \ne
and \neq
PointerEvent
supportmf.mathVirtualKeyboard
. The virtualwindow.mathVirtualKeyboard
.command
attribute is associated with a keycap, amath-virtual-keyboard-command
event is dispatched when the keycap isx^{#?}
in the virtual keyboard variant panel for x
\int
was triggered with sint
. Note that in caseif-math-mode
and if-text-mode
classes to conditionally show virtual\exp
instead of \mathrm{exp}
in the virtual keyboard"sandboxed"
in aenvironmentPopoverPolicy
option. Set to:
"auto"
to show environment popover when inside a tabular environment and"on"
to show it when in a tabular environment"off"
to never show it\underline
and \overline
commands now render correctly.\left...\right
command\left...\right
command was incorrectlyFull Changelog: https://github.com/arnog/mathlive/compare/v0.94.7...v0.100.0
getPromptValue()
mathVirtualKeyboard.layouts
property was a frozen array (an array\text{}
command,
) didPublished by arnog over 1 year ago
\raise
, \lower
and \raisebox
commands. Those commands(
, [
or {
with a selection will enclose the selection with\ce{ O\bond{~-}H}
\mathtooltip{}
and \texttip{}
commandsunstyled-latex
).\cos^2
(operatorsFull Changelog: https://cortexjs.io/mathlive/changelog/
Published by arnog over 3 years ago
virtualKeyboardState
property to indicate if the virtualversion
(previously available as MathLive.version
).infty
and int
inline shortcuts.Published by arnog over 3 years ago
\chi13
(0.1em) gap between the nucleus and the above element was missingOverUnder
atoms (\overset
, etc...).renderMathInElement()
or renderMathInDocument()
,renderMathInElement()
or renderMathInDocument()
.Published by arnog about 4 years ago
#225 Added onCommit
listener to mf.options
. This listener is invoked when
the user presses Enter or Return key, or when the field loses focus
and its value has changed since it acquired it.
In addition, a change
event is triggered when using a MathfieldElement
.
The event previously named change
has been renamed to input
.
This mimics the behavior of <input>
and <textarea>
elements.
#225 Changed the keyboard shortcuts to add columns and rows:
Shortcut | Command |
---|---|
ctrl/cmd + Return/Enter | addRowAfter |
ctrl/cmd + shift + Return/Enter | addRowBefore |
ctrl/cmd + ; | addRowAfter |
ctrl/cmd + shift + ; | addRowBefore |
ctrl/cmd + , | addColumnAfter |
ctrl/cmd + shift + , | addColumnBefore |
Note that Enter/Return no longer create a matrix/vector when inside a parenthesized expression. Use ctrl/cmd + Return/Enter instead.
Added a commit
command to programmatically trigger the onCommit
listener
change
event.
Added mount
and unmount
events to MathfieldElement
The $text()
method, which is deprecated, was accidentally prematurely removed.
It has been added back.
x=sin
-> x\sin
instead of x=\sin
\xrightarrow
were incorrectlyThis release introduce two major new features which will require code changes.
For now, the older API remains supported but it will be dropped in an
upcoming release.
Support for MathfieldElement
custom element/web component and <math-field>
tag.
The makeMathField()
method is still supported, but it will be removed in an upcoming version. You should transition to using <math-field>
or
MathfieldElement
instead.
This transition require the following changes:
MathfieldElement
or declaratively// Before
let mf = MathLive.makeMathField(document.createElement('div'), {
virtualKeyboardMode: 'manual',
});
mf.$latex('f(x) = \\sin x');
document.body.appendChild(mf.$el());
// After
let mfe = new MathfieldElement({
virtualKeyboardMode: 'manual',
});
mfe.value = 'f(x) = \\sin x';
document.body.appendChild(mfe);
or:
<math-field virtual-keyboard-mode="manual">f(x) = \sin x</math-field>
// Before
mf.setConfig({ onContentDidChange: (mf) => {
console.log(mf.$latex())
});
// After
mfe.addEventListener('input', (ev) => {
console.log(mfe.value);
});
Support for web component is an opportunity to revisit the MathLive public API and modernize it.
The goals are:
$latex()
can be used to read or change the content of the mathfield.$selectedText()
can return the value of the selection,getConfig()
is called getOptions()
in mostMathfield methods
The following Mathfield
methods have been renamed as indicated:
Before | After |
---|---|
$setConfig() |
setOptions() |
getConfig() |
getOptions() and getOption()
|
$text() |
getValue() |
$latex() |
value , getValue() and setValue()
|
$insert() |
insert() |
$hasFocus() |
hasFocus() |
$focus() |
focus() |
$blur() |
blur() |
$selectedText() |
mf.getValue(mf.selection) |
$selectionIsCollapsed() |
mf.selection[0].collapsed |
$selectionDepth() |
mf.selection[0].depth |
$selectionAtStart() |
mf.position === 0 |
$selectionAtEnd() |
mf.position === mf.lastPosition |
$select() |
select() |
$clearSelection() |
executeCommand('delete-previous-char') |
$keystroke() |
executeCommand() |
$typedText() |
executeCommand('typed-text') |
$perform() |
executeCommand() |
$revertToOriginalContent() |
n/a |
$el() |
n/a |
n/a | selection |
n/a | position |
The methods indicated with "n/a" in the After column have been dropped.
Only the new methods are available on MathfieldElement
(i.e. when using web components). The Mathfield
class retains both the old methods and the
new ones to facilitate the transition, but the old ones will be dropped
in an upcoming version.
There is also a new selection
property on Mathfield
and MathfieldElement
which can be used to inspect and change the selection and a position
property to inspect and change the insertion point (caret).
The getValue()
method also now take an (optional) Range
, which is
the type of the selection
property, to extract a fragment of the expression.
Default Exports
While default exports have the benefits of expediency, particularly when converting an existing code base to ES Modules, they are problematic for effective tree shaking. Therefore the default export will be eliminated.
This means that instead of:
import Mathlive from 'mathlive';
Mathlive.renderMathInDocument();
you will need to use:
import { renderMathInDocument } from 'mathlive';
renderMathInDocument();
The following functions have been renamed:
Before | After |
---|---|
MathLive.latexToAST() |
Use MathJSON |
MathLive.latexToMarkup() |
convertLatexToMarkup() |
MathLive.latexToMathML() |
convertLatexToMathMl() |
MathLive.latexToSpeakableText() |
convertLatexToSpeakableText( ) |
getCaretPosition()
and setCaretPosition()
Selector
has been improvedgetOptions()
(getConfig()
) are more accurate\enclose
is emptyupward
and downward
hooks when navigating out of thefocus-out
event)tabIndex
wastabIndex="0"
the mathfield frame would be focusable<textarea>
element which is normally focused to receive keyboard events,blur
event (for the container losing focus)focus
event (for the <textarea>
gaining focus)config.strings
property did not reflect the state of the localization strings@stefnotch
for contributing several of the improvements in thisPublished by arnog about 4 years ago
See the Change Log
Published by arnog about 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
See the Change Log
Published by arnog over 4 years ago
#450 Custom keybindings. A keybinding (also called keyboard shorcut)
associate a keystroke combination on a physical keyboard with a command.
Mathlive previously had some built-in keybindings, but now they can be
extended or replaced.
See config.keybindings
and Keybinding
.
Added setKeyboardLayout()
and setKeyboardLayoutLocale()
functions to
customize the current physical keyboard layout.
#461 The array editing commands only worked in math mode. They now apply
in text mode as well.
#459: Add a placeholder for incomplete commands, for example entering
\frac
in command mode.
Added some missing commands: deleteNextChar
, deletePreviousChar
,
deleteNextWord
, deletePreviousWord
, deleteToGroupStart
, deleteToGroupEnd
,
deleteToMathFieldEnd
, moveToSubscript
, applyStyle
, toggleVirtualKeyboard
,
hideVirtualKeyboard
, showVirtualKeyboard
In some cases, the top of the placeholder character could be cut off.
The Read Aloud feature would not work when a Neural Engine AWS voice
was used (such as Joana or Matthew)
In the Vue wrapper, the onKeystroke
handler would error
Styling (applying color, style) was disabled. This also affected mode change
(i.e. alt+= to switch between text and math mode)
After completing a command in command mode (i.e. pressing the return key), the mode did not switch not math mode and remained in command mode.
Published by arnog over 4 years ago
\inf
, \Pr
, \liminf
, \limsup
sinh
, cosh
, sec
, csc
,cot
, arcsin
, arccos
, arctan
\rbrack a
would generate \rbracka
)The absolute value character "|" (and other small delimiters) would be
displayed in the wrong font (and too small)
The absolute value key from the virtual keyboard would
insert '|#@|'
The 'sqrt' key from the virtual keyboard or keyboard shortcut
(option+V) would do nothing. The problem affected any inline shortcut or key
that included a '#0' argument when there was no selection
Fixed an issue with long inline shortcuts that could trigger text mode
(e.g. 'arcsin') and never apply the inline shortcut
Do not trigger smart mode conversion with arrow keys
Fixed an issue on iOS 12 and Firefox/Android where the Mathfield could not be
focused (fix contributed by (https://github.com/beneater)