MathKeyboardEngine provides the logic for a highly customizable virtual math keyboard. It is intended for use together with any LaTeX typesetting library.
$ dotnet add package MathKeyboardEngine
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:
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:
Insert(someMatrixNode) or MoveUp(), DeleteLeft(), etc.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.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.
Live examples can be tested at MathKeyboardEngine.GitHub.io.
Unique about MathKeyboardEngine:
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.A con:
More pros:
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.
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.
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.