Skip to main content

notebooks - NotebookEvaluate with InsertResults -> True from the command line


Suppose I have a notebook template.nb like this:


enter image description here


and I want to evaluate this notebook from the command line. So I wrote this Mathematica script:


UsingFrontEnd[NotebookEvaluate["C:\\Users\\delfinog\\Desktop\\template.nb", 
InsertResults -> True]]

And I run the script like this (Windows 7):



enter image description here


C:> "C:\Program Files\Wolfram Research\Mathematica\10.2\wolfram.exe" -script C:\Users\delfinog\Desktop\mma-script.wl

My expectation is that I should be getting this:


enter image description here


but instead, I get this:


enter image description here


This is the complete output cell


Graphics[{{{}, {}, {Directive[Opacity[1.], RGBColor[0.368417, 0.506779, 0.709798], AbsoluteThickness[1.6]], Line[{{2.040816326530612*^-8, 2.040816326530612*^-8}, {0.000306717908041361, 0.000306717908041361}, {0.0006134154079194566, 0.0006134154079194566}, {0.001226810407675648, 0.001226810407675648}, {0.002453600407188031, 0.002453600407188031}, {0.004907180406212797, 0.004907180406212797}, {0.009814340404262328, 0.009814340404262328}, {0.01962866040036139, 0.01962866040036139}, {0.040908355415730624, 0.040908355415730624}, {0.060777881089422996, 0.060777881089422996}, {0.08025764554305448, 0.08025764554305448}, {0.10138846501985709, 0.10138846501985709}, {0.12110911515498282, 0.12110911515498282}, {0.1424808203132797, 0.1424808203132797}, {0.16346276425151565, 0.16346276425151565}, {0.18303453884807477, 0.18303453884807477}, {0.204257368467805, 0.204257368467805}, {0.22407002874585835, 0.22407002874585835}, {0.24349292780385082, 0.24349292780385082}, {0.2645668818850144, 0.2645668818850144}, {0.28423066662450114, 0.28423066662450114}, {0.305545506387159, 0.305545506387159}, {0.32647058492975595, 0.32647058492975595}, {0.34598549413067603, 0.34598549413067603}, {0.36715145835476726, 0.36715145835476726}, {0.3869072532371816, 0.3869072532371816}, {0.40831410314276706, 0.40831410314276706}, {0.42933119182829166, 0.42933119182829166}, {0.4489381111721394, 0.4489381111721394}, {0.4701960855391582, 0.4701960855391582}, {0.49004389056450015, 0.49004389056450015}, {0.5095019343697813, 0.5095019343697813}, {0.5306110331982336, 0.5306110331982336}, {0.550309962685009, 0.550309962685009}, {0.5716599471949555, 0.5716599471949555}, {0.5926201704848412, 0.5926201704848412}, {0.6121702244330499, 0.6121702244330499}, {0.6333713334044297, 0.6333713334044297}, {0.6531622730341328, 0.6531622730341328}, {0.6725634514437749, 0.6725634514437749}, {0.6936156848765882, 0.6936156848765882}, {0.7132577489677245, 0.7132577489677245}, {0.7345508680820321, 0.7345508680820321}, {0.7544338178546627, 0.7544338178546627}, {0.7739270064072324, 0.7739270064072324}, {0.7950712499829733, 0.7950712499829733}, {0.8148053242170373, 0.8148053242170373}, {0.8361904534742725, 0.8361904534742725}, {0.8571858215114467, 0.8571858215114467}, {0.8767710202069441, 0.8767710202069441}, {0.8980072739256126, 0.8980072739256126}, {0.9178333583026043, 0.9178333583026043}, {0.937269681459535, 0.937269681459535}, {0.9583570596396369, 0.9583570596396369}, {0.978034268478062, 0.978034268478062}, {0.9783774827142147, 0.9783774827142147}, {0.9787206969503675, 0.9787206969503675}, {0.9794071254226728, 0.9794071254226728}, {0.9807799823672838, 0.9807799823672838}, {0.9835256962565057, 0.9835256962565057}, {0.9890171240349493, 0.9890171240349493}, {0.989360338271102, 0.989360338271102}, {0.9897035525072548, 0.9897035525072548}, {0.9903899809795602, 0.9903899809795602}, {0.9917628379241712, 0.9917628379241712}, {0.994508551813393, 0.994508551813393}, {0.9948517660495457, 0.9948517660495457}, {0.9951949802856985, 0.9951949802856985}, {0.9958814087580039, 0.9958814087580039}, {0.9972542657026149, 0.9972542657026149}, {0.9975974799387677, 0.9975974799387677}, {0.9979406941749204, 0.9979406941749204}, {0.9986271226472259, 0.9986271226472259}, {0.9989703368833786, 0.9989703368833786}, {0.9993135511195312, 0.9993135511195312}, {0.999656765355684, 0.999656765355684}, {0.9999999795918367, 0.9999999795918367}}]}}}, {DisplayFunction -> Identity, AspectRatio -> GoldenRatio^(-1), Axes -> {True, True}, AxesLabel -> {None, None}, AxesOrigin -> {0, 0}, DisplayFunction :> Identity, Frame -> {{False, False}, {False, False}}, FrameLabel -> {{None, None}, {None, None}}, FrameTicks -> {{Automatic, Automatic}, {Automatic, Automatic}}, GridLines -> {None, None}, GridLinesStyle -> Directive[GrayLevel[0.5, 0.4]], Method -> {DefaultBoundaryStyle -> Automatic, DefaultMeshStyle -> AbsolutePointSize[6], ScalingFunctions -> None}, PlotRange -> {{0, 1}, {0., 0.9999999795918367}}, PlotRangeClipping -> True, PlotRangePadding -> {{Scaled[0.02], Scaled[0.02]}, {Scaled[0.05], Scaled[0.05]}}, Ticks -> {Automatic, Automatic}}]


So the figure is there, but it is not being displayed. Is there a way to make this work? I was thinking that the UsingFrontEnd command should avoid this situation but there seems to be something else missing.


Motivation: I am developing a report generation system that should be running automatically late at night. As the built-in template system does not work well from MathematicaScript (CASE:3432062) and using ScheduledTasks on my interactive Mathematica session has been unreliable, I am exploring using NotebookEvaluate with the InsertResults -> True option as an alternative template system.




Comments

Popular posts from this blog

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...