4
$\begingroup$

The parametric equation of a line is $\vec x=\vec p+t\cdot\vec u$, I want to display this equation "as it is", don't want for Mathematica to simplify it.

line[t_,p_,u_]:=p+t u

So if I define a line with:

line[t,{1,2,3},{-1,0,1}]
(*
  => {1-t,2,3+t}
*)

But I want it to display it like the equation, something like this: $\begin{pmatrix} 1\\2\\3\end {pmatrix}$ +t·$\begin{pmatrix} -1\\0\\1\end {pmatrix}$

I tried:

line/:MakeBoxes[parameter_,p_,u_]:=
  RowBox[{GridBox[Transpose[{p}]],"+",MakeBoxes[parameter],"·",GridBox[Transpose[{u}]]}]

So the previous command gives the following result:

line[t,{1,2,3},{-1,0,1}] //DisplayForm

(*

1   -1
2+t· 0
3    1

*)

But I can't get to print the parenthesis around the vectors. Also I get an error if I try to use MatrixForm in MakeBoxes, like this:

line/:MakeBoxes[parameter_,p_,u_]:=
  RowBox[{MakeBoxes[p,MatrixForm],"+",MakeBoxes[parameter],"·",MakeBoxes[u,MatrixForm]}]

I get an error that MatrixForm is not a box formatting type

Any help would be appreciated.

$\endgroup$
5
$\begingroup$

According to Jason Harris's talk at Wolfram Technology Conference 2019, the way to do that is:

MakeBoxes[line[
    t_
    , p : _List /; VectorQ @ Unevaluated @ p
    , u :  _List /; VectorQ @ Unevaluated @ u
    ]
   , StandardForm] :=
  With[
   {argsp = Map[Function[{a}, MakeBoxes[a, StandardForm], HoldAll]
      , Unevaluated @ p, {1}]
    , argsu = Map[Function[{a}, MakeBoxes[a, StandardForm], HoldAll]
      , Unevaluated @ u, {1}]}
   , RowBox[{"(", "", GridBox[Transpose @ {argsp}], "", ")", "+", 
     MakeBoxes[t, StandardForm], "(", "", 
     GridBox[Transpose @ {argsu}], "", ")"}]
   ];

line[t, {1, 2, 3}, {-1, 0, 1}]

enter image description here

I'm a beginner on this subject, so there may be subtelties I'm not aware.

$\endgroup$
1
  • 2
    $\begingroup$ There are more recent talks from J. Harris on this subject in more recent Wolfram Technology Conferences. They are very similar. $\endgroup$
    – andre314
    Feb 12 at 20:42
1
$\begingroup$

Does this function do what you want?

line[t_, p_, u_] := CellPrint[
                          Cell[
                         BoxData[
                            RowBox[
                             {StyleBox[
                                  RowBox[{"(", 
                                         GridBox[
                                            {{ToString[p[[1]]]}
                                            ,{ToString[p[[2]]]}
                                            , {ToString[p[[3]]]}}], 
                                  ")"}]
                                    , FontSize -> 12]
                                    , StyleBox["+", FontSize -> 12]
                                    , RowBox[{StyleBox[ToString[t]
                                    , FontSize -> 12]
                                    , StyleBox[".", FontSize -> 12]
                                    , RowBox[{"("
                                    , GridBox[
                                      {
                                         {RowBox[{ToString[u[[1]]]}]}
                                       , {ToString[u[[2]]]}
                                       , {ToString[u[[3]]]}
                                     }]
                                       , ")"}]}]}]]
                                   , "Output"] ];

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.