Cell definition extension in CellFrameLabels definition

I am creating a laptop that contains a style for recording documents. I would like Mathematica to behave the same way as LaTeX, in the sense that when I write the cell "Definition" , then it will write "Definition [Chapter#].[Definition#]" .

To understand what I mean, do the following. In an empty notebook, create a cell and change the style to "Chapter" . You can do this by selecting a cell and going to Format->Style->Other , enter "Chapter" .

Now go to Format->Edit StyleSheet... Type Chapter in the input field. This will create a cell labeled β€œChapter.” Select this cell and click Cell->Show Expression . At this point, select all the text that you see there, and replace it with the following:

 Cell[StyleData["Chapter"], CellFrame->{{0, 0}, {0, 0}}, ShowCellBracket->Automatic, CellMargins->{{42, 27}, {10, 30}}, CounterIncrements->"Chapter", CounterAssignments->{{"Section", 0}, {"Definition", 0}}, FontFamily->"Verdana", FontSize->24, FontWeight->"Bold", CellFrameLabels->{{ Cell[ TextData[{ "Chapter ", CounterBox["Chapter"] }], "ChapterLabel", CellBaseline -> Baseline], Inherited}, { Inherited, Inherited}}, FontColor->RGBColor[0.641154, 0.223011, 0.0623026]] 

This will change the display style of the chapter cell. I changed the color and font. The most important thing for me is CellFrameLabels . Noticed that I did this so that every time you create a chapter cell, it displays: Chapter [Chapter Number] .

Chapter

In the image above, I created several chapter cells, and I added the text: ": Title of Chapter #" .

It's simple enough, we can create any cell, apply the definition and take advantage of the counters for labeling the cells.

I noticed how some books have definitions enclosed in a field. Therefore, in this case, I would like to create a field containing Definition . Here is my lame attempt at defining a "Definition" cell.

 Cell[StyleData["Definition"], CellFrame->{{0, 0}, {0, 2}}, ShowCellBracket->Automatic, CellMargins->{{27, 27}, {0, 8}}, PageBreakWithin->False, CellFrameMargins->16, CellFrameColor->RGBColor[0.641154, 0.223011, 0.0623026], Background->RGBColor[0.963821, 0.927581, 0.844465], FontFamily->"Verdana", CounterIncrements->"Definition", FontSize->12, CellFrameLabels->{{ Cell[ TextData[{ "Definition ", CounterBox["Chapter"], ".", CounterBox["Definition"] }], "DefinitionLabel", CellBaseline -> Baseline], Inherited}, { Inherited, Inherited}}, ] 

Here's what it looks like in a notebook:

Notebook

Here's the question: is there a way to make CellFrameLabels part of a cell? I want the label to have the same background and be embedded in different text. Here is a screenshot of how I want it to look:

Desired output

I made the shortcut in bold and blue. This is what the user should not change.

+6
source share
1 answer

I do not think that this can be done the way you want. CellLabel can only be text, and CellDingbat and CellFrameLabels can be arbitrary cell expressions.

Both CellDingbat -> ... and CellFrameLabels -> {{...,None},{None,None}} work if the cell is only one row long. But do not automatically resize for multiple cells in the row (at least as far as I could tell). For instance:

 Cell["Abcdefg", "Text", CellFrame->{{0, 1}, {0, 2}}, CellMargins->{{30, 24}, {6, 6}}, CellFrameMargins->0, CellFrameColor->RGBColor[0, 0, 1], CellFrameLabels->{{Cell[" Definition 1.1 ", "Text", CellFrame -> {{2, 0}, {0, 2}}, CellFrameMargins -> 0], None}, {None, None}}, CellFrameLabelMargins->0, Background->RGBColor[0, 1, 1]] 

cellframelabel on left

Putting a CellFrameLabel on top does not have this problem, but I don't know how to align it to the left ...

 Cell["Abcde", "Text", CellFrame->{{1, 1}, {0, 2}}, CellMargins->{{30, 24}, {6, 6}}, CellFrameMargins->0, CellFrameColor->RGBColor[0, 0, 1], CellFrameLabels->{{None, None}, {None, Cell[" Definition 1.1 ", "Text", CellFrame -> {{2, 2}, {0, 2}}, CellFrameMargins -> 0]}}, CellFrameLabelMargins->0, Background->RGBColor[0, 1, 1]] 

cellframelabel at top

I think that perhaps the best solution would be to include "Defining ch.def:" in the contents of the cell.

 Cell[TextData[{ Cell["Definition 1.1: ", Editable->False, Selectable->False, Deletable->False], "Abcdefg"}], "Text", CellFrame->{{1, 1}, {0, 2}}, CellMargins->{{30, 24}, {6, 6}}, CellFrameColor->RGBColor[0, 0, 1], Background->RGBColor[0, 1, 1]] 

from above

Make it not deleted by the average user and probably almost as good as the cell (frame) label. It may include counters so that it automatically shows the correct numbering. The only problem is that it does not appear automatically, but if you just copy a pre-existing cell, then this is not a big problem.


Edit: Add alias input that creates a non-delete counter

First we get the current input aliases,

 oldAliases = InputAliases /. Options[EvaluationNotebook[], InputAliases]; 

then replace any existing Esc def Esc alias with our new one:

 newAliases = Append[DeleteCases[oldAliases, "def" -> _], "def" -> Cell[TextData[ RowBox[StyleBox[#, FontWeight->"Bold", FontColor->Blue]&/@{"Definition ", CounterBox["Chapter"], ".", CounterBox["Definition"], ": "}]],(*"Text",*) Editable -> False, Selectable -> False, Deletable -> False]]; SetOptions[EvaluationNotebook[], InputAliases -> newAliases] 

Since I don't have your stylesheet, I need to set up a couple of counters:

 CellPrint[Cell["Setting the counters", "Text", CounterAssignments -> {{"Chapter", 2}, {"Definition", 3}}]] 

Now I can use an alias in an existing cell - it inherits the style of the parent cell (unless otherwise specified):

add defn


Another option is to make a palette to go with your stylesheet. This would be useful since there is only a limited number of MenuCommandKey values ​​that you can use for your new styles (nb rewriting by default just confuses people). See this answer for an example of such a palette.

+6
source

Source: https://habr.com/ru/post/896155/


All Articles