# [✓] Pasting numerical expressions into Input Cells?

GROUPS:
 David J M Park Jr 1 Vote I would like to create a PasteButton that will paste the following expression into an existing Input Cell and display in the Input Cell with the 6 place precision while keeping the full underlying machine precision. From my efforts I suspect that this is not possible because the only way to obtain the shortened display is to paste an entire Output Cell.. expr = N[x/3 + 2 y/3] giving 0.333333 x + 0.666667 y The following is just the simplest approach, which does not work. I haven't found any other approach that works either. PasteButton["1/3", expr] The resulting button pastes the following where the shorter form would be preferable. 0.3333333333333333 x+0.6666666666666666 y Does anyone know a way to specify a PasteButton that will paste the 6 place Output display into an Input Cell?
12 days ago
11 Replies
 Neil Singer 1 Vote David,Use PasteButton["1/3", expr // OutputForm] This will do what you want. It still has the full resolution -- evaluate the result and you can check that all the digits are still there by doing //FullForm.Regards,Neil
12 days ago
 Thanks Neil. That does paste into an Input Cell with the desired print precision but unfortunately I was deficient in my example. Suppose we have an expression with 2D Boxes such as: expr = N[x^2/3 + 2 y^2/3] Then we lose the regular StandardForm. (Also the real numbers would come from a longer calculation and we couldn't just revert back to the rational expression.)
12 days ago
 I can do it with Button but not PasteButton. Maybe this will help: Button["1/3", CellPrint@ExpressionCell[expr, "Input", NumberMarks -> False]] 
12 days ago
 Thanks Michael.The problem with this solution is that it prints an entirely new Input Cell and won't insert into an existing Input Cell.But it gives me a suggestion. Perhaps one can insert a dummy expression into the existing cell, copy the entire cell and Replace the dummy expression and then rewrite the Cell in place. I don't exactly know how to do this yet but will see if I can do it.
12 days ago
 Michael Rogers 1 Vote David,Can you initially create the Input cell into which the code is pasted with the Cell option NumberMarks -> False? Or can you set the option after the pasting?Or maybe you can do something with ButtonBoxOptionsButtonFunction. See CurrentValue[{StyleDefinitions, "Paste"}] for a hint.
12 days ago
 David,You can slightly modify Michael's solution to do what you want including adding to the expression. PasteButton["1/3", ExpressionCell[expr, "Input", NumberMarks -> False]] Regardsoops -- I just realized that this loses the extra precision that you wanted...
12 days ago
 forget my last comment -- It does retain the digits -- I just mistyped the fullform...I think this does what you want PasteButton["1/3", ExpressionCell[expr, "Input", NumberMarks -> False]] Am I correct?
12 days ago
 Hi Neil,This seems closer: PasteButton["1/3", Interpretation[ExpressionCell[expr, "Input", NumberMarks -> False], expr]] But the contents of the embedded cell still cannot be edited (in either this or your solution).
 Carl Woll 3 Votes You can just use a Style wrapper instead of Interpretation + ExpressionCell: PasteButton["1/3", Style[expr, StripOnInput -> True, NumberMarks -> False]] 
 David J M Park Jr 2 Votes Thanks Carl. That has one minor drawback. It pastes the expression in literally and not as a syntactic unit. Of course, the user could always type a set of parentheses before pasting but might often forget. If it was pasted after a 'z' in an existing Input Cell, the 'z' would only be associated with the first term in the expression. So I went to a box structure as follows. expr = N[x/3 + 2 y/3] PasteButton["1/3", RawBoxes@StyleBox[RowBox[{"(", ToBoxes[expr], ")"}], NumberMarks -> False]] When this is pasted into an Input Cell that contains an initial 'z' we now obtain: z (0.333333 x + 0.666667 y) This maintains full machine precision in the notebook, but not in the posting. It is now also editable.