Tag Info

Hot answers tagged

24

My other answer is a nice solution for interactively looking at boxes, but in the comments, Mr.Wizard seems to be indicating that he's more interested in programmatic usage, and that he's definitely interested in seeing the box form after the FE has stripped non-semantic boxes to send to the kernel. So here's a totally different method for doing this which ...


15

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"], ...


12

Here's some code which produces an InputField and the box form of anything you type into the InputField as you type it: DynamicModule[{boxes = ""}, Column[{InputField[Dynamic[boxes], Boxes, ContinuousAction -> True], Dynamic[boxes, BaseStyle -> {ShowStringCharacters -> True}]}]] The critical idea here is using a Boxes style InputField to ...


11

You can convert any expression to string by using ToString. If you want to preserve the visual representation, you should use ToString[(*your expression*), StandardForm]. logo = Import["http://wolfram.com/favicon.ico", "Image"] logostr = ToString[logo, StandardForm] StringJoin["Mathematica", logostr] % // StringQ Edit: By checking the cell expression ...


10

This is a nice exercise on boxing: MakeBoxes[u[v_[r_[b_]]], TraditionalForm] := Module[{b1, b2, b3, t}, t = ToBoxes[#, TraditionalForm] &; {bl1, bl2, bl3} = StyleBox[#1, #2] & @@@ { {"{", {20, Orange}}, {"[", {15, Purple}}, {"(", {12, Blue}}}; {br1, br2, br3} = {bl1, bl2, bl3} /. {"[" -> "]", "{" -> "}", "(" -> ")"}; ...


9

You can place your desired output in a Row and then put it into DisplayForm. Manipulate[ Switch[testStatChoice, 1, testText1], {{testStatChoice, 1, "Select Calculation"}, {1 -> "1: First Calculation Example"}, ControlType -> PopupMenu}, Initialization :> {testText1 := Row[{SuperscriptBox["R", "*"]// TraditionalForm, " = ", "Rate of star ...


9

The following functions will load the expressions and erroneous cells from a notebook: notebookExpressions[path_, pattern_:_] := Cases[Import[path, "Notebook"] // First , c:Cell[_, "Input"|"Output"|"Print", ___] :> Module[{v = eval[c]}, v /; MatchQ[v, _$Failed | Hold[pattern]]] , Infinity ] eval[cell_] := Quiet @ Check[ ...


8

My colleague John Fultz suggested the following answer. f /: MakeBoxes[dat : f[args_], fmt_] := TagBox[ToBoxes[Rasterize@RandomImage[1, {100, 100}]], InterpretTemplate[f[args] &], Editable -> False, Selectable -> True, SelectWithContents -> True, Tooltip -> "tooltip"] After a bit of exploring I realized that I should have checked ...


8

The simple answer is, if you want a string converted to StandardForm, you could wrap BoxData around it. E.g., CellPrint[Cell[BoxData["myFunction::usage=\"myFunction does ...\";"], "Input"]] But, in general, I wouldn't structure this as a question of CellPrint vs. FrontEnd`CellPrint. FrontEnd`CellPrint is undocumented, and therefore there is no contract ...


8

The problem here is independent of Manipulate or Dynamic. It is about how to display a Cell object without using a CellPrint statement. testText1 in itself is always displayed as Cell[...]. Therefore I suggest reconstructing the expression as something else, not wrapped in Cell. testText1 := TraditionalForm@Row[{Superscript[R, "*"], " = Rate of star ...


8

tokenize[str_] := Module[{exp, nb = CreateDocument[{ExpressionCell@ InputForm@MakeExpression[str, StandardForm]}, Visible -> False]}, SelectionMove[nb, Next, Cell]; exp = Flatten[ NotebookRead[nb][[1, 1]] /. {RowBox -> List, i_String /; StringMatchQ[i, Whitespace ..] :> Sequence[]}]; NotebookClose[nb]; exp[[3 ...


8

Perhaps it's not obvious because this doesn't look like a box. But the way that DocumentNotebook, et al, get translated into Notebook is by going through MakeBoxes. Which means that RawBoxes saves the day by preserving its guts in MakeBoxes: DocumentNotebook@{TextCell["Hello world!", "Section"], RawBoxes@cell, TextCell["The solution is:", "Text"]}


8

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]], Unevaluated@c ] ] You can even evaluate such ...


7

This is documented in Part >> More Information (Part >> Details in V9):


7

I believe this is the documentation you are looking for: String Representation of Boxes Notably: And:


6

Why not use ToBoxes (or MakeBoxes) to construct boxes, instead of doing it yourself? DisplayForm[ ToBoxes[Row[List[0, 1, Superscript[2, 3], Superscript[1, 2], a]]]]


6

This is caused by the AutoMultiplicationSymbol option in the front end. SetOptions[$FrontEnd, AutoMultiplicationSymbol -> False] Will make the space disappear.


6

Not quite tested embeddedNotebookForm/: MakeBoxes[embeddedNotebookForm[nb:Notebook[cells_List,___]],StandardForm]:= MakeBoxes@DocumentNotebook[{TextCell@"tag"}]/.{ {{Cell["tag"]}}:>Block[{},List/@ Replace[cells, Cell[CellGroupData[{cs__Cell},_]]:>cs, {1}] /;True], ...


5

Interesting question. I don't have much experience with this sort of thing so I imagine there is a better way but this is what I could hack together at the moment: frac[lst_List] := Column[ Column /@ Partition[Riffle[lst, \[HorizontalLine]], 2, 2, -1, {}], Alignment -> Center, Spacings -> 0] {"x", 200, Integrate[Sin[x^2], x]} // frac Here ...


5

One approach that may be familiar to more experienced users is based on the input syntax described in String Representation of Boxes. \(input\)             raw boxes This appears to work but closer inspection shows that it is not exact: "\({1*^4, 000123, a*b c}\)" // ToExpression ...


5

I believe it is not a restriction, but this comes with the way how Mathematica formats derivatives. That being said, the same way you cannot use 3 superscript primes to input a third derivative, you won't see 3 primes in the output either. D[f[x], x, x, x] gives If you could type this as input, then you would have a way to specify your third ...


5

When I see this right, then the evil function is TraditionalFormDump`ordplus. This seems to change the order. The arguments can be extracted from a Trace TraditionalForm[a + b]; (* Dummy call *) TraditionalFormDump`ordplus[{{"+", "b"}, {"+", "a"}}, {}] (* {2,1} *) If we change this to give a sorted list, then your arguments are not reordered ...


5

While I was working on alternative TeX export, I had similar requirement. I wanted to export annotated Mathematica code to TeX, with annotations reflecting FrontEnd's syntax highlighting. Since I couldn't find a way to use front end itself to do it, I decided to write my own package. My SyntaxAnnotations package is now available on GitHub. It works by ...


5

I'll provide an starting point for 2D case with single particle. Collisions with other particles are likely to be hard to model (or at least require adding an massive amount of WhenEvent rules if implemented this way), since NDSolve and WhenEvent tend to miss discrete events. Also, 3D case would be considerably more complicated to build; likely to take more ...


4

Not an answer since I could not find where it is documented (but I did not spend much time searching) But just to show that they are really same thing, which I did not know this myself as I do not really use subscripts as they do not work nicely across function calls. But this shows that $x_{[[1]]}$ is really the same as $x[[1]]$ , it is just different ...


4

Try setting the option FractionBoxOptions, suboption MultilineFunction to None for the style, or globally.


4

David Carlisle wrote about it back in 2007. The process seems to be rather cumbersome and I have not checked myself if it is reliable working but here are some links that might help you on your specific problem: XHTML and MathML from Office 2007 Going Wordless at the Advanced Mathematica Summer School


4

If you are willing to enter your code as a String you can use this function: parseStringRaw[s_String] := FrontEndExecute @ UndocumentedTestFEParserPacket[s, False] Now: Note that the " characters were entered last; if you enter them earlier the auto-indenting will not be the same and neither will the output. Alternatively you could manually paste ...


4

Here is how you attack this: First click on the little "+" in the right upper corner. Then you select either "Subpod content" or directly "Formula data". Both will result in a more specific request which gives you the hint you need: {WolframAlpha[ "6.38905609893065", {{"PossibleClosedForm", 1}, "FormulaData"}], WolframAlpha[ "6.38905609893065", ...


4

These are Operator Input Forms Characters that are not letters, letter‐like forms, or structural elements are treated by the Wolfram Language as operators. The Wolfram Language has built‐in rules for interpreting all operators. The functions to which these operators correspond may or may not, however, have built‐in evaluation or other rules. ... ...



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