CounterIncrements for individual cells

后端 未结 1 2026
无人及你
无人及你 2021-01-05 16:44

This post derives from my question extending cell definition to cellframelabels. I\'ve been playing around with CounterIncrements and I\'m not obtaining what I\

相关标签:
1条回答
  • 2021-01-05 17:30

    My guess is that counters are only counted if they are in a proper (not inline) cell. This is fine, since inline cells are only really meant for formatting purposes and not for document structure.

    The counter increase works fine if you move it to the outer cell. Modifying your code above:

    CellPrint[Cell["Setting the counter to 0", "Text", 
      CounterAssignments -> {{"MyCounter", 0}}]]
    
    (* Prints a cell containing: Setting the counter to 0 *)
    
    CellPrint[Cell[
      TextData[RowBox[{"MyCounter ", CounterBox["MyCounter"], 
         Cell[TextData[RowBox[{"[InlineCell]"}]], "Text"]}]], "Text", 
      CounterIncrements -> "MyCounter"]]
    
    (* Prints a cell containing: MyCounter 1[InlineCell] *)
    

    Is this for something like your previous "Definition" style? If so, then why don't you have the inline cell as a plain (unstyled) cell which inherits its style from the outer cell. Then just have the counter increment in the "Definition" style, i.e. in the stylesheet? As I said above, the non-inline cell should be the one which is styled (as a "Definition", "Chapter", "Section", etc..), as that is the one that determines the document structure.


    Edit in response to comments:

    Here's a palette that will create new chapter cells and new definition cells. The latter with the built-in, non-editable counter. Note that most of the styling should be moved into the stylesheet.

    CreatePalette[With[{nb = InputNotebook[]}, {
     Button["New Chapter", SelectionMove[nb, After, Cell];
      NotebookWrite[nb, Cell["New Chapter", "Chapter" (* Styling is in stylesheet*)]]],
     Button["New Definition", SelectionMove[nb, After, Cell];
      NotebookWrite[nb, Cell[TextData[RowBox[
       {Cell[TextData[
         StyleBox[#, FontWeight -> "Bold"] & /@ {
           "Definition ", CounterBox["Chapter"], ".", CounterBox["Definition"], ":  "}],
         Editable -> False, Selectable -> False, Deletable -> False],
         "New definition"}]], "Definition", CounterIncrements -> "Definition",
        CellFrame -> {{1, 1}, {0, 2}}, CellMargins -> {{30, 24}, {6, 6}}, 
        CellFrameColor -> RGBColor[0, 0, 1], Background -> RGBColor[0, 1, 1]]]
     ]}], WindowTitle -> "Document writing palette"];
    
    0 讨论(0)
提交回复
热议问题