1.5.16 • Published 17 days ago

react-math-keyboard v1.5.16

Weekly downloads
-
License
ISC
Repository
github
Last release
17 days ago

react-math-keyboard

npm

This library provides :

  • a MathQuill input in which you can write both mathematical expressions (in LaTeX) and raw text
  • a customizable, pretty, mobile-friendly keyboard for this input.

You can test it in CodeSandbox : js version or ts version.

:warning: This is using a fork of MathQuill in order to use the comma as a decimal separator and the symbol $\times$ instead of $\cdot$ for multiplication. This is not customizable so far, but could be in the future if there are requests for it.

This library is used by Mathlive.fr.

Basic usage

Install the package :

npm i react-math-keyboard

Then import the MathInput :

import MathInput from "react-math-keyboard";

You can then use it with no configuration :

<MathInput />

Getting the value of the input as a LaTeX string :

const [latex, setLatex] = useState("")
//...later
<MathInput setValue={setLatex} />

If you need to do more specific stuff with the input, you should retrieve the ref to the MathField, and then the whole MathQuill API is available to use.

const mf = useRef<MathField>();
const onClick=()=> mf.current.latex("click!");

//...later
<MathInput setMathfieldRef={(mathfield)=>mf.current=mathfield} />
<button onClick={onClick}>Click me</button>

Customizing the keyboard

You can hide the toolbar if you don't need additional keys :

<MathInput numericToolbarKeys={[]} />

Or you can provide an array of KeyIds or KeyProps if you only want certain keys. Here is the format for KeyProps :

Prop : TypeDefaultDescription
id: KeyIdnoneUse a KeyId or "custom" for defining your own key
label: string \| ReactNodenoneWhat's displayed on the keyboard
labelType: "raw" \| "tex" \| "svg"noneType of the label
mathfieldInstructions?: MathfieldInstructionsundefinedAn objet { method , content }, with content being a string and method is one of the MathQuill Api methods.
onClick?: () => voidundefinedTo provide custom logic to the key
fullWidth?: booleantrueshorthand for width='100%'
isUtilityKey?: booleanfalseUtility keys have a different background

Example :

<MathInput
  numericToolbarKeys={[
    "cos",
    "sin",
    "tan",
    {
      id: "custom",
      label: "custom label",
      labelType: "raw",
      mathfieldInstructions: {
        method: "write",
        content: "custom content",
      },
    },
  ]}
/>

All the MathInput Props

Prop: TypeDefault valueDescription
lang?: ("en"\|"fr")enDefines the language, currently only English and French suppported
numericToolbarKeys?: (KeyId \| KeyProps)[]undefined undefined : All the keys Empty array : No toolbar Otherwise : the keys you've provided
numericToolbarTabs?: KeyGroupIds[]undefinedChoose the options you want in the select menu of the toolbar. See KeyGroup for a list of options
allowAlphabeticKeyboard?: booleantrueHide/show the alphabetic keyboard
alphabeticToolbarKeys?: (KeyId \| KeyProps)[]undefinedSame thing that numericToolbarKeys but for the alphabetic keyboard
setMathfieldRef?: (mf: MathField) => voidundefinedRetrieve the ref to the MathQuill input in order to use the MathQuill Api
setClearRef?: (f: () => void) => voidundefinedPass it a ref in order to have a shorthand for clearing the input. e.g : setClearRef( f => myRef.current = f) then myRef.current() somewhere in your App
initialLatex?: stringundefinedThis latex will be shown in the input at the initial render. Updates of this prop won't affect the input. You should interact with the MathField ref directly if you want to do stuff with the input.
setValue?: (s: string) => voidundefinedTo retrieve the latex
divisionFormat?: "fraction" \| "obelus""fraction"Whether to show divisions as fractions or with the division symbol ÷
style?: React.CSSProperties{}CSS for the input
size?: "small" \| "medium""medium"Shorthand to change the padding of the input
rootElementId?: stringundefinedBy default, the keyboard applies a padding bottom on the \<body> in order to not overflow the input. You can use this prop to set this padding on another element than the body. For example, you can target Nextjs' root element by doing rootElementId = "__next".
fullWidth?: booleantrueShorthand for width="100%"

Contributing

Don't hesitate to give feedback, and any contribution is welcomed !

1.5.16

17 days ago

1.5.15

1 month ago

1.5.14

1 month ago

1.5.13

1 month ago

1.5.12

2 months ago

1.5.11

2 months ago

1.5.10

2 months ago

1.5.9

2 months ago

1.5.8

3 months ago

1.5.7

4 months ago

1.5.6

4 months ago

1.5.5

4 months ago

1.5.4

4 months ago

1.4.2

6 months ago

1.4.1

7 months ago

1.4.0

7 months ago

1.5.3

6 months ago

1.5.2

6 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.3.2

7 months ago

1.3.1

7 months ago

1.3.0

7 months ago

1.2.38

7 months ago

1.2.39

7 months ago

1.2.37

7 months ago

1.2.34

9 months ago

1.2.35

9 months ago

1.2.33

9 months ago

1.2.36

9 months ago

1.2.32

1 year ago

1.2.31

1 year ago

1.2.30

1 year ago

1.2.29

1 year ago

1.2.28

1 year ago

1.2.27

1 year ago

1.2.26

1 year ago

1.2.25

1 year ago

1.2.24

1 year ago

1.2.23

1 year ago

1.2.22

1 year ago

1.2.21

1 year ago

1.2.20

1 year ago

1.2.19

1 year ago

1.2.18

1 year ago

1.2.17

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.30

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago