# How to prevent formatting as Mathematica code in inline cells?

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.

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

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:

Cell[TextData[{
"The type ",
Cell[BoxData[
FormBox[
RowBox[{
RowBox[{"std", "::", "vector"}], "<", "int", ">"}], TextForm]], "InlineCode",
FormatType->"TextForm"],
" ..."
}], "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:

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


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.

Related:

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

• 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.
– Kuba
Sep 25 '17 at 17:45
• related: full topic + comment298436_110018 or a/14835
– Kuba
Sep 25 '17 at 17:47
• 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"] :)
– Kuba
Sep 25 '17 at 17:48
• @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? Sep 26 '17 at 10:13
• This is what I wanted to demonstrate, but I do not know why this happens :/
– Kuba
Sep 26 '17 at 10:28