MathKeyboardEngine 1.0.0

dotnet add package MathKeyboardEngine --version 1.0.0                
NuGet\Install-Package MathKeyboardEngine -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathKeyboardEngine" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MathKeyboardEngine --version 1.0.0                
#r "nuget: MathKeyboardEngine, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MathKeyboardEngine as a Cake Addin
#addin nuget:?package=MathKeyboardEngine&version=1.0.0

// Install MathKeyboardEngine as a Cake Tool
#tool nuget:?package=MathKeyboardEngine&version=1.0.0                

alternate text is missing from this package README image NuGet

MathKeyboardEngine for C#

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

Also available:

Which LaTeX typesetting libraries?

An example of a typesetting library is KaTeX, which is meant for JavaScript. That library could, however, be used in most C# apps when loaded into a WebView (from local JavaScript and CSS files or via an internet connection). That WebView could be used to display the "output" of the key presses. For each virtual key you could use a PNG file.

If you're making a .NET MAUI Blazor app or a Blazor WebAssembly app, then a WebView is automatically used for your whole app. Therefore, you can use KaTeX or MathJax after creating some JavaScript-C# glue code.

If you don't use Blazor AND your don't want to use a WebView, then you need another typesetting library. Examples per project type:

  • If you're making a WPF app or Windows Forms app, then use WPF-Math as typesetting library.
  • If you're working with UWP, non-Blazor .NET MAUI, Avalonia, Uno, etc., then use CSharpMath as typesetting library.
  • ...
An execution timeline
  1. You load a page with your customized virtual math keyboard (based on one of the examples). On load the LaTeX for each key is typeset (by KaTeX, MathJax, WPF-Math or CSharpMath, etc.) 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(someMatrixNode) or MoveUp(), DeleteLeft(), etc.
  3. Calling GetEditModeLatex() 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 GetViewModeLatex() outputs the LaTeX without a cursor.

Note: you can use Parse.Latex(latexString) for pre-filling the textbox or for allowing users to also use raw LaTeX commands.

Let me test it now!

Live examples can be tested at MathKeyboardEngine.GitHub.io.

Pros and cons?

<i>Unique about MathKeyboardEngine:</i>

  • 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.

<i>A con:</i>

  • 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.)

<i>More pros:</i>

  • 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 from this C# repository or the JavaScript reporitory.)
  • almost forgotten: it's open source, free to use, free to modify (please fork this repo)!

How to use this library

In Visual Studio's Solution Explorer, right-click a project and click Manage NuGet Packages.... Browse and install "MathKeyboardEngine".

Add

using MathKeyboardEngine;

Then you can use:

var latexConfiguration = new LatexConfiguration();
var keyboardMemory = new KeyboardMemory();

// Handle button clicks, etc.

Documentation

Visit the documentation and (the right version of)* the Examples folder for more implementation details. There's only one example - for Blazor WebAssembly - but even if you work with something else - like Xamarin, .NET MAUI (especially .NET MAUI Blazor!), WPF or UWP - you may find parts that you want to copy.

* If you use a version tag in the url like this: https://github.com/MathKeyboardEngine/MathKeyboardEngine.CSharp/tree/v0.2, 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.

License

The MathKeyboardEngine repositories use the most permissive licensing available. The "BSD Zero Clause License" (0BSD) allows for<br/> 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

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 278 11/29/2023
1.0.0-beta 105 11/20/2023
0.2.0 323 1/27/2023
0.2.0-beta 145 1/27/2023
0.1.1 329 11/23/2022
0.1.0 417 6/28/2022
0.1.0-beta 184 6/20/2022