Hot answers tagged

26 votes

SetOptions locally?

Version 12.2 In version 12.2, use the new function WithCleanup[]: ...
21 votes
Accepted

Inheriting Options?

Let us assume that you are designing a function which can take its own unique options, but also shares option names with Plot. What is the best way to implement ...
Szabolcs's user avatar
  • 234k
19 votes
Accepted

Creating a simple Dock Cell that Fades In when Cursor Hover Over It

Edit: Fading overlay window In order to get a top dock element with real transparency, one can create a window that overlays the current notebook window and adjusts its position together with it. <...
Karsten7's user avatar
  • 27.4k
18 votes

Writing functions with "Method" options

Introduction What are good (robust?, simple?, efficient?) patterns for doing this kind of code-switching? This answer outlines a development strategy that can produce robust and extensible ...
Anton Antonov's user avatar
17 votes

SetOptions locally?

I have used several methods, including the ones in the other answers. I have found that the simplest method is Internal`InheritedBlock as it allows for temporary ...
rcollyer's user avatar
  • 33.9k
17 votes

Is a list of all graph layouts available?

ResourceFunction["QueryCodeCompletion"]["GraphLayout","KernelSymbol","Graph","InOptionValuePosition"]
yode's user avatar
  • 26.5k
15 votes

OptionsPattern[] taken as a Replacement Rule

You must use opts : OptionsPattern[] and not opts_ : OptionsPattern[]. The : character has ...
Szabolcs's user avatar
  • 234k
15 votes
Accepted

How to check the validity of an option value

Implementation This is indeed an important problem. It is usually best to have a separate function testing various options. Here is the solution I propose: a wrapper that would factor out the testing ...
Leonid Shifrin's user avatar
15 votes
Accepted

Bulletproofing packages against SetOptions of built-ins

The approach This seems to be a good case for applying some run-time metaprogramming / introspection. The idea would be to patch the already constructed definitions after they have been created, at ...
Leonid Shifrin's user avatar
14 votes
Accepted

What is the fundamental difference between "PlotPoints" and "MaxRecursion"?

PlotPoints guarantees a number of points that will be plotted. MaxRecursion states the maximum recursion, which might not be ...
David G. Stork's user avatar
13 votes
Accepted

Programming scripts to create and modify stylesheets: problems with contexts

One has to be extremely careful with Cell options that are not released in System` context. It seems that your problem is caused ...
Kuba's user avatar
  • 137k
13 votes
Accepted

How to extract the AspectRatio of a plot?

For example: p1 = Plot[Sin[x], {x, 0, π}] AbsoluteOptions[p1, AspectRatio] {AspectRatio -> 0.618034} If this number looks familiar, it is because the default <...
Syed's user avatar
  • 48.6k
12 votes
Accepted

Confused by the opts : OptionsPattern[ ] pattern

Re 1: As documented in Operator Input Forms, colon represents two different operations: symb:expr Pattern[symb, expr] patt:expr Optional[patt, expr] If you ...
Itai Seggev's user avatar
  • 14.1k
12 votes
Accepted

Creating Saveable->False notebooks

To whom it may concern, a workaround: ...
Kuba's user avatar
  • 137k
12 votes
Accepted

What is Hessian?

The Mathematica documentation for FindMaxValue includes the example ...
mikado's user avatar
  • 16.4k
12 votes

SetOptions locally?

Just define your options as sequence held in a local variable. ...
m_goldberg's user avatar
  • 108k
12 votes

What are the possible Method option values for plotting functions?

I found one: For ParametricPlot3D (and Plot, Plot3D), ...
Michael E2's user avatar
  • 234k
12 votes

Are Mathematica commands always supposed to check that Method -> name is valid?

The other answer is completely correct (see my comment), but let me add some context. For algorthmic functions, it is generally the case that we validate the method options and issue messages/fail (...
Itai Seggev's user avatar
  • 14.1k
12 votes
Accepted

Option Lighting in the Show function does not work

Update: This is yet another case of automatic PlotTheme settings injecting directives that override the user-specified ones. So, a much easier fix is to add the ...
kglr's user avatar
  • 392k
12 votes
Accepted

OptionValue doesn't work if a local variable has the same name as the function itself

Looks like a variable capture, caused by the macro-like expansion mechanism of OptionValue , which happens before the r.h.s. of the function gets evaluated. What ...
Leonid Shifrin's user avatar
11 votes
Accepted

More Ticks::ticks errors in AbsoluteOptions in v10

This is what I believe the situation to be. AbsoluteOptions uses FullAxes under the hood. It turns out that ...
Carl Woll's user avatar
  • 130k
11 votes

PenaltyFunction Option in NMinimize

As noted in the OP, "PenaltyFunction" has the form pf[..., step] where the first argument is constructed from the ...
Michael E2's user avatar
  • 234k
11 votes
Accepted

Are Mathematica commands always supposed to check that Method -> name is valid?

I would expect a fully implemented/documented function to check the validity of the specified Method; however, since ...
Bob Hanlon's user avatar
  • 155k
11 votes
Accepted

How to delete an option from a notebook

You can use NotebookGet/NotebookPut. Here is a function that does this: ...
Carl Woll's user avatar
  • 130k
11 votes

Is a list of all graph layouts available?

@yode's answer is the better choice, but since it missed some options, here is a manual one that works in this particular case. The question you asked was discussed during a Live CEOing session (I ...
Ben Izd's user avatar
  • 9,169
10 votes
Accepted

Manipulations with options

You can use my OptionsValidation framework to add options validation to your functions. We start by loading the package: ...
jkuczm's user avatar
  • 15.1k
10 votes

Options for the function 'Classify'

Take the first example from the documentation trainingset = {1 -> "A", 2 -> "A", 3.5 -> "B", 4 -> "B"}; and use a nearest neighbor classifier to find ...
Sascha's user avatar
  • 8,409
10 votes

SetOptions locally?

This is a simple solution. The idea is to save the Plot options on entry, and restore it on leaving the module to whatever it was ...
Nasser's user avatar
  • 142k
10 votes
Accepted

Increasing notebook magnification pushes output onto a new line

You can increase the CellMargins for the styles "Input" and "Output" in your style sheet to accommodate the increased size of the cell labels. For example, the ...
Carl Woll's user avatar
  • 130k

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