Group Abstract Group Abstract

Message Boards Message Boards

1
|
13.5K Views
|
11 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Output as ordered pair (5, -2)?

Posted 10 years ago
POSTED BY: Mark Greenberg
11 Replies
Posted 10 years ago

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! : )

POSTED BY: Mark Greenberg
POSTED BY: Sander Huisman
CreateVector2[x_List] := Row[Join[{"("}, Riffle[x, ","], {")"}]]
CreateVector2 /@ {{1, 2}, {3/4, a}, {\[Pi], Graphics[{Red, Disk[]}]}}

Now you can use anything: numbers, symbols, graphics, networks...

POSTED BY: Sander Huisman
Posted 10 years ago
POSTED BY: Mark Greenberg

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:

enter image description here

Alternatively, you could use the small package MaTeX

http://szhorvat.net/pelican/latex-typesetting-in-mathematica.html

to get true latex into Mathematica...

POSTED BY: Sander Huisman
Posted 10 years ago
POSTED BY: Mark Greenberg

This one uses some low-level tricks to make it work:

CreateVector3[x_List]:=DisplayForm[StyleBox[RowBox[{"(",Row[x,","],")"}],SpanMaxSize->Infinity]]
CreateVector3/@{{1,2},{3/4,a},{\[Pi],Graphics[{Red,Disk[]}]}}

enter image description here

Using the low-level function XYZBox you can typeset anything and using AdjustmentBox you can tune it further...

POSTED BY: Sander Huisman
Posted 10 years ago
POSTED BY: Mark Greenberg

Hi Mark,

You could use StringRiffle so you can use the following functions for any length vector:

CreateVector[x_List]:=StringRiffle[ToString[#,InputForm]&/@x,{"(",",",")"}]
pts={{4,7},{-5,1/4},{7/12,6},{-1,0}};
CreateVector/@pts

I think this is quite elegant code. Not so bad. Of course you could also take the StringTemplate route:

StringTemplate["(`1`, `2`)"] @@@ pts

also not too bad (though 'slower' I think). But probably that is not of your concern.

POSTED BY: Sander Huisman
Posted 10 years ago

Hi Mark,

You can use one of the options in ToString to solve the format issue with fractions:

"(" <> ToString[#[[1]], InputForm] <> ", " <> ToString[#[[2]], InputForm] <> ")" & /@ pts

I would like to know if there's a nicer way as well to not convert things to string to display with round brackets.

Cheers,

Wilson

POSTED BY: Wilson Kan
Posted 10 years ago

I still got the 7/12 version of the fraction with this code:

enter image description here

POSTED BY: Mark Greenberg
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard