CMath plugin for Take Command / TCC / TCC/LE

Version 1.0.5     2025-05-14

Charles Dye

Purpose:

This plugin provides an easy way to evaluate math expressions at the command line. Just type a colon, followed by the expression you want to evaluate, and press Enter.

Installation:

To use this plugin, copy CMath.dll to some known location on your hard drive. (If you are using the 32-bit version of Take Command, take CMath-x86.dll instead of CMath.dll.) Load the .DLL file with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\test\cmath.dll

If you copy the .DLL file to a subdirectory named PlugIns within your Take Command program directory, CMath will be loaded automatically when TCC starts.

Using CMath:

To evaluate a math expression, type a colon followed by the expression. Then press Enter:

:1+2*3

The answer, 7, will be displayed below your expression. It will also be saved to the environment variable ANS. You can use this variable in your next expression:

:ans*2

Just remember that the value of ANS changes every time you use CMath. After the second line, ANS will be 14, not 7.


CMath calls the same function that @EVAL uses internally. You can use any operator or function that is legal in @EVAL:

:log(100)


set r=4
:pi*r**2


:1492 =x



You do not need to quote or escape most special characters:

:(1+2)*3


:1 << 8


:1024 >> 3


:5 & 9


:5 | 9


:5 ^ 9



The one special character which needs attention is the percent sign. If you want to use a percent sign as the modulo operator, you will need to double it. (But it’s probably easier just to type MOD.)

:100%%7


:100 mod 7



You do not need a percent sign before environment variables. You do need a percent sign before internal variables and variable functions:

:%_pid =x


:3 * %@dec[foo]



@EVAL’s built-in functions do not take a percent sign:

set n=52
set r=5
:fact(n) / fact(n-r) / fact(r)



You can save the resulting value to a different environment variable, instead of ANS:

set n=1066
:tri=(n*(n+1))/2


The variable name may contain only letters, digits, dollar signs, hyphens, periods, and underscores. It must be less than 64 characters long, and must not begin with a digit or a period. Do not space between the variable name and the equals sign.


The clipboard: If you press Ctrl-Enter instead of just Enter, the resulting value will be copied to the clipboard, as well as being saved to ANS or another environment variable.

The Highlight Variable:

The displayed answer will be highlighted. You can customize this feature by setting an environment variable Highlight:

rem  Disable highlight:
set highlight=none

rem  Set the highlight foreground:
set highlight=bright cyan

rem  Set both foreground and background:
set highlight=bri whi on blu

rem  Numbers are also supported:
set highlight=46


If the Highlight environment variable is not defined, the plugin will check the registry for a value named Highlight of type REG_SZ. The plugin will search, in this order:

Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Changes:


Version:Date:Changes:
1.0.52025-05-14Per Joe Caverly: Ctrl-Enter also copies the resulting value to the clipboard.
Added support for the NO_COLOR environment variable. If NO_COLOR is defined and HIGHLIGHT is not, disable highlighting.
1.0.42024-11-29Strip all control characters from the string after the call to ExpandVariables(). I don’t think Evaluate() expects to see anything but printable ASCII characters.
1.0.32024-11-09Strip any CR or LF characters from the string after the call to ExpandVariables(). (@PSHELL returns these sometimes.)
1.0.22024-10-30Check for a leading environment variable name with an equals sign. If found, save the resulting value to that variable instead of ANS. Made the buffers bigger.
1.0.1.22024-10-04Changed http:// to https:// in the PLUGININFO block.
1.0.1.12023-10-12Updated the plugin’s web page.
1.0.12023-07-25Added the ability to store the Highlight variable in the registry instead.
1.0.02021-10-22First release.

Status and Licensing:

This plugin is © Copyright 2025, Charles Dye. Unaltered copies of the binary and documentation files may be freely distributed without restriction. I make no guarantee and give no warranty for its operation. If you find a problem, you can report it in the JP Software support forum.

Download:

You can download the current version of the plugin from https://charlesdye.net/dl/cmath.zip.