Elegant Any Math Multi Preview
A calculator that shows its work
- values
- int
- float
- boolean
- string
Sooner or later your workflow needs a number that isn't a widget anyone hands you. Steps derived from a quality slider. A width rounded to the nearest 64. Megapixels out of a width and a height. ComfyUI has no scratchpad for that, so you either do the arithmetic in your head every time or you bury a magic number in a field and forget why 1248 is there. This node is the scratchpad.
What it actually is
Elegant Any Math Multi Preview evaluates one expression over any number of incoming values and hands the result out as four different types, while showing you the expression with the real numbers substituted in. It sits in ComfyUI's plumbing layer - the invisible majority of nodes that touch no pixels, existing only to hold, compute or route values. The pack it ships in, Elegant Nodes by wipeer, is built around one promise: everything stays usable from the subgraph node, so you don't have to open a collapsed subgraph to see inside. That's why the worked-out result shows up there after a run.
It's not the first math node - ComfyUI's own Math Expression node exists, and people do use it for exactly this kind of ranged input. What this adds is auto-growing inputs and a preview that shows the substitution.
How it works
Evaluation goes through simpleeval, the same library ComfyUI uses for its Math Expression node. So the expression is parsed as math, not Python: no imports, no attribute access, no code execution, and a ceiling on exponents so nobody hangs the worker with 2 ** 9999999.
The preview is the interesting part. It doesn't just print the answer; it re-tokenizes your expression and swaps each variable name for its value, which is why it reads like
1 + (2 / 2) - 3 = -1
int -1
float -1.0
boolean True
string -1.0
Function names and attributes aren't substituted, so round(a / 64) * 64 doesn't turn into nonsense.
Inputs and outputs you'll touch
values is the auto-growing input: name it a, b, c… in the expression, and a fresh socket appears each time you connect the last free one. It accepts anything, and text that looks like a number is treated as one, so str(int) round-trips don't bite you. Single-element tensors coming out of another math node get unwrapped to plain numbers too. The whole set is also available as the list values, so sum(values) works.
expression is the only thing you type, and it defaults to a + b. You get the usual arithmetic, //, %, **, comparisons, and/or/not, and the x if condition else y form, plus a function set that's broader than core's: sum min max abs round pow sqrt ceil floor log log2 log10 exp sin cos tan clamp int float str bool, with pi and tau as constants.
The four outputs are where this earns a permanent slot: int for width, height, steps or seed; float for CFG and denoise; boolean for driving a switch, since it's False for 0 or empty text; and string for a Note or a filename. Watch the truncation: int cuts decimals off toward zero, so 1.77 becomes 1, and a 0.5 result becomes 0. If you wanted rounding, say so - round(a / b). If the result is text that isn't numeric, int and float come out as 0 while string and boolean keep the actual value.
The everyday ones:
round(a / 64) * 64 # snap a width to an SDXL-friendly multiple
a * b / 1048576 # megapixels from width and height
clamp(a, 1, 150) # keep a steps value sane
max(a, b) # the larger of two dimensions
a % 2 == 0 # hand a boolean to a switch
Installing it
ComfyUI Manager is the path of least resistance: search for Elegant Nodes and install. Command line:
cd ComfyUI/custom_nodes
git clone https://github.com/wipeer/comfyui-elegant-nodes.git
pip install -r comfyui-elegant-nodes/requirements.txt
Restart ComfyUI and refresh the browser. The one Python dependency is simpleeval, which ComfyUI already ships, so there's nothing heavy to download. The nodes live under utilities → elegant in the Add Node menu.
Things that go wrong
The hard requirement is ComfyUI 0.4.0 or newer - this pack is written against the V3 node API and needs auto-growing inputs, which is what makes the values sockets appear as you connect them. On an older build the pack simply won't register, and in a pack this new that means no NODE_CLASS_MAPPINGS to find either; that's expected, not broken.
If you loaded a workflow from before the pack's 1.0.0 release, the node shows up as missing. The ids were renamed in that version, and the old math node carried over with a new name - replace it by hand once and re-save.
Two behavior notes. The node is flagged as an output node, which is how the worked-out preview is guaranteed to refresh on every queue - feature, not bug. And when something's wrong it fails the run rather than quietly handing you a zero, so if a queue dies right after you add this node, read the error: it names the expression and usually the culprit, whether that's an unconnected input or a divide by zero.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| values | COMFY_AUTOGROW_V3 | Values used in the expression as a, b, c, … | |
| expression | STRING | a + b | For example: a * b, (a + b) / 2, max(a, b), a > b, round(a / 64) * 64. Click the ? in the title for all operators and functions. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| int | INT | — |
| float | FLOAT | — |
| boolean | BOOLEAN | — |
| string | STRING | — |