Skip to main content

MathKeyboardEngine provides the logic for a highly customizable virtual math keyboard. It is intended for use together with any LaTeX typesetting library.

Project description

latest release

MathKeyboardEngine for Python

MathKeyboardEngine for Python provides the logic for a highly customizable virtual math keyboard. It is intended for use together with any LaTeX typesetting library (for example matplotlib.mathtext, sympy in combination with the official latex install or Katex in a webview).

Also available:

An execution timeline

  1. You load a page with your customized virtual math keyboard (based on one of the examples). The keys show typeset LaTeX - loaded form a local png file or rendered on the fly - and a cursor is displayed in a textbox-look-a-like element.
  2. On your customized virtual math keyboard, you press a key. The key calls a MathKeyboardEngine function, for example insert(some_matrix_node) or move_up(), delete_left(), etc.
  3. Calling get_edit_mode_latex() outputs the total of LaTeX you typed, for example \frac{3}{4}\blacksquare (if \blacksquare is your cursor), which you then feed to the typesetting library for display.
  4. Calling get_view_mode_latex() outputs the LaTeX without a cursor.

Let me test it now!

Live (JavaScript) examples can be tested at mathkeyboardengine.github.io.

A Python example for the PyQt6 GUI framework can be found in the examples folder. Note that the Python example is limited, because it does not handle physical keyboard input. Also, there are many more GUI frameworks for which there is no example. However, the PyQt6 example might provide insight in how to use MathKeyboardEngine in any project.

Pros and cons?

Unique about MathKeyboardEngine:

  • it supports (almost?) all math mode LaTeX, including matrices. (Please share if you know anything that is not supported.)
  • its syntax tree consists of very few different parts: the StandardLeafNode, StandardBranchingNode, AscendingBranchingNode and DescendingBranchingNode can be used for almost all LaTeX, including fractions, powers, combinations, subscript, etc. with ready-to-use up/down/left/right navigation.
  • it can be used with any LaTeX math typesetting library you like.

A con:

  • this library will never be able to handle setting the cursor with the touch of a finger on a typeset formula. (But it DOES support up/down/left/right navigation and has a selection mode via arrow keys.)

More pros:

  • you have full control over what you display on the virtual keyboard keys and what a virtual key press actually does.
  • customize the editor output at runtime: dot or comma as decimal separator, cross or dot for multiplication, cursor style, colors, etc.
  • this library also supports handling input from a physical keyboard, where - for example - the forward slash "/" key can be programmed to result in encapsulating a previously typed number as the numerator of a fraction. (See the examples.)
  • almost forgotten: it's open source, free to use, free to modify (please fork this repo)!

How to use this library

Install Python and VS Code.

Run the following command in the VS Code Terminal:

py -m pip install --upgrade mathkeyboardengine

Then use

from mathkeyboardengine import *

k = KeyboardMemory()
latexconfiguration = LatexConfiguration()

# subscribe to button click events of virtual key presses, etc.

or

import mathkeyboardengine as mke

k = mke.KeyboardMemory()
latexconfiguration = mke.LatexConfiguration()

Note: "mke" is an abbreviation of "MathKeyboardEngine". You can choose something different.

Documentation

Visit the documentation and the (latest version of the)* examples folder for more implementation details.

* If you use a version tag in the url like this: https://github.com/MathKeyboardEngine/MathKeyboardEngine.Python/tree/v0.1.1, you can see the git repository as it was for that version. That may not be needed if the changelog doesn't note any important changes.

How to use this repo

Follow these steps to set up (and verify) a development environment for this repository:

  1. Install the latest version of Python via https://www.python.org/downloads. The download includes pip.
  2. Open the Terminal in VS Code and run
    py -m pip install pytest==7.4.4.
  3. Run all tests via
    py -m pytest tests/.
  4. See code coverage:
    py -m pip install pytest-cov==5.0.0
    py -m pytest tests/ --cov=src --cov-report term-missing.
  5. This repository has been developed in a folder structure that helps understanding it. The released package however has a "flat" structure, so that all imports can be done from a single namespace. This is done via _disthelper/flatpack.py (developed especially for this repository). Files from the src folder are recursively copied to a new folder 'mathkeyboardengine' and import statements are automatically updated. It also produces a new version of the tests folder. It is called in setup.py and noxfile.py.
  6. Run all tests for the flatpacked mathkeyboardengine for multiple versions of python :
    py -m pip install nox==2023.4.22
    py -m nox (this uses noxfile.py from the root of the repository).
  7. If you're interested the release steps, see _disthelper/release_steps.txt.

License

The MathKeyboardEngine repositories use the most permissive licensing available. The "BSD Zero Clause License" (0BSD) allows for
commercial + non-commercial use, closed + open source, with + without modifications, etc. and is equivalent to licenses like:

The "BSD Zero Clause License" (0BSD) does not have the condition

(...), provided that the above copyright notice and this permission notice appear in all copies.

which is part of the "MIT License" (MIT) and its shorter equivalent "ISC License" (ISC). Apart from that they are all equivalent.

Ask or contribute

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathkeyboardengine-1.0.0b0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

mathkeyboardengine-1.0.0b0-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

Details for the file mathkeyboardengine-1.0.0b0.tar.gz.

File metadata

  • Download URL: mathkeyboardengine-1.0.0b0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for mathkeyboardengine-1.0.0b0.tar.gz
Algorithm Hash digest
SHA256 cf2177a844ca38197ba258a0f90f374e4141bd25f84d0b0dda94aab5d6c50e5d
MD5 93714ea6d0a7fdeda700f0b766d3e87d
BLAKE2b-256 9a24005e1de9bb13d4a2de659630f9c9c3608dc21a78eefb6af61f2675edb86f

See more details on using hashes here.

File details

Details for the file mathkeyboardengine-1.0.0b0-py3-none-any.whl.

File metadata

File hashes

Hashes for mathkeyboardengine-1.0.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b86414c50a9af567b8fcc4d5f1a41cdb2a0f0b2b141eaac70c25724e7196553
MD5 769cd0d67378cf56d9a92248361c2dca
BLAKE2b-256 d7cab0efea03fb1f8c9c278b605a0f640a916aefccc5802315895c57a7f15abc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page