Hot answers tagged

16

The reason is to prevent users to mess with it. Unprotecting something is not necessarily dangerous, but unprotecting everything definitely is. Performance is probably not the issue. The real danger is that you replace a very important feature of a built-in symbol by chance. Since built-in symbols often have the ReadProtected attribute, you cannot check ...


15

There is a typesetting step after formatting, and MakeBoxes definitions do not require unprotecting Hold, you will just add more DonwValues for MakeBoxes. MakeBoxes[Hold[a___], fmt_] := With[ {foo = MakeBoxes[Panel[Column[{a}]], fmt]} , InterpretationBox[ RowBox[{"Hold", "[", foo, "]"}] , Hold[a] ] ] Hold[1 + 1, 2 + 2, 4 + 4] It ...


13

If you have Version 11 you can use the function PrettyForm instead of processing InputForm output to get the desired result: Needs["GeneralUtilities`"] Interpolation[{1, 2, 3, 4}] // PrettyForm ListLinePlot[Range[5]^2] // PrettyForm For earlier versions you can also wrap InputForm with DisplayForm: ListLinePlot[Range[5]^2] // InputForm // DisplayForm


11

Per my comment, I like using expr //InputForm //SequenceForm, but another similar possibility is to use a custom head with a custom MakeBoxes rule. For instance, let's call the custom form myInputForm. Then, we can define: myInputForm /: MakeBoxes[myInputForm[expr_], StandardForm] := MakeBoxes[InputForm[expr]] We also need to add myInputForm to $...


10

The best thing to do, IME, is to set the default notebook zoom level to something higher. This way, the text is rendered crisply and at a reasonable size. You can do that as follows: Go to Preferences -> Advanced -> Open Option Inspector Set Show option values to Global Preferences Go to Notebook Options Go to Display Options Change magnification to ...


9

Mathematica 11.2 seems to use Qt 5.6 framework which supports DPI scaling override. At least on Linux, it's possible to get bearable results by starting Mathematica as follows: QT_SCALE_FACTOR=1.5 Mathematica QT_SCALE_FACTOR is an environment variable that defines UI scaling. It seems to work quite well except for the splash screen.


8

Conversion to $\TeX$ uses various Style options: Style["text", FontWeight -> "Bold", FontSlant -> "Italic"] // TeXForm (* \pmb{\text{\textit{text}}} *) but it seems that FontColor is not one of them: Style["text", FontColor -> Red] // TeXForm (* \text{text} *) If we look at DownValues of System`Convert`TeXFormDump`maketex function, which is ...


8

The reason your last line is not working is because Grad[f[x, y], {x, y}] is not a function, but a list of (operations applied to) symbols. What you need is instead a function taking two inputs and giving two outputs. One way to do this is by explicitly defining one (* define function *) gradf[x_, y_] := Evaluate[Grad[f[x, y], {x, y}]] (* apply function to ...


8

Carl's tip seems to be the best quick solution. Very often I find syntax/style highlighting very useful too so I use: CellPrint[ExpressionCell[InputForm@#, "Input"]] & to get everything what Input cells offer: Plot[x, {x, 0, 1}, PlotPoints -> 10, MaxRecursion -> 1 ] // CellPrint[ExpressionCell[InputForm@#, "Input"]] & related: How to ...


7

You can do this by modifying AutoStyleOptions programmatically: SetOptions[EvaluationNotebook[], AutoStyleOptions -> {"CommentStyle" -> {FontWeight -> Bold, FontColor -> Blue, ShowAutoStyles -> False, ShowSyntaxStyles -> False, AutoNumberFormatting -> False}}]


6

Generally speaking, that TagSetDelayed form is preferable, as the rule is attached to the myfuncF rather than to MakeBoxes. This means: Clear[f] will remove the FormatValues. The pattern is only matched against expressions which contain myfuncF rather than all expressions. The pattern won't compete against any other patterns attached to MakeBoxes (i.e, it'...


6

Changing a__ and b__ to a_ and b_, respectively, j2[q_] := q /. b_ Cos[x__] + a_ Sin[x__] :> {{a}, {b}, {x}}; j2[h] gives $\left( \frac{\tau w}{\tau ^2 w^2+1}, \frac{1}{\tau ^2 w^2+1}, t w \right) $ and, the same change in OP's function j j3[q_] := q /. b_ Cos[x__] + a_ Sin[x__] :> Sqrt[a^2 + b^2] Sin[x + Pi/2 + ArcTan[b/a]]; j3[h] gives ...


6

Just use Style whenever you want to change the style of something: TraditionalForm[Style[x^3 + y^3 == 22 z^3, FontSize -> 24]]


6

With Windows 10 Build 15002 and above, you can use the following settings to obtain a higher resolution of MMA than magnification for 200%, for example.


6

While you can do this via a stylesheet, and also programmatically, the quickest way to do it is via the preferences menu:


6

Using the code from my answer to Format and TeXForm does not work as expected (which I include at the bottom of this answer: Format[ArcTan[x_], TeXForm] := arctan[x] Then: 1 + ArcTan[x] //TeXForm $\arctan (x)+1$ Here is the code: Initial /: Verbatim[TagSetDelayed][Initial[sym_], lhs_, rhs_] := With[ { new = Block[{sym}, TagSetDelayed[...


6

It's not clear how XML can be converted to JSON in a general way, because how would one deal with attributes? You happen not to have attributes in your XML, but that's just a special case. Luckily, Mathematica is a great language to write ad hoc parsers in. convert[XMLObject["Document"][{}, content_, {}]] := convert[content] convert[XMLElement[tagName_, _, ...


6

Partition[connectionsOrder, 2, 1, {1, -1}, {}, Rule] {"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH", "THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL", "WHEEL" -> "WHEEL_L"} or Rule @@@ Partition[connectionsOrder, 2, 1] {"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -&...


5

I would use: f /: MakeBoxes[f[a_, i__], form:StandardForm] := With[ {s = MakeBoxes[Subscript[a, i], form]}, InterpretationBox[s, f[a, i]] ] instead.


5

BlockMap can do more of the work than you are allowing it to: BlockMap[Apply[Rule], connectionsOrder, 2, 1] {"BASE" -> "HAA", "HAA" -> "HIP", "HIP" -> "HFE", "HFE" -> "THIGH", "THIGH" -> "KFE", "KFE" -> "shank_fixed", "shank_fixed" -> "WHEEL", "WHEEL" -> "WHEEL_L"}


4

You will find this in the Preferences (or Settings) for Mathematica; follow the tabs in the Preferences window: Appearance > Syntax Coloring > Other


4

e.g.: Magnify[TraditionalForm[x^3 + y^3 == 22 z^3], 2] or TraditionalForm[Magnify[x^3 + y^3 == 22 z^3, 2]] Depending on if you want to maintain TF.


4

You're using an ancient stylesheet, that doesn't take advantage of stylesheet inheritance. In particular, it doesn't inherit from the default/core stylesheet where autostyles are controlled. You can fix autostyles by inheriting the default stylesheet. You can use Format | Edit Stylesheet... from the menu and edit the stylesheet used by your notebook by ...


4

The file appears to be nothing but 15 columns of 64 bit reals: f = OpenRead["KABHVS111110R01_NextGenDrive#1.r64", BinaryFormat -> True] all = BinaryReadList[f, "Real64", ByteOrdering -> -1]; Partition[all[[;; 200]], 15] // TableForm Close[f] note column 15 is the difference of cols 13&14, consistent with the description (program position, real ...


4

Usually the simplest methods tend to be the best. Try the code expr = ArcTan[x/y] - ArcTan[z/w]; StringReplace[ToString[expr, TeXForm], "\\tan ^{-1}" -> "\\arctan"] which returns \arctan\left(\frac{x}{y}\right)-\arctan\left(\frac{z}{w}\right) and in display form is $$ \arctan\left(\frac{x}{y}\right)-\arctan\left(\frac{z}{w}\right) $$


4

I've not been involved with XML lately, but I used to (re)define XMLObject and XMLElement to process an XML structure. It's usually received lukewarm appreciation on this site, but it seems like the sort of expression-rewriting Mathematica was built for. And in this case, it's easy: json = Block[ { XMLObject = Function[{#2} &], , XMLElement = #1 ...


4

When you have a first plot P = Plot[x^2, {x, 0, 1}, AspectRatio -> 2, PlotTheme -> "Scientific"] you can copy many of the options to a second plot with Plot[x^3, {x, -1, 1}, Evaluate[Sequence @@ Options[P]]]


3

Pattern matching takes place on (something close to) the FullForm of the expression rather than the display form that you see. You can visualize it using TreeForm: h // TreeForm I am not sure what you are attempting but I imagine your pattern was not written with this in mind. What parts did you expect to match a__, b__, and x__? What actually matched ...


3

The following creates a duplicate notebook before temporarily exporting the text. It removes all output cells. CleanNotebook[nb_: SelectedNotebook[], styles_: {"Output", "Print"}] := (NotebookFind[nb, #, All, CellStyle]; NotebookDelete[nb];) & /@ styles; nbExport[n_, new_: ""] := Module[{loc, nb}, loc = FileNameJoin[{$...


3

Does it fit your needs? Print[ 23 ] cell break cell = NotebookRead @ Experimental`PreviousCell[]; DumpSave["test", cell] You don't have to use PreviousCell, it is just handy here. ClearAll[cell] << test CellPrint @ cell


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