7

In Mathematica 11.1 and earlier it was possible to select just part of the text in a cell, and apply a different style to it using Format → Style. For example, we could type "One two three four" in a "Text" cell, select "three" and apply the "Program" style:

enter image description here

The cell expression would look like this:

Cell[TextData[{
 "One two ",
 StyleBox["three", "Program"],
 " four."
}], "Text"]

In Mathematica 11.2, using Format → Style when only part of a cell is selected changes the style of the entire cell. Performing the same steps results in:

Cell["One two three four.", "Program"]

How can I change the style of just part of a cell in M11.2?


Related:

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • FrontEndTokenExecute[EvaluationNotebook[], "Style", "Program"] or FrontEndExecute[ FrontEnd`SelectionSetStyle[EvaluationNotebook[], "Program"]] will do, the question is where do you want to put them. – Kuba Sep 24 '17 at 09:34
  • 1
    @Kuba That's weird because I thought that the Style font end token was exactly the same thing as the Style menu item in the Format menu. – Szabolcs Sep 24 '17 at 09:47
  • Yep, me too. So maybe worth asking the Support. p.s. related: 78774 – Kuba Sep 24 '17 at 11:36
  • Is there any reason not to consider this to be a bug introduced in 11.2? – Alan Sep 24 '17 at 14:04
  • @Alan It is not clear at all that this change was not intentional. I could imagine that somebody was complaining that they can't change the style of the entire cell (because they did not select it). Do you read Wolfram Community? But yes, it did cross my mind that this is a bug (and I am very annoyed by this change too). – Szabolcs Sep 24 '17 at 14:06
  • @Szabolcs I hope this is not intentional. And breaking the link between the "Style" front-end token and the Style menu item is just bizarre. – Alan Sep 24 '17 at 14:51
  • 2
    At least on OSX, you can use Alt-0 on the selected text to do what you want. – Carl Woll Sep 24 '17 at 15:10
  • 2
    @CarlWoll 1. Thank goodness that has not changed. 2. This is good behavior, but we should be able to also use Alt-0 as we are typing along (without first creating a format box). 3. I consider the new behavior buggy and have reported it to Support. If you hear any debate over this, please ask the debaters to go through the process of typing a long text cell with many formatted text fragments. As soon as they reach for the mouse, put them in time out. – Alan Sep 24 '17 at 15:53
  • @Alan What OS are you using? The behavior you want is how OSX behaves – Carl Woll Sep 24 '17 at 15:56
  • 1
    @CarlWoll I am using Win 10 with Mma 11.1. But I'm confused. Previously you said "Alt-0 behaves similarly to Alt-8" and you also reported that you needed to use ctrl-( before using Alt-8. But we should not have to use ctrl-(. Additionally, doing so will create an entire inline Cell wrapping a FormBox that wraps a StyleBox. I just want to insert a StyleBox, like Alt-8 does in Mma 11.1 under Win 10. Bottom line: it should be as easy as possible to type with style, and the new (11.2) behavior is apparently breaking this. – Alan Sep 24 '17 at 16:27
  • @Alan For me, on OSX M11.1, Cmd-8 and Cmd-0 behave the same, while on OSX M11.2, Cmd-8 and Cmd-0 behave differently. That is, in both OSX M11.1 and M11.2, using Cmd-0 does not change the cell style, it only changes the style of new text. On the other hand, on OSX, using Cmd-Alt-0 does change the cell style. It seems on Windows, both Cmd and Alt use Alt, so Alt-0 on Windows is equivalent to Cmd-Alt-0 on OSX. – Carl Woll Sep 24 '17 at 18:02
  • @CarlWoll More odd inconsistencies. Furthermore, in Mma 11.1 on Win 10, combining Alt with Cmd leads to no effect. Do you have any insight into how all this evolved or whether the unwelcome 11.2 change was intentional? – Alan Sep 24 '17 at 18:12
  • 1
    In 11.3, we've changed it so that if you have a non-empty selection, it will apply the style to the selection. But if you have an empty selection (blinking caret), it will apply to the whole cell. I think that strikes the right balance of what we were trying to achieve. – John Fultz Sep 25 '17 at 21:29
  • @JohnFultz: and how precisely did you imagine people would typeset cells with mixed styles in 11.2? Or do you think nobody does that? That's extremely poor planning, I have to say. – Andrej Bauer Jan 13 '18 at 22:37
  • @AndrejBauer, well you are welcome to make such a statement and direct it at me (as you probably should...I'm not responsible for many Wolfram decisions, but I certainly do bear a reasonable amount of direct responsibility for this particular one). I imagine your question is rhetorical...you're frustrated, and although there are options for working around this (you can use Style->Other..., you can create a palette to apply your styles, etc.), your preferred workflow isn't working and won't until the next release (which will probably be within a month). (continued...) – John Fultz Jan 19 '18 at 01:00
  • @AndrejBauer (continued...) But if you honestly want to know how it wasn't alarmed before the release, I suspect not many people in Wolfram use the menus to apply inline styles. The styles which have direct keyboard shortcuts are, frankly, ill-suited for inline styles. Some of the ones without direct keyboard shortcuts aren't, but some users (myself included) find it more convenient to use Style->Other... because it has the keyboard shortcut. And, as mentioned previously, that still allows selection-level style application. This is not an excuse, but it is an explanation. – John Fultz Jan 19 '18 at 01:02
  • @AndrejBauer and so, yes, it's a mistake, and one for which I bear a fair bit of the credit/blame. Sorry, and also sorry that it probably won't be the last one I make (and if it is...well, it was a nice life). But part of why I come here is to learn from those mistakes and work toward making a better product. In this case, I still think the core idea was solid, but it definitely merited the tweak I outlined above. – John Fultz Jan 19 '18 at 01:09
  • Thank you for the explanation. Let me just explain where the frustration comes from. I write text for students (I teach Mathematica at a math department) and I need to mix prose with math formulas and snippets of code. The shortcuts for entering and exiting math mode are fine. For inline code there used to be a shortcut, which in 11.2 is broken as far as I am concerned. (And I would fire any UI designer who suggests that keyboard shortcuts aren't needed.) – Andrej Bauer Jan 19 '18 at 07:11
  • Also: perhaps I don't know how to use Style→Other, but it is not really working when I have to type I-N-P-U-T and T-E-X-T to switch back and forth (and capitalize them correctly!). – Andrej Bauer Jan 19 '18 at 07:13

0 Answers0