Hot answers tagged

23

First of all, I agree, as OP mentioned in his comment, ANTLR is one of the proper ways to go. Now for this specific task, it might be easier to just compose a parser in the "dirty" way, except we don't have to go so far to regex. In my opinion Mathematica's StringExpression is much more powerful and very suitable for the job. All we have to do is (as OP ...


22

You can setup CellEpilog to automatically advance a cell after evaluating the current one. That way, you don't need to press the down arrow after evaluating a cell. SetOptions[EvaluationNotebook[], CellEpilog :> SelectionMove[EvaluationNotebook[], Next, Cell]]


22

This syntax was deprecated in the version 6.0 era. According to the legacy documentation, For example, in version 5.2, the following strings are interpreted differently string1 = "first line second line" string2 = "\<first line second line\>"


21

Intro One day I was playing with Developer` package and found DateSetter which uses some kind of floating elements that I found useful. After taking a look at a source code I found out it was FrontEnd`AttachedCell. From the code one could learn enough to create something useful: Usage FrontEnd`AttachCell[ parentObject, (*Box or Cell ...


18

The following seems to work, however I think it's not general enough: At a clean nb, enter: For[i = 0, i < 4, i++, Print[{i, {33, i}}]] For[i = 0, i < 4, i++, Print[Graphics[Circle[], ImageSize -> 20]]] And then retrieve the Print[ ] output as: c = Cases[NotebookRead /@ Cells[GeneratedCell -> True], Cell[___, "Print", ___]]; ToExpression /@ ...


17

You can use this to create a functionality which will fit your need the best. Here's how you can preview your input cell with c highlighted Red. CellPrint[ NotebookRead @ PreviousCell[] /. "c" -> InterpretationBox[ StyleBox["c", FontColor -> RGBColor[1, 0, 0]], c ] ] You can even evaluate such cell. General ...


17

Update I have incorporated Kuba's improvement into the code. Here is how I would do it. In a working notebook (not the target notebook) put the following code. With[{nb = target}, SetOptions[nb, ShowCellBracket -> False]; SetOptions[#, CellOpen -> False] & /@ Cells[nb, CellStyle -> "Input"];] With[{nb = taget}, SetOptions[nb, ...


16

"Style" /. Developer`CellInformation[nb] where nb is the NotebookObject for the notebook you care about. Since you could have multiple cells selected, this will always return a list. It's also possible to have no cells selected, in which case CellInformation will return $Failed and the above code would throw an error.


16

This took some digging but at least in Version 7 the FrontEnd command is FT, e.g.: FE`FT["Plot"] You can read the definition with Definition[FE`FT]. If you want only the Box form itself we can modify it accordingly (here for version 7): templateCell[name_String] := Module[{template}, If[! StringQ@ToExpression[name <> "::usage"], $NewMessage[...


16

Typesetting in Text cells Cell[TextData[Cell[BoxData[ FormBox[ RowBox[{ FractionBox["1", "N"], RowBox[{ UnderoverscriptBox["\[Sum]", RowBox[{"i", "=", "1"}], "N"], FractionBox[ RowBox[{ SubsuperscriptBox[ OverscriptBox["x","~"], "j", "i"], "(", RowBox[{"k", "|", "k"}], ")"}], SqrtBox[ ...


16

The case when the evaluation is finished Some of my calculations take hours or even days, so I don't want to restart the entire evaluation just to add Timing[] to it. If your code generates an Output Cell then you can find at least an upper bound of the evaluation time as the difference between last CellChangeTimes of the Output and Input Cells. It can ...


15

If your keyboard has a numeric keypad, or a way to emulate one by using a function key, you can use Shift+Enter on the numeric keypad. This keystroke will evaluate a cell if you're in an evaluatable cell, or move to the next evaluatable cell if you're not. It would still be two keystrokes to move then evaluate, but it'd be the same keystroke.


15

You can use something like this. (I have added extra steps to demonstrate practical usage.) Selectable code x = 3 y = x + 2; Clear[x, y, z] SelectionMove[EvaluationNotebook[], Previous, Cell, 3]; z = ToExpression@First@NotebookRead[EvaluationNotebook[]]; y + z Addendum Further to xzczd's comment, you can also use a cell tag :-


15

TL;DR; To set ShowGroupOpener on a global level, previously done by CurrentValue[$FrontEnd, ShowGroupOpener] = True, now use: CurrentValue[$FrontEnd, {StyleHints, "GroupOpener"}] = "OutsideFrame" This is what preferences menu does too. Further explanation The direct cause is Core.nb / All / Working style which, as a stylesheet setting, comes between the ...


15

Evaluate SetOptions[$FrontEnd, EvaluationCompletionAction -> "ShowTiming"] and then the evaluation time for the last evaluation will be shown in the lower left corner of the notebook: Like many front end options, this setting is sticky. Set it once, and forget it; it also works across all versions of Mathematica installed.


14

Version 9 offers a couple of new ways to access cells that are useful to meet the needs of this question. The first way involves the use of the Cells and EvaluationCell functions. They can be used in the present context like this: previousCell[] := Cells @ EvaluationNotebook[] /. {___, prev_, EvaluationCell[], ___} :> ToExpression @ First @ ...


13

It is not straightforward to access the clipboard contents but one way, that doesn't involve writing and reading from temporary notebooks is to use the undocumented ClipboardNotebook function: CellPrint /@ StringSplit[NotebookGet[ClipboardNotebook[]][[1, 1, 1]], "\n"]; See also this answer which mentions some caveats. This prints strings as text cells. ...


12

Another possibility is to modify the notebooks style sheet by defining a new "Screen Environment" that hides cell brackets and closes input cells: SetOptions[ EvaluationNotebook[], StyleDefinitions -> Notebook[{ Cell[StyleData[StyleDefinitions->"Default.nb"]], Cell[StyleData[All, "Working"], MenuCommandKey->"D"], ...


11

This is very straightforward in v9 using Cells and CellObject. Let's start with a notebook with a disjoint selection of the type you're describing: nb = NotebookPut[ Notebook[{ Cell["a", CellTags -> "x"], Cell["b"], Cell["c", CellTags -> "x"]}]]; NotebookFind[nb, "x", All, CellTags] Now, we can get CellObjects for the selected cells ...


11

I don't know if any of them can be callled documented but I know three ways to do this: mentioned above: FrontEndToken way: ( SelectionMove[#, All, Cell]; FrontEndTokenExecute[EvaluationNotebook[], "Style", "Title"] ) & /@ Cells[CellStyle -> "Section"] or SelectionSetStyle way: ( SelectionMove[#, All, Cell]; ...


11

There are a number of nonlinear filters that are possible. One that might help is the RidgeFilter img=Import["http://i.stack.imgur.com/IyUPZ.jpg"]; ImageAdjust[RidgeFilter[img, 5]] Let's now clean it up a bit: Pruning[Thinning[SelectComponents[Binarize[ImageAdjust[RidgeFilter[img, 5]], 0.094], "Count", # > 800 &]]] The above binarizes the ...


11

Thanks to andre's comment (where this link is provided), I now see the effect of those delimiters (I tested it in Mathematica 11 and also some earlier versions). When I add 2 newlines to the box representation of the cell: Cell[BoxData["\"\<a bc\>\""], "Input", CellChangeTimes->{{3.662918813714031*^9, 3.6629188530623317`*^9}}] and switch back ...


11

Here is a quick way of doing it: NotebookFind[nb = EvaluationNotebook[], "Print", All, CellStyle]; CreateDocument[NotebookRead[nb]]


11

You can use StyleKeyMapping to easily switch back and forth from "Input" cells to your "CustomInput" cell. For example: Cell[StyleData["Input"], StyleKeyMapping->{ "=" -> "WolframAlphaShort", "*" -> "Item", ">" -> "ExternalLanguage", "Tab" -> "CustomInput" } ] Cell[StyleData["CustomInput"], ...


10

More stable answer, in case of images and stuff evaluated in place in input cells: NotebookDelete /@ Select[Cells[GeneratedCell -> False], StringMatchQ[ First@ FrontEndExecute[ FrontEnd`ExportPacket[NotebookRead@#, "InputText"]], (" " | "\t" | "\r" | "\n" | "\[IndentingNewLine]") ... ] & ] It may be slower than the original ...


10

There is a special cell attribute called CellID. I would suggest using this instead of cell tags to avoid the problem that you mentioned with cell tags being inherited. Here's an example of how Select can be used to retrieve a cell with a specific cell ID: nb = CreateWindow[]; cells = <| "name" -> RandomInteger[10^6], "status" -> ...


10

Here's beta version, basic functionality is delivered. I have to polish it but probably I won't have time for that this year. It has to be packed into self contained module and styling options have to be enabled. I will update a nice description of an approach too, but meanwhile, if anything is not clear, feel free to ask. ActionNestedMenu[ "Test menu" -&...


10

Summary of the all available information In the hoarier days space-like characters (spaces, newlines, tabs) inside strings were interpreted on input in an odd way: for example single newlines followed by spaces or tabs were converted to a single space. The \<\> syntax was introduced as a way to avoid this: between \< and \> the space-like ...


10

You don't have to write all your code within ParallelSubmit. You can wrap your code in Module or Block and assign it to a variable using SetDelayed (:=) so it won't be evaluated immediately. Here is a toy example: eval1 := PrimeQ[528973465287364528736543] eval2 := Module[{}, Pause[2]; 3] evaluators = ParallelSubmit[{eval1, eval2}] You then run the ...


10

You can increase the CellMargins for the styles "Input" and "Output" in your style sheet to accommodate the increased size of the cell labels. For example, the following setting: CellMargins -> {{80, 10}, {10, 5}} fixes the issue for me with a Magnification of 2. If you don't want to mess around with editing the style sheet, you could evaluate the ...


Only top voted, non community-wiki answers of a minimum length are eligible