Quick Math Scratchpad
WIDGETDASHBOARD
maws7140

Quick Math Scratchpad

Type a sum and see the answer instantly. Supports + - * / % ^ and brackets.

What you need

  • The Datacore community plugin (Settings → Community plugins → Browse, search "Datacore").
  • The VaultHub widgets CSS snippet: download vaulthub-widgets.css, save it in your vault's .obsidian/snippets/ folder, then switch it on under Settings → Appearance → CSS snippets. One snippet styles every VaultHub widget.

Add it to a note

Paste the block below into any note. It renders in Live Preview and Reading view.

Only digits, operators, brackets and spaces are evaluated; anything else is dropped before the sum is worked out. ^ means "to the power of".

return function QuickMath() {
    const [expr, setExpr] = dc.useState('125 * 8 + 2^4');

    let result = '= 0';
    try {
        const clean = expr.replace(/[^0-9+\-*\/().^% ]/g, '').replace(/\^/g, '**');
        if (clean.trim()) {
            result = `= ${Function('"use strict";return (' + clean + ')')()}`;
        }
    } catch (e) {
        result = '= ...';
    }

    return (
        <div className="vh-widget vh-calc">
            <div className="vh-calc-header">CALC SCRATCHPAD</div>
            <input
                type="text"
                className="vh-calc-screen"
                value={expr}
                onChange={(e) => setExpr(e.target.value)}
                placeholder="Type math..."
            />
            <div className="vh-calc-result">{result}</div>
        </div>
    );
}

Related

How to Install

  1. Install the Datacore community plugin
  2. Add the VaultHub widgets CSS snippet to .obsidian/snippets/ and enable it
  3. Copy the code block on this page into any note

Required Plugins

Datacore

Categories

Tags

vaulthubcalculatormathutility