jml*_*pez 6 wolfram-mathematica
我正在创建一个包含写入文档样式的笔记本.我希望Mathematica的行为类似于LaTeX,因为当我写一个"Definition"单元格然后它会写"Definition [Chapter#].[Definition#]".
要明白我的意思,请执行以下操作.在空白笔记本中创建一个单元格并将样式修改为"Chapter".您可以通过选择单元格并转到Format->Style->Other,输入来完成此操作"Chapter".
现在去Format->Edit StyleSheet....输入Chapter在输入框中.这将生成一个标记为Chapter的单元格.选择该单元格,然后单击Cell->Show Expression.此时选择您在那里看到的所有文本,并将其替换为以下内容:
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]]
Run Code Online (Sandbox Code Playgroud)
这将改变章节单元格的显示方式.我改变了颜色和字体.对我来说最重要的是CellFrameLabels.注意到我已经做到了这一点,每次你创建一个章节单元格时它会显示:Chapter [Chapter Number].

在上面的图片中,我创建了几个章节单元格,并添加了文本:": Title of Chapter #".
这很简单,我们可以创建任何单元格,应用定义并利用计数器的优势来标记单元格.
我注意到有些书的定义用方框括起来.所以在这种情况下我想创建一个包含的框Definition.这是我对细胞定义的蹩脚尝试"Definition".
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}},
]
Run Code Online (Sandbox Code Playgroud)
以下是它在笔记本中的外观:

这是一个问题:有没有办法制作CellFrameLabels细胞的一部分?我希望标签具有相同的背景,并与其他文本内联.这是我希望它看起来的屏幕截图:

我制作了"标签"粗体字和蓝色.这是用户无法修改的内容.
我认为不可能以你想要的方式做.CellLabels只能是文本,同时兼具CellDingbat并CellFrameLabels可以任意细胞表达.
无论CellDingbat -> ...和CellFrameLabels -> {{...,None},{None,None}}如果电池是唯一的一条线长的工作.但是不要为多个线路单元自动调整大小(至少据我所知).例如:
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]]
Run Code Online (Sandbox Code Playgroud)

将CellFrameLabel放在顶部没有这个问题,但我不知道如何将它对齐到左边...
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]]
Run Code Online (Sandbox Code Playgroud)

我认为最好的解决方案可能是在单元格内容中包含"定义ch.def:".
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]]
Run Code Online (Sandbox Code Playgroud)

使它不能被普通用户删除,它可能几乎与单元格(框架)标签一样好.它可以包括计数器,以便它自动显示正确的编号.唯一的问题是它不会自动出现,但如果你只是复制一个预先存在的单元格,那么这不是一个问题.
首先我们得到当前的输入别名,
oldAliases = InputAliases /. Options[EvaluationNotebook[], InputAliases];
Run Code Online (Sandbox Code Playgroud)
然后用我们的新别名替换任何现有的别名Escdef Esc:
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]
Run Code Online (Sandbox Code Playgroud)
由于我没有你的样式表,我需要设置几个计数器:
CellPrint[Cell["Setting the counters", "Text",
CounterAssignments -> {{"Chapter", 2}, {"Definition", 3}}]]
Run Code Online (Sandbox Code Playgroud)
现在我可以在现有单元格中使用别名 - 它继承了父单元格的样式(除非另有说明):

另一个选择是使用调色板来设置样式表.这很有用,因为只有有限数量的MenuCommandKey值可用于新样式(nb覆盖默认样式会让人感到困惑).请参阅此答案以获取此类调色板的示例.
| 归档时间: |
|
| 查看次数: |
400 次 |
| 最近记录: |