# How to change the output of an expression (e.g. a vector) into a form that can be easily copied to Maple?

I am trying to write the result of the equation of the line passing through points pA, pB. My code

pA = {1, 2, 3};
pB = {3, 6, 7};
u = pB - pA;
pA + u t


{1 + 2 t, 2 + 4 t, 3 + 4 t}

How can I get this result in the form [1 + 2 t, 2 + 4 t, 3 + 4 t] which can be easily copied to Maple?

• Mathematica's default convention is to use braces for vectors; why do you need brackets in the output? – J. M. will be back soon Mar 13 '18 at 16:02
• Sometimes, I want to copy the result to Maple. – minhthien_2016 Mar 13 '18 at 16:03
• Your question has nothing whatsoever to do with the equation of a line. Don't you see that? Please write a useful title that will help others find the solution if they have a similar problem, which is only about converting to a Maple format. – David G. Stork Mar 13 '18 at 16:26
• Since Maple afaik can import MatLab-expressions maybe this old package (ToMatlab.m) is an option? – gwr Mar 13 '18 at 18:22
• I have now rephrased your title to make it (imho) more sensible - if you do not like this, simply roll back. – gwr Mar 13 '18 at 18:28

StringReplace[TextString[{a, b, c}], {"{" -> "[", "}" -> "]"}]


[a,b,c]

Even shorter:

pA = {1, 2, 3};
pB = {3, 6, 7};
u = pB - pA;
result = pA + u t

mapleForm[ mat_List ] := mat /. List -> "" (* // ToString  see comment by Carl Woll*)

result//mapleForm


[1 + 2 t, 2 + 4 t, 3 + 4 t]

And also:

{{1,2,3}, {4,5,6}} // mapleForm


[ [1, 2, 3], [4, 5, 6] ]

"To see the forest for the trees"* - thanks to b3m2a1 for the helpful comment!

• That's a cute trick. I like it. Even better to hit this at every level: result /. List -> "" – b3m2a1 Mar 13 '18 at 19:53
• I would avoid single argument ToString, e.g., consider the horrific output from mapleForm[{1/2, 10^x}]. – Carl Woll Mar 13 '18 at 20:09