MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Using Mathgroup Effectively -- cutting and pasting expressions


At 01:15 AM 6/12/2002, Dave Collins wrote:

>Of course, if this were a carefully formatted notebook, I'd need to discard
>the changes after conversion and copying. Given all the other options
>under the "Edit|Copy as" menu, it would be nice if Wolfram would add
>"Copy as input form", perhaps with the option of making it the default.
>
>-- Dave Collins

Here's code for a palette that does just that. It takes a selection and 
passes it through Cell>Convert To>InputForm and then does Edit>Copy 
As>Plain Text (all without altering the original selection).

NotebookPut@
   Notebook[{Cell[BoxData@ButtonBox["Copy As InputForm", ButtonFunction :>
               Module[{cpy, cpynb, evalnb},
                 cpy = NotebookRead@InputNotebook[];
                 If[cpy === {}, Return[]];
                 cpynb = NotebookCreate[Visible -> False];
                 NotebookWrite[cpynb, cpy];
                 SelectionMove[cpynb, All, Notebook];
                 FrontEndExecute[{FrontEndToken[cpynb, "SelectionConvert",
                       "InputForm"]}];
                 evalnb =
                   NotebookPut@
                     Notebook[
                       Map[Cell[#, "Input"] &, {
                           BoxData@RowBox@{"cpynb", "=", ToBoxes@cpynb},
                           "FrontEndExecute[{FrontEndToken[cpynb, 
\"CopySpecial\",\"PlainText\"]}]",
                           "NotebookClose[cpynb]",
                           "NotebookClose[EvaluationNotebook[]]"}],
                       Visible -> False];
                 SelectionMove[evalnb, All, Notebook];
                 SelectionEvaluate@evalnb;
                 ],
             ButtonEvaluator -> Automatic,
             Active -> True], "Text"]},
     WindowClickSelect -> False,
     ShowCellBracket -> False,
     WindowSize -> {150, Fit},
     WindowElements -> {},
     WindowFrame -> "Palette",
     WindowFrameElements -> {"CloseBox"},
     ClosingAutoSave -> True
     ]

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html



  • Prev by Date: Re: Nonlinear Programming?
  • Next by Date: RE: Re: A friendly challenge: Generalized Partition
  • Previous by thread: Re: Using Mathgroup Effectively -- cutting and pasting expressions
  • Next by thread: Dashed Arrowheads