4
$\begingroup$

It's not that I can't live with that but I don't understand why e.g:

ExpressionCell[ Defer @ Style["string", Red], "Input"]

enter image description here

is not showing quote marks? This means that a ShowStringCharacters option is not inherited from an "Input" style, as one (at least me) would expect, but (probably) from an "Output".

CurrentValue[{StyleDefinitions, #, ShowStringCharacters}] & /@ {"Input", "Output"}
{True, False}

Can this be explained with documentation?

Maybe I'm missing the point of an ExpressionCell?


With CellPrint everything will be ok, but it's not what I'm after because I'd like to use an ExpressionCell as a part of the output somewhere to quickly format an InputStyle, eg:

Column[{
  "here is an example of the input cell:",
  ExpressionCell[Defer@Style["string", Red], "Input"]
} ]
$\endgroup$
  • 2
    $\begingroup$ When you evaluate ExpressionCell in an input cell, the result will be an output cell, and therefore you do not see the quotation marks. I do not have a good understanding of EvaluationCells and TextCells, but my feeling is that they are supposed not to be used as stand alone commands, but as arguments of functions such as CellPrint. As you observed, then it works as expected. $\endgroup$ – Fred Simons Jan 3 '16 at 18:46
  • 2
    $\begingroup$ ExpressionCells are baffling to me as well! They use interpretation boxes, so this would work: CopyToClipboard@ExpressionCell[Defer@ Style["string", Red], "Input"];Paste[] $\endgroup$ – M.R. Jan 3 '16 at 19:11
  • $\begingroup$ @FredSimons Ok, I've read a little bit and it seems to be logical at the end :) $\endgroup$ – Kuba Jan 4 '16 at 11:40
4
$\begingroup$

Ok, after taking a look at Core.nb stylesheet it is clear what happens.

What's there is a Notebook setting of ShowStringCharacters->True and ShowStringCharacters->False are included only in styles that need it to be False, like an Output. Input just inherits from the Notebook.


By evaluating ExpressionCell[ Defer @ Style["string", Red], "Input"] we get something which inherits style in following way:

Output styles (from the cell it was put in) --> Input styles (from the ExpressionCell)

Input styles are superior since ExpressionCell is the inner one. But ShowStringCharacters is not set explicitly in Core.nb for Input style.


So at the end we get:

  • ShowStringCharacters->True from Notebook settings, which
  • is overwritten by ShowStringCharacters->False from Output settings, and
  • an Input ExpressionCell is passing it because there is no spec in stylesheet about ShowStringCharacters for Input.

How to get nice Input like ExpressionCell then? We can put Notebook styles in between outer Output and ExpresisonCell Input styles:

Panel @ ExpressionCell[
    Defer @ Plot[x, {x, 0, 1}, PlotLabel -> "string"], 
    "Notebook", "Input"
]

enter image description here

Now, it looks like real Input cell. With syntax coloring etc.

$\endgroup$

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.