Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copy as InputForm

0 views
Skip to first unread message

Bobby R. Treat

unread,
Dec 19, 2003, 7:21:35 AM12/19/03
to
Some of you already know this, but here's a nice way to clean up
Mathematica code and output before pasting it into e-mail (or other
text programs). Omega Consulting wrote the palette involved, which
performs "copy as InputForm".

Note to Wolfram: THIS SHOULD BE BUILT IN TO THE MATHEMATICA MENUS!

I put the palette in

C:\Documents and Settings\All Users\Application
Data\Mathematica\Applications\InputForm\FrontEnd\Palettes

Step 1) Create that directory (you can use a different name for the
InputForm directory if you want, or use a directory that already
exists in that position, like Utilities).
Step 2) Select the code below (all of it, and nothing else).
Step 3) Copy it.
Step 4) Paste it into Mathematica.
Step 5) Answer yes when Mathematica asks if you want to convert the
expression.
(Then you should see a new, untitled palette on your screen.)
Step 6) Close Mathematica, and it should ask if you want to save the
untitled palette. Save it in the above directory, name it whatever you
want. I named mine InputForm, so it became InputForm.nb.
Step 7) Reopen Mathematica.
Step 8) File>Palettes should show the new palette, and you're in
bidness.

I leave the palette always open. Select anything you want to copy into
a text program, push the palette button, and paste where you want it.

If the button turns out bigger than you like, reduce the number after
"Magnification->" near the bottom of the code.

Bobby
code follows...

Notebook[{
Cell[BoxData[
ButtonBox[
RowBox[{
RowBox[{"Copy", " ", "As"}], "\n", " ", "InputForm"}],
ButtonFunction:>Module[ {cpy, cpynb, evalnb},
CompoundExpression[
Set[ cpy,
NotebookRead[
InputNotebook[ ]]],
If[
SameQ[ cpy, {}],
Return[ ]],
Set[ cpynb,
NotebookCreate[ Visible -> False]],
NotebookWrite[ cpynb, cpy],
SelectionMove[ cpynb, All, Notebook],
FrontEndExecute[ {
FrontEndToken[ cpynb, "SelectionConvert",
"InputForm"]}],
Set[ 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], Null]],
ButtonEvaluator->Automatic,
Active->True]], NotebookDefault,
CellMargins->{{Inherited, Inherited}, {7, Inherited}},
PageBreakAbove->True,
CellLabelMargins->{{12, Inherited}, {Inherited, Inherited}},
InputAutoReplacements->{
"->"->"\[Rule]", ":>"->"\[RuleDelayed]", "<="->"\[LessEqual]",
">="->"\[GreaterEqual]", "!="->"\[NotEqual]", "=="->"\[Equal]",
Inherited},
"TwoByteSyntaxCharacterAutoReplacement"->True,
Hyphenation->True,
LineSpacing->{1.25, 0},
ScriptMinSize->9,
CounterIncrements->"Text",
StyleMenuListing->None,
FontFamily->"Courier"]
},
FrontEndVersion->"5.0 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 967}},
ClosingAutoSave->True,
Editable->False,
WindowToolbars->{},
PageWidth->334,
WindowSize->{116, 56},
WindowMargins->{{Automatic, 5}, {72, Automatic}},
WindowFrame->"Palette",
WindowElements->{},
WindowFrameElements->"CloseBox",
WindowClickSelect->False,
ScrollingOptions->{"PagewiseScrolling"->True,
"VerticalScrollRange"->Fit},
ShowCellBracket->False,
CellMargins->{{0, 0}, {Inherited, 0}},
Active->True,
CellOpen->True,
ShowCellLabel->False,
ShowCellTags->False,
ImageMargins->{{0, Inherited}, {Inherited, 0}},
Magnification->1.5
]

Dr Bob

unread,
Dec 20, 2003, 6:17:53 AM12/20/03
to
Sorry about the problems. I don't have version 4.0 loaded to test this,
but...

For the first error, edit this line:

FrontEndVersion->"5.0 for Microsoft Windows"

(It may also work to just ignore the error message and save the file
anyway... that should rewrite the version for you.)

For the second problem, delete the option

"VerticalScrollRange"->Fit

(and the comma before it).

I used the same palette under version 4.0 and 4.1, and didn't consciously
add the option... so I suppose it isn't necessary.

Make both changes, then copy and paste into Mathematica as before. If that
doesn't work, somebody else on the list probably has an answer.

Bobby

On Fri, 19 Dec 2003 09:50:51 +0100, Stefan Fredriksson
<ste...@fredriksson.nu> wrote:

> Hi,
>
> Thanks for your response but it looks like mya version is to old. I have
> Mathematica4.0 and when I paste the text it tells me it was created for
> another version and that I should contact Wolfram for information on
> upgrade.
>
> I also get:
>
> ----
> Front End Message (9:49:01 on 12/19/03)
> An unrecognized option name ("VerticalScrollRange") was encountered.
> ----
>
> Regards
> Stefan
>
> Dr Bob wrote:
>
>> (Stefan: this is in response to a question you asked. I've also posted
>> it to the list.)

0 new messages