Skip to content

Commit 6fa3e1f

Browse files
committed
doc: info about audio customization
1 parent 5da3e04 commit 6fa3e1f

File tree

4 files changed

+69
-10
lines changed

4 files changed

+69
-10
lines changed

docs/mathfield/02-playground.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ Read more about the supported **LaTeX commands**.<Icon name="chevron-right-bold"
614614
Learn more about MathJSON and try a demo of the **Compute Engine**.<Icon name="chevron-right-bold" />
615615
</ReadMore>
616616

617-
<h2 id="shortcuts">Keyboard Shortcuts</h2>
617+
## Keyboard Shortcuts
618618

619619

620620
<div className="shortcuts">

docs/mathfield/09-integration.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ simplest way to use mathfields is by loading the library from a CDN.
88

99
In this section we'll discuss other options for adding a mathfield to a web page.
1010

11-
## Using Mathfields with JavaScript Modules
11+
## Using JavaScript Modules
1212

1313
In addition to `MathfieldElement`, the Mathfield library provide some functions
1414
such as `renderMathInDocument()`.
@@ -61,7 +61,7 @@ keyboard shortcuts, use custom macros and more.
6161
The section below discuss additional options to load the library for more
6262
complex configurations.
6363

64-
<h2 id='npm'>Using NPM</h2>
64+
## Using NPM
6565

6666
If you need...
6767

@@ -97,7 +97,7 @@ Make sure the contents of the `/fonts/` and `/sounds/` folder are copied to
9797
your build output directory.
9898
:::
9999

100-
## Using `<script>` Tags
100+
## Using a `<script>` Tag
101101

102102
If you need to support browsers that don't support JavaScript modules, you
103103
can use a `<script>` tag to load a UMD version of the library.
@@ -134,7 +134,7 @@ The version of the library currently loaded can be obtained with:
134134
console.log(MathfieldElement.version);
135135
```
136136

137-
<h2 id='files'>Library Files</h2>
137+
## Library Files
138138

139139
If you need to incorporate the library files directly into your project
140140
(for example if you are building a standalone application), you can obtain
@@ -159,7 +159,7 @@ and may be useful for debugging.
159159
| `dist/mathlive-static.css` | A stylesheet which can be used when the MathLive library is not loaded to display markup that has been rendered by the MathLive library previously. Rarely needed. |
160160
| `dist/types` | The TypeScript declaration files. Not needed at runtime. |
161161

162-
<h2 id='fonts-folder'> Controlling the Location of the <kbd>fonts</kbd> Folder</h2>
162+
Controlling the Location of the `fonts` Folder
163163

164164
In order to display mathfields correctly a set of specialized math fonts must
165165
be available. These fonts are provided as part of the library in a directory called `fonts`.
@@ -189,7 +189,7 @@ path from the JavaScript directory to the fonts directory is `../assets/mathlive
189189
The `MathfieldElement.soundsDirectory` property can similarly be set to point
190190
to the sound file assets.
191191

192-
<h2 id='asset-pipeline'>Integrating with a Bundler or an Asset Pipeline</h2>
192+
## Integrating with a Bundler or an Asset Pipeline
193193

194194
In some cases, simply pointing MathLive to the directory where the fonts can
195195
be located might not be enough. For example, some bundlers, such as WebPack,
@@ -259,7 +259,7 @@ Learn more about the attributes, properties, methods and events <kbd>ENTER</kbd>
259259
Learn more about the <strong>Lifecycle</strong> of the mathfield web component.
260260
</ReadMore>
261261

262-
<h2 id='static-render'>Displaying Non-Editable Formulas</h2>
262+
## Displaying Non-Editable Formulas
263263

264264
While MathLive is primarily a math editor, the same engine that renders
265265
an interactive math formula can also render "static" formulas in a web page,

docs/mathfield/12-customizing.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,62 @@ MathfieldElement.fractionNavigationOrder = "denominator-numerator";
556556
```
557557

558558

559+
## Sounds and Haptic Feedback
560+
561+
The mathfield provides some audio feedback when a key is pressed on the virtual
562+
keyboard or when an action cannot be performed, for example when trying to
563+
delete when the mathfield is empty (the "plonk" sound).
564+
565+
The files for the sounds played by the mathfield should be located in a
566+
directory named `sounds` next to the mathfield library. If your bundler or
567+
asset management system require a different configuration you can specify
568+
where the sounds can be located using the `MathfieldElement.soundsDirectory`
569+
property.
570+
571+
```js
572+
MathfieldElement.soundsDirectory =
573+
"https://unpkg.com/mathlive/dist/sounds/";
574+
```
575+
576+
Specific sounds can be disabeld or customized with the `MathfieldElement.keypressSound`
577+
property.
578+
579+
```js
580+
MathfieldElement.keypressSound = {
581+
spacebar: null,
582+
return: "./sounds/return.mp3",
583+
delete: null,
584+
default: null,
585+
}
586+
```
587+
588+
### Playing "Plonk" Sound
589+
590+
**To play the "plonk" sound** when an action cannot be performed, use `MathfieldElement.playSound('plonk')`.
591+
592+
```js
593+
MathfieldElement.playSound('plonk');
594+
```
595+
596+
597+
### Disabling Sounds
598+
599+
**To turn off the sounds** set the `MathfieldElement.soundsDirectory` property to `null`.
600+
601+
```js
602+
MathfieldElement.soundsDirectory = null;
603+
```
604+
605+
### Haptic Feedback
606+
607+
When a key on the virtual keyboard is pressed, a small vibration is triggered
608+
on devices that support it. This can be turned off by setting the
609+
`MathfieldElement.keypressVibration` property to `false`.
610+
611+
```js
612+
MathfieldElement.keypressVibration = false;
613+
```
614+
559615
## Fonts
560616

561617
The content of the mathfield is displayed using a family of high-quality

docs/mathfield/22-security.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ whenAvailable("DOMPurify", () => {
7575
(Note that this example is moot, as the `htmlData` command already sanitizes its input.)
7676

7777

78-
## Restricting Commands That Modify the DOM
78+
## Restricting Commands That Could Modify the DOM
7979

8080

81-
Some commands modify the DOM and pose a higher risk of XSS attacks. For instance, `\htmlData{}{}` and `\href{}{}` allow the insertion of HTML attributes. While both commands sanitize their input to prevent harmful attributes, you may want to disable them for added security.
81+
Some commands modify the DOM and pose a higher risk of XSS attacks.
82+
For instance, `\htmlData{}{}` and `\href{}{}` allow the insertion of HTML
83+
attributes. While both commands sanitize their input to prevent harmful
84+
attributes, you may want to disable or restrict them for added security.
8285

8386

8487
### Disabling Commands

0 commit comments

Comments
 (0)