Since most CLIs are really just terminals (rather dumb, but sometimes with color), the only cross-platform way I've ever done is to allocate multi-level physical lines for each virtual line, for example:
2 f(x) = x + log x 2
This is not ideal, but it is probably the best you get without a GUI.
After receiving more information on which platforms you are mainly interested in:
With Ubuntu, at least gnome-terminal starts in UTF-8 mode by default, so the following code shows how to create superscript indexes and indexes:
#include <stdio.h> static char *super[] = {"\xe2\x81\xb0", "\xc2\xb9", "\xc2\xb2", "\xc2\xb3", "\xe2\x81\xb4", "\xe2\x81\xb5", "\xe2\x81\xb6", "\xe2\x81\xb7", "\xe2\x81\xb8", "\xe2\x81\xb9"}; static char *sub[] = {"\xe2\x82\x80", "\xe2\x82\x81", "\xe2\x82\x82", "\xe2\x82\x83", "\xe2\x82\x84", "\xe2\x82\x85", "\xe2\x82\x86", "\xe2\x82\x87", "\xe2\x82\x88", "\xe2\x82\x89"}; int main(void) { int i; printf ("f(x) = x%s + log%sx\n",super[2],sub[2]); for (i = 0; i < 10; i++) { printf ("x%sx%s ", super[i], sub[i]); } printf ("y%s%s%sz%s%s\n", super[9], super[9], super[9], sub[7], sub[5]); return 0; }
The super and sub char * arrays are UTF-8 encodings for Unicode code points for numeric superscripts and indexes (see here ). This program will display my formula on top (on one line instead of three), then on another test line for all options and y-super-999 and z-sub-75, so you can see how they look.
MacOS doesn't seem to use gnome-terminal as a terminal program, but the link here and here seems to indicate that the standard terminal understands UTF-8 (or you can download and install gnome-terminal as a last resort).