Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Reference documentation and guides at cortexjs.io/mathlive.
Try it at mathlive.io.
To add a mathfield element in your page use a <math-field>
tag.
It works just like a <textarea>
or <button>
. You can manipulate the
mathfield using methods of the element and listen for events to be notified when
its internal state changes.
<!DOCTYPE html>
<html lang="en-US">
<body>
<math-field>f(x)=</math-field>
<script src="https://unpkg.com/mathlive/dist/mathlive.min.js"></script>
</body>
</html>
This project is licensed under the MIT License.
0.60.0 2021-04-12
Renamed getCaretPosition()
and setCaretPosition()
to get/set caretPoint
.
"Position" refers to where the caret/insertion point is, as an offset inside the expression. These methods return client screen coordinates and the new name better reflect the correct terminology.
Removed deprecated (April 2019) method enterCommandMode()
Replaced ignoreSpacebarInMathMode
option with mathModeSpace
. The
ignoreSpacebarInMathMode
was accidentally not working (#859). However,
the boolean form is problematic as an element attribute (it defaults to true,
but element attributes default to false). It has been replaced with
mathModeSpace
which is more flexible (you can specify which space to use)
and doesn't have the issue of the default boolean value.
Support for iframes. Multiple mathfields in a single document but in different iframes can now share a single virtual keyboard. In the main document, use:
makeSharedVirtualKeyboard({
virtualKeyboardLayout: 'dvorak',
});
And in the iframes, use the use-shared-virtual-keyboard
attribute:
<math-field use-shared-virtual-keyboard></math-field>
See examples/iframe
for more info.
Contribution by https://github.com/alexprey. Thanks!
#555 Support for IME (Input Method Engines) for Japanese, Chinese, Korean and other complex scripts.
applyStyle()
has now more options. Previously it always toggled the style of
the selection. Now it can either toggle or set the style, and modify the
selection or a specific range.
#387 find()
method to search the fragments of an expression that match a
LaTeX string or regular expression.
For example the following code snippet will add a yellow background to the fractions in the expression:
mf.find(/^\\frac{[^}]*}{[^}]*}\$/).forEach((x) => {
mf.applyStyle({ backgroundColor: 'yellow' }, x, {
suppressChangeNotifications: true,
});
});
#387 replace()
method to replace fragments of an expression.
This method is similar to the replace()
method of the String
class. The
search pattern can be specified using a string or regular expression, and the
replacement pattern can be a string or a function. If using a regular
expression, it can contain capture groups, and those can be references in the
replacement pattern.
The following snippet will invert fractions in a formula:
mf.replace(/^\\frac{([^}]*)}{([^}]*)}$/, '\\frac{$2}{$1}');
New LaTeX Mode
This mode replaces the previous Command Mode. While the Command Mode (triggered by pressing the \ or ESC key) was only intended to insert a single LaTeX command (e.g. "\aleph"), the LaTeX Mode is a more comprehensive LaTeX editing mode.
To enter the LaTeX Mode, press the ESC key or the \ key. While in this mode, a complex LaTeX expression can be edited. Press the ESC or Return key to return to regular editing mode.
To quickly peek at the LaTeX code of an expression, select it, then press ESC. Press ESC again to return to the regular editing mode.
To insert a command, press the \ key, followed by the command name. Press the TAB key to accept a suggestion, then the RETURN key to return to regular editing mode (previously pressing the TAB key would have exited the command mode).
Added soundsDirectory
option to customize the location of the sound files,
similarly to fontsDirectory
.
Enabled audio feedback by default.
#707 added support for \begin{rcases}\end{rcases}
(reverse cases
, with
brace trailing instead of leading)
#730 added new CSS variables to control the height of the virtual keyboard:
--keycap-height
--keycap-font-size
--keycap-small-font-size
(only if needed)--keycap-extra-small-font-size
(only if needed)--keycap-tt-font-size
(only if needed)#732 Support for Dvorak keyboard layout
Synchronize the virtual keyboard layout (QWERTY, AZERTY, etc...) with the physical keyboard layout.
Added \htmlData
command, which takes as argument a comma-delimited string of
key/value pairs, e.g. \htmlData{foo=green,bar=blue}
. A corresponding
data-foo
and data-bar
DOM attribute is generated to the rendered DOM.
read-only
mode, it was still possible to
delete a portion of it by pressing the backspace key.typedText
selector dropped its options argument. As a result, the sound
feedback from the virtual keyboard only played for some keys.<math-field>
element the command popover did not
display correctly.plain/text
item.alt+e
, and they are properly
displayed as a composition (side effect of the fix for #555).Complete rewrite of selection handling.
This is mostly an internal change, but it will offer some benefits for new capabilities in the public API as well.
Warning: This is a very disruptive change, and there might be some edge cases that will need to be cleaned up.
The position of the insertion point is no longer represented by a path. It is now an offset from the start of the expression, with each possible insertion point position being assigned a sequential value.
The selection is no longer represented with a path and a sibling-relative offset. It is now a range, i.e. a start and end offset. More precisely, the selection is an array of ranges (to represent discontinuous selections, for example a column in a matrix) and a direction.
These changes have these benefits:
onDelete
function now regroups all the
special handling when pressing the Backspace and Delete keys.find()
method
which returns its results as an array of ranges. It is also possible now to
query and change the current selection, and to apply styling to a portion of
the expression other than the selection.On a historical note, the reason for the original implementation with paths
was based on the TeX implementation: when rendering a tree of atoms (which TeX
calls nodes), the TeX layout algorithm never needs to find the parent of an
atom. The MathLive rendering engine was implemented in the same way. However,
for interactive editing, being able to locate the parent of an atom is
frequently necessary. The paths were a mechanism to maintain a separate data
structure from the one needed by the rendering engine. However, they were a
complex and clumsy mechanism. Now, a parent
property has been introduced in
instance of Atom
, even though it is not necessary for the rendering phase.
It does make the handling of the interactive manipulation of the formula much
easier, though.
Changes to the handling of sentinel atoms (type "first"
)
This is an internal change that does not affect the public API.
Sentinel atoms are atoms of type "first"
that are inserted as the first
element in atom branches. Their purpose is to simplify the handling of "empty"
lists, for example an empty numerator or superscript.
Previously, these atoms where added when an editable atom tree was created,
i.e. in the editor
code branch, since they are not needed for pure
rendering. However, this created situations where the tree had to be
'corrected' by inserting missing "first"
. This code was complex and resulted
in some unexpected operations having the side effect of modifying the tree.
The "first"
atoms are now created during parsing and are present in editable
and non-editable atom trees.
Refactoring of Atom classes
This is an internal change that does not affect the public API.
Each 'kind' of atom (fraction, extensible symbol, boxed expression, etc...) is
now represented by a separate class extending the Atom
base class (for
example GenfracAtom
). Each of those classes have a render()
method that
generates a set of DOM virtual nodes representing the Atom and a serialize()
method which generates a LaTeX string representing the atom.
Previously the handling of the different kind of atoms was done procedurally and all over the code base. The core code is now much smaller and easier to read, while the specialized code specific to each kind of atom is grouped in their respective classes.
Unit testing using Jest snapshot
Rewrote the unit tests to use Jest snapshots for more comprehensive validation.
FAQs
A web component for math input
The npm package mathlive receives a total of 39,945 weekly downloads. As such, mathlive popularity was classified as popular.
We found that mathlive demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.