2
$\begingroup$

I would like to modify the style of Print in a Mathematica notebook. Locally, I can do so by toggling on Show Cell Expression of some output of Print (i.e. in some cell generated by the command), adding ShowCellLabel->True and modifying CellLabel->"mylabel".

This works for a single cell and I would like to make this change for all cells of the notebook. Hence I edit the Stylesheet and paste the section Local definition for Style "Print" from Default.nb -> Core.nb to the private style definition of the notebook.

If I now modify this particular style (editing the cell expression in the style definitions), I can e.g. successfully change the margins of all Print cells in the notebook. I can also toggle on the labels using ShowCellLabel->True, but I can NOT modify these labels. Any command CellLabel->"mylabel" is simply ignored in the notebook. Instead, the label During evaluation of In[.]:= remains.

How can I change the cell label using the stylesheet s.t. it applies to all Print cells?

$\endgroup$
3
$\begingroup$

Print inserts the label explicitly in a Cell that is about to be printed so there is not much you can do about it.

  1. You can create your own Print like here: How to Print to the Console

  2. Or you can set a CellDynamicExpression for a "Print" style that will modify the CellLabel and remove itself just after. Similarly to: Styles that prepend text to cell contents

Let me know if you have troubles adapting any of those solutions.

$\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.