0

I'm using Python 3.10 to implement a classical mechanics problem, and I want to print a message to the console asking the user to input the initial velocities. I am using x, y, and z as coordinates so ideally I want to denote the velocity components as vx, vy, and vz.

Originally I thought of using unicode subscirpts, but apparently they don't exist for y and z (as this other SO answer explains).

Of course I could just display (v_x, v_y, v_z), but I wanted it to look a bit more polished. Is there an easy way to display non-unicode subscripts in Python? Or otherwise, some very bare-bones UI package where I can have more freedom in formatting the text (like using LaTeX, or Markdown)?

Chaotic
  • 101
  • 2
  • 1
    People are accustomed to the limitations of command line apps. A lot of people would understand "v(x), v(y), v(z)". If you want fonts, you could look into doing a simple GUI application, maybe with `pysimplegui`. – Tim Roberts Nov 10 '22 at 23:05
  • Thanks! I kind of expected that to be the case, but still wanted to ask in case I was missing some other way to make it work. I will look into the package you suggested. – Chaotic Nov 10 '22 at 23:11
  • You can display images in terminals (it is still magic to me, but very few tools do it, and i still didn't find documentation on such standard). In any case keyboard is not the most practical one, and people are used with different interface, so try to do a web interface. – Giacomo Catenazzi Nov 11 '22 at 07:39
  • @GiacomoCatenazzi That very much depends on which terminal emulator you are using. – chepner Nov 11 '22 at 21:52

1 Answers1

0

No -

The terminal emulator (or command line) can only display characters, and does not allow for unlimited character transformations, as it is possible with text on a web browser or in a graphic interface.

ALthough there are special character sequences that can trigger special features such as foreground and background color, underline and blinking, those have to be implemented by the terminal emulator program itself, and appart from a subset, there is no universal code convention. The closest one, are what we usually call "ANSI escape code sequences" do not provide for a subscript or super-script convert - you can check the available codes on wikipedia - those will work in most terminal programs for Linux and MacOS and most custom terminal programas in windows (including the one called "terminal" in the microsoft store), but not on the default "cmd" app which cames pre-installed in windows.

(There is a Python package called "colorama" which tries to overcome this limitation to cmd, allowing cross-platform terminal programs able to display rich text - but it will filter out the codes for using fullcolor in terminal programs that accept them, so it is not always a good idea)

All that said, the tables as they are in the linked wikepdia article may be a bit confusing - but for shorten: "CSI" is the sequence "\x1b[" - where "\x1b"is the "ESC" character (decimal 27) , and "[" is a literal "open square bracket" char - the "SGR" sequence is"\x1b[<list-of-parameters-separated-by-;>m"` (again, "m" here is just the plain letter "m" closing a sequence of numeric codes that may change the way the terminal will display some text.

So, for front-face red text, you may want to do:

print("\x1b[31mThis text in red\x1b[39m normal color").

(note that the numbers are also plain decimal strings with the digits)

You will note that the code "74" is reserved for "subscript" code - however, I don't know of a terminal emulator which implements it.

jsbueno
  • 99,910
  • 10
  • 151
  • 209