We can start a new inline cell using Insert → Typesetting → Start Inline Cell. This is often used to insert mathematical formulae in text cells.

Instead, I want to use it to insert small bits of non-Mathematica code in text cells, e.g. std::vector<int>. Correspondingly, I set DefaultNewInlineCellStyle to an appropriate custom style* in the notebook. I also changed the default format type to TextForm using DefaultInlineFormatType.

enter image description here

Even so, any text I enter into this inline cell is automatically formatted as if it were Mathematica code.

enter image description here

Notice that the :: was formatted as if it were a message, with vector in grey, and that the spacing around < and > are increased as if they were relational operators.

This is the cell expression:

 "The type ",
    RowBox[{"std", "::", "vector"}], "<", "int", ">"}], TextForm]], "InlineCode",
 " ..."
}], "Text"

Question: What exactly is controlling this automatic formatting? How can I prevent it? Is it related to the fact that the inline cell gets BoxData by default (while the surrounding text cell gets TextData)?

If I could get the following cell, that would be perfect:

 "The type ",
 Cell["std::vector<int>", "InlineCode"],
 " ..."
}], "Text"]

enter image description here

Perhaps the answer is that inline cells are not meant for this, and one should use a StyleBox instead of a Cell. But that is no longer easy to enter in M11.2.


* For simplicity, you may simply set it to "Text" style. It does not make a difference for this question.

  • $\begingroup$ It seems that ShowAutoStyles or LanguageCategory don't affect a::b, which is at least strange. Also when text form inline cell is created inside a standard form cell, not text form like here, then it does not get this FormBox wrapper and everything is correct because FormBox brings standard form styles and hardcoded whatever FE thinks it should do with BoxData. Not to mention that InlineCell style can interfere even if it is not explicitly used. #dailyFun, hope JF could clarify, maybe you could ping him somewhere. $\endgroup$
    – Kuba
    Sep 25 '17 at 17:45
  • $\begingroup$ related: full topic + comment298436_110018 or a/14835 $\endgroup$
    – Kuba
    Sep 25 '17 at 17:47
  • $\begingroup$ p.s. code to play with: NotebookDelete@NextCell[]; CellPrint[Cell["Test ", "Text"]]; SelectionMove[ NextCell[], After, CellContents]; FrontEndTokenExecute["CreateInlineCell"]; NotebookWrite[EvaluationNotebook[], "var::vec<int>"]; try it with regular Text cell like above and Cell[BoxData@"Test ", "Text"] :) $\endgroup$
    – Kuba
    Sep 25 '17 at 17:48
  • 1
    $\begingroup$ @Kuba Re your last comment. I find that very confusing. I thought that TextData (or no wrapper) is what makes things act like plain text (what I want), and BoxData is what causes this special auto-formatting. Now it looks like if the parent is TextData, then the child (i.e. the inline cell) will be BoxData. If the parent is BoxData then the child will be TextData. Am I missing something? $\endgroup$
    – Szabolcs
    Sep 26 '17 at 10:13
  • $\begingroup$ This is what I wanted to demonstrate, but I do not know why this happens :/ $\endgroup$
    – Kuba
    Sep 26 '17 at 10:28

Your Answer

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

Browse other questions tagged or ask your own question.