New answers tagged

0

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]


8

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


3

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 ...


5

How about: Export[ StringDrop[path, -2] <> "txt", StringRiffle[ NotebookImport[path, "Input" -> "InputText"], "\n" ] ]


3

You can execute the following inside the notebook SetOptions[EvaluationNotebook[], ShowCellLabel -> False] Alternatively, you can change the options of the desired notebook (testnb1.nb in the example below) by executing SetOptions[...] in a different notebook (untitled-3.nb in the example): Or, use the Option Inspector (in the Format Menu) to change ...


3

Here is a function came from this page setFont[fontFamily_, fontSize_] := With[ { styleNB = Notebook[{ Cell[StyleData[StyleDefinitions -> "Default.nb"]], Cell[StyleData["StandardForm"], FontFamily -> ToString[fontFamily], FontSize -> ToExpression[fontSize]]} ], styleSheetName = FileNameJoin[ ...


8

This MathGroup discussion should answer your question, so I'll cite it here: On Tue, 29 May 2012 05:47:52 -0400 (EDT), JCW wrote: Please forgive my dragging up ancient history: I have been using Mathematica from version 2.2 through 7.0. I remember at least one (maybe two?) format conversions that were necessary to update old ...


1

I felt like it is something very fundamental for working with UI developement in MMA so I asked WRI Support to help me. It took a while but I received a very good answer, which is to suspend DynamicUpdating when Export takes place. [...] For the effect you want, turn off the global DynamicUpdating option for the fronend just before the call to ...


1

Here is another solution in the spirit of the answer by M.R. (should work starting from Mathematica version 7): AbsoluteImageDimensions[img_Image] := Module[{m = CurrentValue[Magnification], w0, h0, w}, {w0, h0} = ImageDimensions[img]; w = Options[img, ImageSize][[1, 2, 1]]; {m {w, w*h0/w0}, 100 (m w/w0)^2}] And here is a better version ...


1

According to the Documentation, you should set CellLabelAutoDelete -> False for making cell labels permanent: Create a notebook with the setting CellLabelAutoDelete -> False: nb = CreateDocument[{ExpressionCell[Defer[1 + 1], "Input"], ExpressionCell[Defer[2 + 2], "Input"]}, CellLabelAutoDelete -> False] When inputs are evaluated, ...


0

"In/Out" labels are created, roughly, when you evaluate/create cells. And according to CellLabelAutoDelete documentation: If you edit a previously evaluated input cell, its cell label is cleared That's what is happening when you paste copied image. A default cell is created, with a label, but then the cell is edited by pasting your image. This clears ...


6

You can't. This feature only works with certain programs and as of version 10.4 Mathematica is not one of them. Maybe the coming Mac front end improvement mentioned in this presentation will fix that, but this is purely a guess on my part. As a workaround you can use window control software such as Spectacle, which makes it easy to arrange notebooks in a ...


3

Here's a slightly more limited approach, that doesn't require changing the stylesheet or environment of the notebook. The following styles are bulleted, with increasing levels of indentation: Subchapter Item Subitem Subsubitem Subchapter is usually accessible via a keyboard shortcut; check Format > Style for specifics. Item is automatically used as the ...


2

InitializationGroup vs group of InitializationCells If you create a new cell in an InitializationGroup it will automatically become an InitializationCell. For the group of InitializationCells you will get a default one, which you can turn into another InitializationCell or not. A set of InitializationCells vs one InitializationCell. I can't find any ...


1

Using Alexey's pattern: AbsoluteImageDimensions[img_] := Module[{m = CurrentValue[Magnification]}, Cases[{ToBoxes@img}, GraphicsBox[___, OrderlessPatternSequence[ Verbatim[Rule][ImageSizeRaw, {w0_, h0_}], Verbatim[Rule][PlotRange, _], Verbatim[Rule][ImageSize, {w_, _}]]] :> {m {w, w*h0/w0}, 100 (m w/w0)^2}, ...


2

Here is one approach (Mathematica version 10 is required). Paste the following code as the next cell after the cell with your image and evaluate: cell = NotebookRead[PreviousCell[]]; m = CurrentValue[Magnification] Cases[cell, GraphicsBox[__, OrderlessPatternSequence[ImageSize -> {w_, _}, ___, ImageSizeRaw -> {w0_, h0_}], ___] :> {m {w, ...


4

There is a straightforward way to set CellMargins to be zero: DialogInput[ DialogNotebook[{ExpressionCell[Pane[RandomImage[], ImageMargins -> 8], CellMargins -> 0]}]] Instead of ImageMargins we can rely on CellFrameMargins: DialogInput[ DialogNotebook[{ExpressionCell[RandomImage[], CellMargins -> 0, CellFrameMargins -> 8, ...


2

As noted by ilian, this behaviour is explained in StoringAndTrackingPaletteStates tutorial. Shortly, CurrentValue[$FrontEnd, System`PalettesMenuSettings] keeps those values cached. In order to achieve what I described in the question we have to drop an entry that coresponds to our palette. It doesn't really matter when it's done. Just do it before you ...


3

I gave up looking for neat solution. Here's brute force. Since the bottom CellMargins are not respected then let's not use any! :) We can use Pane and its ImageMargins to take control over padding. DialogInput[ DynamicModule[{}, Pane[RandomImage[], ImageMargins -> 8], Initialization :> (SetOptions[EvaluationCell[], CellMargins -> ...


8

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\>"


2

It really expects that you have some buttons along the bottom. DialogInput[Column[{Pane @ RandomImage[], Button["OK", DialogReturn[0]]}]] but you can do it this way DialogInput[Column[{Pane @ RandomImage[], ""}]] Update I Think it looks better with the bottom margin a bit larger than the top, but if you are being picky about equal margins, try ...


0

Here is a Mathematica expression in a meta-notebook, based on the Wolfram-supplied "StandardReport" style, as an example that creates another Notebook with all the styles set up the way I want them. I store this meta-notebook in the same place I store all my other notebooks instead of in a magical directory on my path, so it gets backed up and survives ...


3

You can use SetOptions directly on any Notebook like this: myNewCell = Cell@RawBoxes@ ToBoxes@Style["Title of talk, Conference, Location, Date", 22, Italic, FontColor -> Blue, FontFamily -> "Times"]; SetOptions[EvaluationNotebook[], DockedCells -> myNewCell] Since DockedCells are not editable but may still contain dynamics, this is ...


0

(The full code is at the end of this post, put together into a shortcut ctrl-| that copies the cell containing the selection, wraps the selection in brackets, and places the cursor before the brackets so as to allow the user to type some function to apply to that subexpression.) My solution is by no means pretty nor bulletproof. Most checks are done by ...


4

You can get this behaviour by setting StucturedSelection to True at the Global`, Notebook, or Cell level. See the Options for Expression Input and Output guide. This can be done with the Options Inspector or with SetOptions. To set it at the notebook level: SetOptions[EvaluationNotebook[], StructuredSelection -> True] After this is done you will only ...


4

The workaround suggested by Algohi works but it leads to reevaluation of the entire LogLogPlot each time you open a Notebook. The following workaround avoids this: With[{g = Labeled[LogLogPlot[x, {x, 10^-5, 1}], "Test"]}, Dynamic@g] Another workaround is to place this Graphics as Inset inside of another Graphics object: pl = LogLogPlot[x, {x, 10^-5, 1}]; ...


3

Just to give back to community, here's a little piece of code: Item[KeyEvent["e", Modifiers -> {Control}], FrontEndExecute @ Module[{nb, t}, nb = InputNotebook[]; SelectionMove[nb, All, Expression]; t = NotebookRead[SelectedNotebook[]]; NotebookWrite[nb, ButtonBox[RowBox[{"(", CounterBox["Section", t], ".", ...


3

It seems that sometimes Cells and friends are not smart enough to be aware of the parent notebook, supplying the code with EvaluationNotebook gives something working for me: Tooltip["TEST!", Dynamic @ Rasterize @ NotebookRead @ First @ Cells[ EvaluationNotebook[], CellTags -> "TestTag"] ] Is this what you are after?


6

LogLogPlot plots contain a dynamic objects which when you open the notebook, the security of Mathematica prevents the dynamic objects from being updated. Check this What you can do is wrap your plot with dynamic and when opened again and when you click Enable Dynamic, you will get the correct plot. Dynamic@Labeled[LogLogPlot[x, {x, 10^-5, 1}], "Test"]


7

In case you want to plot in place you can use something like: Button["Plot", NotebookWrite[ InputNotebook[], ToBoxes @ Plot[ Evaluate @ ToExpression @ CurrentValue @ "SelectionData", {x, 0, 10} ] ] ] You may want to add Method -> "Queued" for more complicated plot to avoid timeout. And if you want x from ...


7

According to the documentation, "PasteButton, evaluates its arguments in an ordinary way, so that expr is immediately evaluated" It is like you evaluate Plot[\[SelectionPlaceholder], {x, 0, 10}] which will give empty plot. This could be one solution: PasteButton["Plot", Defer[Plot[\[SelectionPlaceholder], {x, 0, 10}]]]


3

Just a slight modification of Mechanical snail's answer here, (I need a more creative username...) to make the output match the input exactly. In[1]:= {{2}, {3}} // MatrixForm In[2]:= ToExpression[InString[1], StandardForm, Defer] // DisplayForm Which you can copy/paste, or just append //CopyToClipboard to the command above and you can just paste it ...


2

I don't think it is possible by reading the In, since the information is stored in a list of HoldPattern expression, and your input is not preserved. But if you did not delete the input cell, it is possible to obtain your input by doing this: CellPrint@ Cell[Cases[NotebookRead@Cells[], Cell[x_, _, _, CellLabel -> "In[42]:="] -> x][[1]], "Input"] ...


1

Manipulate is HoldAll and the body isn't evaluated till it is displayed. That's because effectively there is Dynamic[body]. I once explained that a little in Manipulate in Manipulate. So inside the package it won't do anything, as no output is generated. You can see this here: ClearAll[x]; Manipulate[x = 5, {y, Null}]; Pause[1]; x Manipulate[x = 5, {y, ...


6

You can temporarily change CellContext of the notebook with SetOptions or CurrentValue but if the notebook isn't opened yet, this is faster: Module[{path, nb} , path = (*path*); nb = NotebookOpen[ path, CellContext -> "Global`", Visible -> False]; NotebookEvaluate[nb, InsertResults -> False]; NotebookClose[nb] ] You can use ...


2

I believe that I now know the answer. In addition to setting InitializationCellEvaluation option to True InitializationCellWarning option to False with the notebook selected, you also need to set these same values at the Global Preference level.



Top 50 recent answers are included