Let’s say I have a list of pairs of numbers, like this:
pts={{4,7},{-5,1/4},{7/12,6},{-1,0}};
I want to output individual points in the form of (4,7), possibly with a space after the comma. This is how students in the US usually see points formatted. So far, the only way I have been able to do it is by building up a string for each point, like this:
But there are a few problems with this method. First, it doesn’t work for fractions, though a more elaborate version might. Second, converting numbers to strings isn’t really consistent with the symbolic nature of Wolfram programming.
How should I get the points to output as traditional ordered pairs?
Thank you, Wilson and Sander, for showing me more elegant ways of converting point coordinates to strings. It’s cool how there are so many ways to do the same thing in the Wolfram Language.
I’m still wondering whether there is a way to keep a point as a symbol while outputting its coordinates separated by a comma and surrounded by parentheses. Disadvantages of a string approach include non-scaling parentheses and fractions that look like 7/12 rather than
.
Yes, this is closer to what I have in mind, only the parentheses don’t scale to their content. Notice the second point especially in this example. Can one indicate “stretchy” parentheses in the Wolfram Language, as is possible in LaTex, or cause parentheses to automatically resize to their content as happens in equation editors and in Wolfram notebooks in other contexts?
I’m not sure you can explicitly introduce stretched parenthesis easily… That could be tricky to do I think! Though TraditionalForm does make stretched parenthesis:
Unfortunately, TraditionalForm uses stretched parentheses only in places where Wolfram syntax says that parentheses are needed, as in your example in which the parentheses group the disc and the fraction for the exponent. It doesn’t recognize (2,7) as a valid syntax, so it throws an error. It would be nice if the TraditionalForm of the correct syntax for a point, Point[{2,7}], would format as (2, 7), but it only outputs Point[{2,7}] in “Times” font.
I did look over the MaTex site, which looks like it is too involved for my needs, but that may be the only way to achieve what I am after.
Ah, very nice! I suspected that there was a way to do it, and there is. I have seen in the docs that box functions exist, but I assumed that they had something to do with input and output containers. I didn’t imagine they were the solution to my question, and they appear to be pretty simple too. Thank you very much, Sander! : )
There are generally many ways to achieve something in Mathematica/Wolfram Language, without knowing what someone REALLY wants to do and all the cases they consider and what ‘fringe-cases’ it should support, et cetera the answer can vary… hope the above works for you!