9
$\begingroup$

I want to make a notebook with the following special feature: some of its cells show up only when the notebook is opened in for instance versions 11 and 12, but are hidden if the notebook is opened in other versions. Is this possible to do?

$\endgroup$
2
  • $\begingroup$ Do you want Input Cells to be visible or hidden depending on Mathematica's version or maybe Output Cells? $\endgroup$
    – Markhaim
    Commented Sep 23, 2019 at 9:25
  • $\begingroup$ It is arbitrary, I just want to mark a bunch of cells (no matter the type) to only show up for certain values of $VersionNumber. $\endgroup$ Commented Sep 23, 2019 at 9:41

1 Answer 1

9
$\begingroup$

You can use the approach from this question to get front-end-only version dependent styling of cells and combine it with this question to get invisible cells:

CellPrint@Cell[
  BoxData["Only in 12.0+"],
  "Text",
  "Text",
  CellElementSpacings ->
   {"CellMinHeight" -> FEPrivate`If[
      FEPrivate`Less[FEPrivate`$VersionNumber, 12],
      0,
      Inherited
      ],
    "ClosedCellHeight" -> FEPrivate`If[
      FEPrivate`Less[FEPrivate`$VersionNumber, 12],
      0,
      Inherited
      ]
    },
  CellMargins -> FEPrivate`If[
    FEPrivate`Less[FEPrivate`$VersionNumber, 12],
    -2,
    Inherited
    ],
  CellOpen -> 
   FEPrivate`Not@FEPrivate`Less[FEPrivate`$VersionNumber, 12],
  ShowCellBracket -> 
   FEPrivate`Not@FEPrivate`Less[FEPrivate`$VersionNumber, 12]
  ]
CellPrint@Cell["All versions", "Text"]

The above cell will print two cells, the first one is only visible in version 12.0 and higher, in lower versions it will be completely invisible:

Version 12.0: enter image description here

Version 11.3: enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.