Hot answers tagged

28

Assuming nb is your notebook object, then this will do what you want without touching the clipboard: First[FrontEndExecute[ FrontEnd`ExportPacket[NotebookSelection[nb], "InputText"]]] Some notes about this solution: It preserves evaluation semantics precisely, regardless of typesetting. It does not dirty the clipboard If you prefer to get the ...


16

str = {"1,2,3,5,10,12,13,17,26,30,32,41,42,43,113,115,121,125"} Flatten@ToExpression@StringSplit[str, ","] Short explanation: After executing StringSplit you get a list of separated "StringNumbers" like {{"1", "2", ... "125"}} ToExpression converts these "StringNumbers" to Integers. Flatten removes the outermost brackets. You can even omit Flatten ...


14

The coolest way is to check the answer to this question by David Carraher. I am shamelessly stealing his code here to write a function that gives you rules for up to maxNumber: ordinalRule[maxNumber_Integer] /; maxNumber > 0 := Block[{p}, Thread[ Function[{x}, x -> StringSplit[SpokenString[p[[#]]]][[2]] &[x] // Quiet] /@ ...


13

TeXForm is indeed your friend. It even gives you nicely formatted code: Table[RandomInteger[10], {3}, {4}] // TeXForm gives (* \left( \begin{array}{cccc} 9 & 5 & 10 & 9 \\ 6 & 10 & 3 & 9 \\ 9 & 5 & 9 & 7 \\ \end{array} \right) *)


12

data = FinancialData["SPY", "Jan. 1, 2011"] /. {d_List, v_} :> {AbsoluteTime@d, v}; model = a x^4 + b x^3 + c x^2 + d x + e; fit = FindFit[data, model, {a, b, c, d, e}, x] modelf = Function[{x}, Evaluate[model /. fit]] Plot[modelf[x], {x, Min@data[[All, 1]], Max@data[[All, 1]]}, Epilog -> Map[Point, data]] Edit Better (tick labels showing dates) ...


12

Nested WolframAlpha approach, showing the intermediate steps: numberString[a_, k_: 10] := FixedPointList[ StringReplace[#, b : (DigitCharacter ..) :> WolframAlpha["spell " <> b, {{"Result", 1}, "Plaintext"}]] &, a, k] numberString["123456"] (* ==> {"123456", "123 thousand and 456", "one hundred twenty-three \ thousand and ...


10

I've got my own package that I've used for a few years to generate LaTeX from Mathematica. All the labs on my Mathematica course page were produced with this package. Here's a handout on probability theory for Calc II students that was produced by the package. Unfortunately, it's not at all polished and really not usable by anyone but me. I can present ...


10

Mathematica 10 introduces IntegerName: IntegerName[n] gives a string containing the full English name of the integer n. IntegerName[n,"type"] gives a string of the specified type. Possible types include: "DigitsWords" a combination of three-digit numbers and words "Words" using only words "Approximate" the first few digits ...


10

The reason your original code fails is that the TreeFrom object is only formatted as Graphics object, meaning that it converted for display rather that as part of the normal evaluation sequence. You can convert to and from box form to recover your Graphics object: tf = TreeForm[a + b^2 + c^3 + d]; gr = tf // ToBoxes // ToExpression gr /. (x_Framed ...


10

While this is overkill, I'm just trying everything I can do with these new (in V10) and exciting Mesh and Region functions. So here we go: f[x_, y_] := -E^(-(1 + x)^2 - y^2)/3 + 3*E^(-x^2 - (1 + y)^2)*(1 - x)^2 - 10*E^(-x^2 - y^2)*(x/5 - x^3 - y^5); gr = Plot3D[f[x, y], {x, -3, 3}, {y, -3, 3}, PlotRange -> All, PlotPoints -> 100]; We ...


10

I noticed only afterwards that you were asking for a built-in method. I'm not certain if you would actually want to rely on an undocumented feature instead of writing your own, since it's not hard. This requires v10 for StringTemplate. It could be replaced with something else, of course... Range[120] /. { tens_Integer /; Floor[Mod[tens, 100], 10] == 10 ...


10

It is well-documented! According to the Documentation page for StandardForm, StandardForm generates output that gives a unique and unambiguous representation of Wolfram Language expressions, suitable for use as input. » StandardForm is the standard format type used for both input and output of Wolfram Language expressions in notebooks. ...


9

Messy but a working method inWords[n_] := Module[ {r, numNames = {"", " one", " two", " three", " four", " five", " six", " seven", " eight", " nine"}, teenNames = {" ten", " eleven", " twelve", " thirteen", " fourteen", " fifteen", " sixteen", " seventeen", " eighteen", " nineteen"}, tensNames = {"", " ten", " twenty", " ...


9

N A one-character answer is disallowed by SE, so I will expand. N is mostly what I use. If I have an expression like $2 x + 3$, I sometimes write it 2. x + 3. in Mathematica; then if x is numeric, whether it happens to be an Integer or not, the expression will always be Real or Complex.


9

There are two parts to accessing the contents of a Java Map object. The first is to traverse the iterator interface to extract the map elements. The second is to use accessor methods on those elements to extract their properties. For the purpose of discussion, let's create a map from strings to Java date objects: Needs["JLink`"] InstallJava[]; $map = ...


8

In Mathematica 8 you can use free form input : = Spell 15 and you get "fifteen" Or just write = thirty and you obtain 30 Since for larger numbers this approach yields expressions like {number words number, _ } one could nest this arbitrarily to obtain expressions containing only words. In fact, it is sufficient to nest only two times. For ...


8

It seems that every time you open a new cell with no style, that is "", it automatically puts the span tag to it. To to avoid this we can use this rule: "ConversionRules" -> { "" -> {"", ""} } So now, evaluating ExportString[ Cell[TextData[{"This is an equation: ", Cell[BoxData[ FormBox[RowBox[{RowBox[{"f", "(", "x", ...


8

You can use the Range function in this way: Range[1, 2, 0.1] to get {1.,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.} If the problem is how to pass the parameter a you can use: 1- Using Apply. a = {1, 2, 0.1} Range@@a The Apply operator (@@) "decapitates" the List head from list a and changes it by Range. 2- Using Sequence a = {1, 2, 0.1}; ...


8

You can start with that. StringCases["8.0,1034(*g opx ksp pl ilm liq q *)", x__ ~~ y : ("(*" ~~ ___ ~~ "*)") :> {x, y}] {{"8.0,1034", "(*g opx ksp pl ilm liq q *)"}} And You can do with the first elements what You need. Edit I can not be passive after Jacob's remarks :) Following solution is based on his but simplified in order to avoid ...


8

The following works in Version 9.0.1.0 and Version 10.0.1.0 BoxForm`$UseTemplateSlotSequenceForRow = False; {x^a, Sqrt@b, ArcSin[c]} // Row // TeXForm (* x^a\sqrt{b}\sin^{-1}(c) *)


8

Normal[# /. a : Arrow[{__List}, Except[_List]] :> Thread @ a] gives a quick fix for these examples.


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


8

Question 1: What is the typesetting in Mathematica? What procedures does it include? I think that this 2008 year MathGroup post by John Fultz completely answers this question, so I'll cite it here: In version 6, the kernel has absolutely no involvement whatsoever in generating the rendered image. The steps taken in displaying a graphic in ...


7

Update As @VCL pointed out in his comment, just exporting a list of graphics does not work since the braces and commas of the list a exported as well. Additionally, the pdf is one single page. Here is an updated approach, which takes all imported pdf-pages and inserts them into a new notebook where every page is separated by a pagebreak. The resulting pdf ...


7

Don't use BaseForm[number,base] Use IntegerDigits[number,base] : IntegerDigits[10, 2] (* ---> {1, 0, 1, 0} *) It returns a List of Integers, which is a very good thing for further processing


7

You can access many different font characteristics via CurrentValue. Here is an approximation to convert between ItemSize and ImageSize: itemSize = {10, 10}; Overlay[{ Grid[ {{"Sample", "Text"}}, Frame -> All, Spacings -> {0, 0}, ItemSize -> itemSize, Alignment -> {Left, Center}], Row[{ Framed["Sample", ImageSize -> ...


7

This seems to work on my system at least, but as Mr.Wizard said it might be system dependent lineHeight = 1.5; conversion = 10;(*magic number*) scrollToThis = 80; paneHeight = 200; pos = (scrollToThis - 1/2)*lineHeight*conversion - paneHeight/2; Framed[ Pane[ Grid[List /@ data, Frame -> All, ItemSize -> {5, lineHeight}, ...


7

NOTE: This answer is provided for illustrative purposes only, since it shows some techniques of working with boxed data. While it illustrates how one could emulate the correct behavior in some cases, this code should NOT be used in practice (as a solution for this particular problem), because doing so may be both fragile and dangerous. Please read the ...


7

From this answer Network`GraphPlot`ExprTreePlot[a+b^2+c^3+d] /. (x_Framed :> Print[x])


7

I would use ImportString myself: string = "1,2,3,5,10,12,13,17,26,30,32,41,42,43,113,115,121,125"; ImportString[string, "CSV"] {{1, 2, 3, 5, 10, 12, 13, 17, 26, 30, 32, 41, 42, 43, 113, 115, 121, 125}} Are you using Mathematica for the operation which I imported from a homepage? There may be a more direct method in that case. Regarding your ...



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