5
$\begingroup$

Let's say I decide I want all my axes to be colored red, so I do

SetOptions[Plot,AxesStyle->Red]

For the remainder of my session, I correctly get

Options[Plot,AxesStyle]
(* {AxesStyle->Red} *)

But when I quit and subsequently reload MMA, I get

Options[Plot,AxesStyle]
(* {AxesStyle -> {}} *)

For how long are changes made by SetOptions supposed to persist? I (apparently incorrectly) understood that these changes were supposed to persist across sessions (i.e., permanent). I thought if you wanted such changes to persist only for the current session, you needed to use something like $FrontEndSession.

$\endgroup$

1 Answer 1

6
$\begingroup$

For how long are changes made by SetOptions supposed to persist?

Normally, SetOptions is used with functions (see here). In this case changes do not persist across kernel restarts.

I (apparently incorrectly) understood that these changes were supposed to persist across sessions (i.e., permanent).

No, that is not the case, except in special situations.

I thought if you wanted such changes to persist only for the current session, you needed to use something like $FrontEndSession.

SetOptions[$FrontEnd, ...] does indeed persist between restarts. This is a special case though. The same applies to using SetOptions with cell or notebook references: the cells/notebooks are modified, and if you then save them, the changes become permanent.

This use of SetOptions in my mind is completely distinct from setting options for functions, it just happens to have the same syntax.

$\endgroup$
3
  • $\begingroup$ thank you very much. I suppose adding SetOptions[symb,rule] to a kernel Init.m file would make the change persist across sessions? Not sure if that's a best practice, but it seems it would work. $\endgroup$
    – bmclaurin
    Oct 9, 2021 at 19:24
  • $\begingroup$ @bmclaurin Yes, it would work. I do not think it is best practice, and I do not recommend it. Sometimes people change stuff in their init.m, then forget it, and it takes a long time to figure out the cause of a problem they are posting about. If you want to change multiple such options, put the changes in a package, and load that package manually when you need it. $\endgroup$
    – Szabolcs
    Oct 9, 2021 at 20:21
  • $\begingroup$ Perfect counsel, thank you again. $\endgroup$
    – bmclaurin
    Oct 9, 2021 at 23:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.