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

Mathematica 9: bug in merging cells

212 views
Skip to first unread message

Fred Simons

unread,
Dec 4, 2012, 4:09:37 AM12/4/12
to
When writing a larger program, I usually test the single steps in
separate cells, then merge these cells and localize the variables by
wrapping the contents of the merged cells in a Module. By doing so in
Mathematica 9, due to a bug in merging cells, I lost a lot of code. I
reported this bug to WRI two weeks ago. It is not yet repaired in the
new release, so I thought I would mention this annoying bug here as well.

This is an example (Mathematica 9 for Windows, I am not aware if this
happens for other systems too).

Construct two input cells, the first one containing

a=1;
(* comment *)
b=2;

and the second one

c=3;

When merging these two cells the contents ending with the comment is
shown in an orange rectangle, with the error message that there is a
RowBox with an invalid first argument. I cannot see any reason why this
merging of cells could not be undone with ctrl-Z, but it cannot and
therefore part of my code was gone.

In this simple example I could see how to fix it. Toggle ctrl-E for
seeing the box structure. Place a } just behind the RowBox with the
comment and a { behind the very first RowBox[, that is followed on the
next line with another RowBox.

During writing this message, I found that the same happens when you try
to copy and paste the first cell.

Fred Simons
Eindhoven University of Technology

Murray Eisenberg

unread,
Dec 5, 2012, 3:10:10 AM12/5/12
to
I'm seeing exactly the same cell-merge bug in Mathematica 9 under OS X
(10.8.2).

It has nothing to do with the (* comment *) per se. Exactly the same
thing happens if in the first cell you replace the comment line with a
blank line.

On the other hand, I don't get any error with copy-and-paste, whether
with the (* comment *) or with just a blank line there.
---
Murray Eisenberg
mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2838
(W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305






David Reiss

unread,
Dec 5, 2012, 3:10:48 AM12/5/12
to
Just a quick observation to note that one does not need the comment
between the first two code lines, the presence of a carriage return is
all that's needed to create the error upon merging the two cells.
Thus, the first cell would contain

a = 1;

b = 2;

and the second cell would have any code in it: e.g.,


c = 3;

Then merge the two and the error box appears.

--David

Rafapa

unread,
Dec 5, 2012, 3:11:49 AM12/5/12
to
Same problem with Mathematica 9.0.0 under Linux x86 (64 bit).

Rafael R. Pappalardo
Univ. of Seville (Spain)

Rolf....@gmail.com

unread,
Dec 6, 2012, 4:57:18 AM12/6/12
to

What I really like about Mathematica is that it can often fix its own bugs:
Evaluate the following in your notebook

Button["Fix9", (NotebookWrite[#1,
NotebookRead[#1] //.
HoldPattern[RowBox[a_, b__]] :> RowBox[{a, b}]] & ) /@
Cells[CellStyle -> "Input"]]

Clicking on it will magically restore wrongly merged cells.

But I hope that with 9.0.1 this will be fixed.

Rolf Mertig
GluonVision GmbH
(web)Mathematica consulting
Berlin, Germany

David Reiss

unread,
Dec 6, 2012, 4:55:58 AM12/6/12
to
I reported the bug.

rolf....@gmail.com

unread,
Dec 7, 2012, 1:36:58 AM12/7/12
to
Running this and restarting Mathematica will provide a keyboard
shortcut Command Option m (Mac) or Command (or WindowsKey) Optiom m
(Windows)
or Mod1 Alt m on Linux as an alternative to the buggy Control Shift
m

I also added a key for deleting all outputs and one for quitting the
kernel since I find this useful.

Rolf
P.s.: This can also be invoked most conveniently as
Import["http://www.mertig.com/mykeys.m"]

(* ******************************************************* *)
(* ::Package:: *)

(* ::Section:: *)
(*Keyevents for M9*)


(* ::Text:: *)
(*Author: Rolf Mertig, http://www.mertig.com, GluonVision GmbH,
Berlin, Germany*)


(* ::Text:: *)
(*Executing the code below generates a KeyEventTranslations.tr in a
subdirectory in $UserBaseDirectory *)


$OverWriteUserBaseDirectoryKeyEventTranslations = True;
mymenuitems="
(* Delete all Output, Message and Print cells in the selected
notebook
Basically my answer from http://mathematica.stackexchange.com/a/13992/29

Windows: Command (Windows-Key) Alt d deletes all Output and
Message and Print Cells
MacOSX: Command Option d

*)
Item[KeyEvent[\"d\", Modifiers -> {Option, Command}],
KernelExecute[
Module[{nb = SelectedNotebook[]},
Scan[Function[c, If[NotebookFind[nb, c, All,
CellStyle, AutoScroll -> False] =!= $Failed,
NotebookDelete[nb, AutoScroll ->
False]]
],
{\"Message\", \"Output\", \"Print\"}
];
SelectionMove[nb,After,Notebook];
]
], MenuEvaluator -> Automatic ],\n

(* Merge cells fix for M9; instead of
Control Shift M
Windows: Command Alt m
MacOSX: Command Option m
can be used instead: *)
Item[KeyEvent[\"m\", Modifiers -> {Command,Option}],

KernelExecute[
FrontEndExecute[FrontEndToken[\"CellMerge\"]];
Module[{ce=Cells[CellStyle -> \"Input\"]},
Scan[Function[x,NotebookWrite[x,ReplaceRepeated[NotebookRead[x],

RuleDelayed[HoldPattern[RowBox[Pattern[a,Blank[]],Pattern[b,BlankSequence[]]]],RowBox[List[a,b]]]]]],ce];
];
] , MenuEvaluator -> Automatic ],


(* Quit the kernel by Command Alt k
from http://mathematica.stackexchange.com/questions/6224/best-way-to-add-keyevents-and-faster-quit?rq=1
*)
Item[KeyEvent[\"k\", Modifiers -> {Command,Option}],
KernelExecute[ToExpression[\"Quit[]\"]
], MenuEvaluator -> Automatic
],


";
With[{os =
Switch[$OperatingSystem,"MacOSX","Macintosh","Windows","Windows","Unix","X"]},
Quiet@CreateDirectory@FileNameJoin[{$UserBaseDirectory,"SystemFiles","FrontEnd","TextResources",os}];
mykeyeventtrans=FileNameJoin[{$UserBaseDirectory,"SystemFiles","FrontEnd","TextResources",os,"KeyEventTranslations.tr"}];
If[$OverWriteUserBaseDirectoryKeyEventTranslations===True,
If[FileExistsQ[mykeyeventtrans],DeleteFile@mykeyeventtrans];
CopyFile[FileNameJoin[{$InstallationDirectory,"SystemFiles","FrontEnd","TextResources",
os,"KeyEventTranslations.tr"}],mykeyeventtrans]
]];
keytext=Import[mykeyeventtrans,"Text"];
mykeytext=StringReplace[keytext,"EventTranslations[{":>StringJoin["EventTranslations[{\n",mymenuitems,"\n"]];
Export[mykeyeventtrans,mykeytext,"Text"];

Print["Please quit the FrontEnd and restart.
Then, for Windows ( Command = Windows Key )
Command Alt d deletes all Output
and Message and Print Cells
Command Alt m merges Cells, like
Control Shift m, but fixes a M9 bug
Command Alt k quits the kernel
for MacOSX :
Command Option d deletes all Output
and Message and Print Cells
Command Option m merges Cells, like
Control Shift m, but fixes a M9 bug
Command Option k quits the kernel

Fox X11 :
Mod1 Alt d deletes all Output
and Message and Print Cells
Mod1 Alt m merges Cells, like
Control Shift m, but fixes a M9 bug
Mod1 Alt k quits the kernel
"];
Quit[];

0 new messages