如何为Mathematica笔记本中的细胞标签自动编号? [英] How to Autonumber Cell Tags in Mathematica Notebooks?

查看:235
本文介绍了如何为Mathematica笔记本中的细胞标签自动编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照Mathematica-8笔记本中自动编号单元格的指示进行操作,

I tried to follow the directions on autonumbering cells in a Mathematica-8 notebook, here

http://reference.wolfram.com/mathematica/tutorial/AutomaticNumbering.html

我用四个文本单元创建了一个小笔记本

I created a tiny notebook with four text cells

foo
qux
blancmange
bar

将光标放在foo之前,然后使用Insert菜单Automatic numbering项,为我提供Create Automatic Numbering Object对话框.我在Counter下拉列表中选择了项目Text,单击了This counter object单选按钮,然后选择了Huzzah!在foo之前得到数字1,大概是指笔记本中第一个Text类型的单元格.我现在看到了

Placing the cursor just before foo, I then used the Insert menu, Automatic numbering item, giving me the Create Automatic Numbering Object dialog box. I chose in the Counter dropdown then item Text, clicked This counter object radio button, and Huzzah! got the number 1 just before foo, presumably referring to the first cell of type Text in the notebook. I now see

1foo
qux
blancmange
bar

然后我在1后面插入自己的dot space以获得漂亮的外观

and I insert my own dot space after the 1 to get a nice-looking

1. foo
qux
blancmange
bar

我也对bar做同样的事情,并且看到了预期的结果

I do likewise with bar and see the expected

1. foo
qux
blancmange
4. bar

因为barText类型的第四个单元格.伟大的.现在,我想为单元格quxblancmange创建一个独立的编号系统.我使用Cell菜单,Cell Tags...Add/Remove Cell tags...项目,并将标签test放在单元格quxblancmange上.我使用Cell菜单,Cell Tags...Show cell tags项目来确保它们在那里,并且确实可以将它们显示在笔记本中(在这里,我不会尝试模仿显示器,但是这里有如果您想看看,在此问题底部的Dropbox公用文件夹中指向我的笔记本的链接).然后将光标放在qux之前,并使用Insert菜单,Automatic numbering项目,这次选择用户创建的标签Use the counter value corresponding to the location of:The first cell with the tag:test,然后单击OK,然后我得到零! blancmange之前的同上.在用我自己的dotspace在猪上涂了一点口红后,我的最终(不良)结果看起来像

because bar is the fourth cell of type Text. Great. Now I want to create an independent numbering system for cells qux and blancmange. I use Cell menu, Cell Tags..., Add/Remove Cell tags... item and put the tag test on cells qux and blancmange. I use Cell menu, Cell Tags..., Show cell tags item to make sure they're there, and, sure enough, they show up in the notebook (I won't attempt to mimic the display, here, but there is a link to my notebook in a Dropbox public folder at the bottom of this question if you want to have a look). I then position the cursor before qux and use Insert menu, Automatic numbering item, this time choosing Use the counter value corresponding to the location of:, then The first cell with the tag:, then test, my user-created tag, go OK, and i get a ZERO! ditto before blancmange. My final (bad) result, after putting a little lipstick on the pig with my own dot and space, looks like

1. foo
0. qux
0. blancmange
4. bar

如果尝试引用不存在的标签,我会得到

If try referring to a non-existent tag, I get

1. foo
XXXqux
XXXblancmange
4. bar

所以Mathematica认出了一些东西,但不是我期望或需要的东西.

so Mathematica recognized something, but not what I expected or needed.

我还需要说我尝试了Format项中的Item Numbered项,但是它有两个问题:(1)我不知道如何从1重新开始编号,因此每个块Item Numbered个单元格中的属于相同的编号项目序列.我得到1、2、3,这里,然后得到4、5、6,以后,以及7、8、9,甚至以后,等等.我真的需要独立编号的项目块:1、2、3这里,1、2 ,3个以后以及1个,2个,3个甚至更晚等等.(2)我需要给各种不同类型的单元格编号,因此我确实需要创建自己的标签并控制对它们的跟踪.

I also need to say that I tried the Item Numbered item in the Format item, but I have two problems with it: (1) I don't know how to RESTART the numbering from 1, so every block of Item Numbered cells belongs to the same sequence of numbered items. I get 1, 2, 3, here, then 4, 5, 6, later, and 7, 8, 9, even later, etc. I really need independently numbered blocks of items: 1, 2, 3 here, 1, 2, 3 later, and 1, 2, 3 even later, etc. (2) I need to number various different kinds of cells, so I really need to create my own tags and control my tracking of them.

我将非常感谢您提供任何建议.

I will be very grateful for any advice.

这是我平凡的小笔记本的链接.

Here's a link to my trivial little notebook.

CellTagsAutonumbering.nb

推荐答案

我认为您正在尝试以错误的方式使用单元格标签
(我刚刚注意到您在上面的评论中说了很多)!

I think you are trying to use cell tags in the wrong way
(and I just noticed that you said as much in a comment above)!

计数器仅计算已经发生了某种样式的单元格数量(尽管可以自动或手动重置/更改计数器).单元格标记使您以后可以引用特定的单元格,例如特定的方程式或代码块等...

The counters only count how many cells of a certain style have already occurred (although the counters can be automatically or manually reset/changed). The cell tags are so that you can refer to a specific cell later on, such as a specific equation or code block etc...

此刻,您的单元格在以下计数器CounterBox["Code", "test"]上标记了测试"我们. 该计数器将查找标记有"test"的第一个代码样式单元格并打印其编号.由于您没有标记为"test"的代码块,因此它返回零.

At the moment, your cells tagged "test" us the following counter CounterBox["Code", "test"]. This counter will look for the first code style cell tagged with "test" and print its number. Since you have no code blocks tagged "test", it returns zero.

如果您希望使用与普通文本单元格不同的计数器的类似文本的单元格, 那么您需要重新设计一种新的文字样式. 转到格式>编辑样式表.然后单击default.nb,然后将文本样式"单元格复制到笔记本的样式表中.然后,您可以对其进行修改,使其具有不同的名称(例如"Text2")和不同的计数器.然后,您可以像使用普通文本单元格一样使用CounterBox["Text2"]引用这些单元格编号.

If you want a text-like cell that uses a different counter from the normal text cells, then you need to make up a new text style. Go to Format > Edit Stylesheet. Then click on the default.nb and copy the Text style cell into your notebook's stylesheet. Then you can modify it to have a different name (e.g., "Text2") and different counter. Then you can reference these cells numbers using CounterBox["Text2"], just like you did with the normal text cells.

还可以通过将CounterBox添加到CellDingbatCellFrameLabels来自动编号.例如,请参见:将单元格定义扩展到CellFrameLabels定义

You can also have them automatically numbered by adding the CounterBox to the CellDingbat or CellFrameLabels. See, for example: Extending cell definition to CellFrameLabels definition and CounterIncrements for individual cells

这篇关于如何为Mathematica笔记本中的细胞标签自动编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆