From 9cc75a03f73e915c8961d0eea9e7df18b1d82194 Mon Sep 17 00:00:00 2001 From: Arno Gourdol Date: Wed, 9 Oct 2024 16:19:26 +0200 Subject: [PATCH] fix: fixed #2533 --- CHANGELOG.md | 296 +++++++++++----------- css/virtual-keyboard.less | 245 ++++++++++-------- src/api.md | 26 +- src/atoms/macro.ts | 11 + src/core/atom-class.ts | 7 +- src/editor-mathfield/keyboard-input.ts | 3 + src/editor-mathfield/mathfield-private.ts | 18 +- src/editor-mathfield/render.ts | 1 + src/editor-model/styling.ts | 9 +- src/virtual-keyboard/variants.ts | 10 + test/smoke/index.html | 4 +- 11 files changed, 355 insertions(+), 275 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f62923622..2cbd87935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,33 @@ ## [Unreleased] - ### Issues Resolved - In some cases, the `placeholder` attribute would not be displayed when the mathfield was empty. - When using static math, the font-familly for text content was not correctly inherited from the parent element. +- **#2533** When using the virtual keyboard to insert a character with a + blackboard style followed by a non-alphabetic symbol without a blackboard + style, the second symbol would incorrectly be serialized with a blackboard + style. +- In some cases, the inherent style of a macro could get overriden. For example + typing the "RR" inline shortcut resulted in an unstyled R instead of the + expected blackboard R. ## 0.101.0 _2024-07-17_ ### Breaking Changes -- The properties `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... +- The properties `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... ### Improvements and New Features -- Macros can now be specified with `renderMathInElement()` and `renderMathInDocument()` - using the `macros` option. For example: +- Macros can now be specified with `renderMathInElement()` and + `renderMathInDocument()` using the `macros` option. For example: ```js renderMathInElement(element, {macros: {RR: '\\mathbb{R}'}}) @@ -29,27 +35,28 @@ - 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. +- 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 `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 + + - `[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: - + ```js mathVirtualKeyboard.setKeycap('[*]', {latex: '\\times'}); ``` @@ -59,34 +66,33 @@ - **#2455** Serialization to ASCII Math of brackets and braces is now correct. - When using Chrome in some locale (such as `es-419`), the context menu would not be displayed. -- When the `MathfieldElement.isFunction` handler is updated, re-render all - the mathfields on the page to take it into account. +- When the `MathfieldElement.isFunction` handler is updated, re-render all the + mathfields on the page to take it into account. - **#2415** A content change event is now dispatched when the value of the - mathfield is changed as a result of switch from LaTeX mode to math mode - by changing the selection. + mathfield is changed as a result of switch from LaTeX mode to math mode by + changing the selection. - Dispatch a `contextmenu` event any time the context menu is about to be displayed. This allows the event to be canceled. - **#2413** When setting the `alphabeticLayout`, the current keyboard would not be updated in some cases. -- **#2412** The serialization of some expressions to LaTeX could result in some spaces - being omitted. For example, `\lnot p` would serialize as `\lnotp`. -- **#2403** The virtual keyboard Keycap Variants panel was positioned incorrectly - when the page used a RTL layout direction. +- **#2412** The serialization of some expressions to LaTeX could result in some + spaces being omitted. For example, `\lnot p` would serialize as `\lnotp`. +- **#2403** The virtual keyboard Keycap Variants panel was positioned + incorrectly when the page used a RTL layout direction. - In the virtual keyboard, the background of the variant panel was sometimes displayed transparently. - **#2402** Characters inserted after a `\mathbb{}` command were not styled correctly. -- The `math-virtual-keyboard-command` event was not dispatched when a - mathfield was focused and a keycap was pressed. -- There are now CSS selectors to customize the size of glyphs in the - virtual keyboard (shift, enter, etc...): - - `--keycap-glyph-size` - - `--keycap-glyph-size-lg` - - `--keycap-glyph-size-xl` - -- **#2397** When a `beforeinput` event was canceled, the text would still - be inserted when using the physical keyboard. -- **#2398** When a placeholder was the only element in a group, i.e. +- The `math-virtual-keyboard-command` event was not dispatched when a mathfield + was focused and a keycap was pressed. +- There are now CSS selectors to customize the size of glyphs in the virtual + keyboard (shift, enter, etc...): + - `--keycap-glyph-size` + - `--keycap-glyph-size-lg` + - `--keycap-glyph-size-xl` +- **#2397** When a `beforeinput` event was canceled, the text would still be + inserted when using the physical keyboard. +- **#2398** When a placeholder was the only element in a group, i.e. `{\placeholder{}}`, the placeholder was not automatically selected. ## 0.100.0 _2024-06-12_ @@ -95,17 +101,18 @@ - **#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. +- **#2392** Pressing the backspace key after typing several digits would delete + all the digits. + +- **#2395** Added a `dispatchEvent` command which can be attached to a custom + keycap. 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. + argument is an object with the `detail` property, which is the data associated + with the event. ```ts - { + { label: "✨", command: "dispatchEvent('customEvent', {detail: 'some data'})" } @@ -119,21 +126,21 @@ }); ``` - ## 0.99.0 _2024-06-10_ ### Breaking Changes - The `mf.offsetFromPoint()` method has been renamed `mf.getOffsetFromPoint()` -- The `mf.setCaretPoint()` method has been replaced with `mf.position = 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{}`. -- 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. @@ -151,8 +158,8 @@ /** The bounding box of the element */ bounds?: DOMRect; - /** id associated with this element or its ancestor, set with `\htmlId` or - `\cssId` + /** id associated with this element or its ancestor, set with `\htmlId` or + `\cssId` */ id?: string; @@ -172,94 +179,96 @@ }; ``` - ### Bold -The way bold is handled in LaTeX is particularly confusing, reflecting +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 +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. +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. +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 +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. +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. +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. +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 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. - +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. ### Mode Switching -- **#2375** The `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. -- It is now possible to roundtrip between math and text mode. For example, - selecting a fraction `\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 +- **#2375** The `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. +- It is now possible to roundtrip between math and text mode. For example, + selecting a fraction `\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}`. -- When in LaTeX mode, changing the selection would sometimes unexpectedly exit +- When in LaTeX mode, changing the selection would sometimes unexpectedly exit LaTeX mode, for example after the Select All command. This has been fixed. ### New Features -- **`\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`. +- **`\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 + 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 @@ -268,36 +277,35 @@ and numbers. `` element, for example ``. - 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 `