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.



ShowAutoStylesorLanguageCategorydon't affecta::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 thisFormBoxwrapper and everything is correct becauseFormBoxbrings 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:45NotebookDelete@NextCell[]; CellPrint[Cell["Test ", "Text"]]; SelectionMove[ NextCell[], After, CellContents]; FrontEndTokenExecute["CreateInlineCell"]; NotebookWrite[EvaluationNotebook[], "var::vec<int>"];try it with regular Text cell like above andCell[BoxData@"Test ", "Text"]:) – Kuba Sep 25 '17 at 17:48TextData(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 isTextData, then the child (i.e. the inline cell) will beBoxData. If the parent isBoxDatathen the child will beTextData. Am I missing something? – Szabolcs Sep 26 '17 at 10:13