# Tag Info

12

If the first appearance of the Symbol in the Notebook is the definition, or close enough to the definition to be convenient, you could use the following Palette button to find that first appearance for whatever token the cursor is within. With[{nb := SelectedNotebook[]}, DynamicModule[{token}, Button["Find First", SelectionMove[nb, All, Word]; ...

11

This appears to be a difference in parsing between the frontend and the kernel. Compare (in a notebook) HoldForm[\[LeftCeiling]x\[RightCeiling] + 1] (* Ceiling[x] + 1 *) with Get[StringToStream["HoldForm[\[LeftCeiling]x\[RightCeiling] + 1]"]] (* Ceiling[x] (+1) *) where the latter has multiplication instead of addition. One possible workaround is ...

8

that is what the third argument of ToExpression is for: ToExpression["\\sqrt{2.0}",TeXForm,HoldForm]

8

To whom it may concern, a workaround: path = FileNameJoin[{$HomeDirectory, "Desktop", "testWorking.nb"}]; nb = Notebook[{}, Saveable -> False, NotebookEventActions -> {{"MenuCommand", "Save"} :> {}} (*the fix*) ]; Export[path, nb, "NB"] 7 Here is a way to search from within mathematica: notebooks = Quiet@FileNames["*.nb", NotebookDirectory[], 2]; Monitor[Select[ Table[{nb, StringJoin@Select[ StringSplit[Import[nb, "Plaintext"], "\n"] , ((If[#, Print["match on:", nb]]; #) &@ StringMatchQ[#, "*NIntegrate*"]) &, 5]}, {nb,notebooks}], #[[2]] ... 5 How about: Export[ StringDrop[path, -2] <> "txt", StringRiffle[ NotebookImport[path, "Input" -> "InputText"], "\n" ] ] 5 Similar approach to Mr.Wizard's but searching only code and input cells. Put that procedure inside joker.m file, as described in 72914 or as a procedure for Button in a Palette. Module[{name, nb}, nb = InputNotebook[]; Label["readName"]; name = NotebookRead[nb]; If[name === {}, FrontEndExecute@FrontEndToken[nb, "ExpandSelection"]; Goto["readName"] ... 5 UPDATE As Kuba correctly notes in the comment, with negative CellMargins we can make the cell height to be effectively zero: CellPrint@Cell[BoxData["a"], CellElementSpacings -> {"CellMinHeight" -> 0, "ClosedCellHeight" -> 0}, Background -> Hue[.8], CellMargins -> -2, CellOpen -> False, CellFrame -> 0, ShowCellBracket -> ... 4 Here is an approach which does not rely on the NBImport.exe (which actually performs importing of the NB files as "Plaintext" under the hood) and performs all the operations in the Kernel only. Currently NBImport.exe contains a bug due to which it returns$Failed when have to import a NB file with non-ASCII file path. I'm also not sure how it interprets ...

4

To replicate the Ctrl+A Enter execution behaviour automatically you can run Solve.nb from a package file, say runSolve.m, containing the code below. While Wolfram Language Scripts are straightforward, this method has the advantage that output can be saved in the notebook as if it was being run manually. (DeveloperCellInformation usage thanks to Arnoud ...

4

For producing a NB file without line breaks you can Get it as a Notebook expression, then Export it with PageWidth -> Infinity as "Package" (other possible options does not work correctly: Export ignores PageWidth -> Infinity when exporting as "NB" and corrupts the code when exporting as "Text"): Export["document.nb", Get["ExampleData/document.nb"], ...

4

Here three approachs: 1. Using comments like (* metadata *) written as plain text directly in the notebook's file. Pros: Human readable. Simple to manage. Readable from other application. If in XML format, simply to validate against a DTD. Cons: Unpredictable behaviour (well, ... a behaviour that I can't understand): sometime I have seen comments, all of ...

3

Instead of SelectionMove and NotebookSelection one can use NotebookRead[PreviousCell[]] and then cleanup the text returned by the ExportPacket. Thread @ MakeExpression[ "{" <> StringReplace[ First[FrontEndExecute[FrontEndExportPacket[NotebookRead[PreviousCell[]], "InputText"]]], {"\r\n " -> "", "\r\n" -> ","}] <> "}", ...

3

I augmented Mr.Wizard's answer with a "Back" button: With[{nb:=SelectedNotebook[]}, DynamicModule[{token,backcell}, Column[{ Button["Find First", (* Expand selection to whole word *) SelectionMove[nb,All,Word]; (* Create notebook sub-object based on current selection *) ...

3

Use CounterBox["Page", CounterFunction :> FrontEndCapitalRomanNumeral] in setting the PageFooter option as follows SetOptions[EvaluationNotebook[], PageFooters -> {{ None, Cell[TextData[CounterBox["Page", CounterFunction :> FrontEndCapitalRomanNumeral]], "Footer", CellMargins -> {{0, Inherited}, {Inherited, ...

3

As Kuba notices in the comment, undocumented FrontEndExportPacket allows conversion of a whole Notebook into plain text: nb = NotebookGet@EvaluationNotebook[]; First[FrontEndExecute[FrontEndExportPacket[nb, "PlainText"]]] "nb=NotebookGet@EvaluationNotebook[]; First[FrontEndExecute[FrontEndExportPacket[nb,\"PlainText\"]]]" But it isn't the whole ...

2

Begin may be what you need here, as it allows you to define variables inside a given Context: a = 3; Begin["MyContext"]; {a, b, c} = {1, 2, 3}; Print@{a, b, c}; End[]; Print@{a, b, c} Print@{MyContexta, MyContextb, MyContextc} {1,2,3} {1,b,c} {MyContexta,2,3} There are a couple of important caveats: If you have already given a ...

2

Here is a solution written in the spirit of the answer by george2079 but NOT relying upon the buggy NBImport.exe executable. Instead it uses FrontEnd for converting Notebooks into plain text using the findings described here: findInNBFile::cntconv = "Failed to extract plain text from 1"; findInNBFile[NBFilePath_String, stringPattern_, resPerFile_Integer: ...

2

A couple of additional solutions. The first, with FindList, is probably the simplest and quickest. Using FindList searchDir = "<NB dir>"; fnames = FileNames["*.nb", searchDir, 2]; Length@fnames sres = {#, FindList[#, {"curve"}, WordSearch -> False]} & /@ fnames; sres = Select[sres, Length[#[[2]]] > 0 &]; Grid[sres, Dividers -> All, ...

2

What you want, I think, is the cell option ShowCellLabel -> False. You can edit the stylesheet to add the option to the styles "Input" and "Output" in the "Printout" environment. Or you can add them to a notebook, assuming it has the default style definitions, as follows: SetOptions[EvaluationNotebook[], StyleDefinitions -> ...

2

Evaluate this and then save as another nb, open the new nb file, and then save as PDF SetOptions[InputNotebook[], CellLabelAutoDelete -> True];

2

It is not a good idea to try to run a notebook in command line mode. Whether or not it is possible, it is just not a good idea because notebooks can only be handled by the Front End, which is not a command line tool. If you go this route anyway, expect difficulties. The usual way is to extract the code you want to run into a plain text .m file and run ...

2

It seems to me that setenv is being used here to set the values of a series of helper variables that are then used by the other functions in the code. This (is awful but) works within a single notebook because all those variables are visible to all functions. I suspect, however, that once you put the code in a package, you run into context problems. Those ...

2

Another way which makes a docked cell (much like a package notebook): SetOptions[EvaluationNotebook[],DockedCells -> Cell[ BoxData@ ToBoxes@ DynamicModule[{cell$}, Grid[{ {Dynamic@ActionMenu["Functions", (#[[1]]:>(SelectionMove[EvaluationNotebook[],Before,Notebook,AutoScroll->False]; ... 2 Here is a slight modification of Karsten's answer. Previously I felt it was too similar, but I suppose it cannot hurt to post it. The main difference is that I avoid MakeExpression. I also like the alternative in your question, which is to use StringToStream. read[cObj_] := DeleteCases[#, HoldComplete[Null]] &@( ToExpression[#, InputForm, ... 2 There is no reason to keep your Input inside of Manipulate, you don't want a dialog show up every time it updates, right? Probably you need something like this: ClearAll[f, x, \[Alpha]] f[x_, \[Alpha]_] = Input["Please input a function of x to plot with one parameter \ \[Alpha] to manipulate"]; Manipulate[Plot[f[x, \[Alpha]], {x, 0, 1}], {\[Alpha], 0, ... 2 This gives the recently opened files as a list of rules: Lookup[Options@$FrontEnd, NotebooksMenu] Just the file names: First /@ Lookup[Options@$FrontEnd, NotebooksMenu] FileNameJoin instead of FrontEnd`FileName: (only tested on windows) FileNameJoin[(Append @@ ((First@Last[#])[[;; 2]]))[[2 ;;]]] & /@ Lookup[Options@$FrontEnd, NotebooksMenu]

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