2
$\begingroup$

There must be a possibility to convert a CounterBox into a number. For example

CounterBox["Page", {FileNameTake[bookUrl], "someTag"}]

The suggestion

book = NotebookOpen[bookUrl];
CurrentValue[NotebookSelection[book], {"CounterValue", "Chapter"}]

does not work (if the cell is selected programmatically).

I don't know how to referene a cell with a special tag with CurrentValue, but I presume that wouldn't work either.

I don't know why I have the hint here that this question is "subjective"??

I would appreciate any help.

$\endgroup$
  • $\begingroup$ You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$ – Michael E2 Mar 8 '16 at 12:39
  • $\begingroup$ "... the hint here ..." -- where is "here"? $\endgroup$ – m_goldberg Mar 8 '16 at 12:47
  • 1
    $\begingroup$ CurrentValue[SelectedCells[], {"CounterValue", "Section"}] works fine, yet I don't know if that's the answer. The question is a little bit chaotic. $\endgroup$ – Kuba Mar 8 '16 at 12:49
  • $\begingroup$ Thank you for the comments, I will follow the instruction in future posts. The "hint" came up in a yellow window shortly after I typed the title of my question. Sorry, I am rather new in this forum. $\endgroup$ – Darwin1871 Mar 8 '16 at 22:40
6
$\begingroup$

Your basic idea seems to work for me. I used Cells instead of NotebookSelection. I tagged a cell with the tag "C2", so that the cell looked like this:

Cell["Stuff", "Text",
 CellChangeTimes->{{3.666429490958235*^9, 3.666429492522786*^9}},
 CellTags->"C2"]

Then CurrentValue returns a number:

enter image description here

It even works in another notebook. Let nb be the other notebook object.

foo = CurrentValue[
  First@Cells[nb, CellTags -> "C2"], {"CounterValue", "Chapter"}]
(*  2  *)

Note book selection works, too. Below I had selected the "Hi there!" cell.

foo = CurrentValue[
  NotebookSelection[nb], {"CounterValue", "Chapter"}]
(*  1  *)
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you Michael for your very well documented answer. Finally i tried this on my raspberry pi with version 10. And it works! But not on my version 9!! with Windows. What can be the reason? A lot of things with CurrentValue do work, but nothing with counters like Section, Page, etc. What might be the reason? Is there a bug? Or might it be some fancy Option somewhere? Or the fact that I have also an older version of mathematica installed on my system? I read somewhere that this might cause some trouble (but I never encountered any). $\endgroup$ – Darwin1871 Mar 8 '16 at 23:18
  • $\begingroup$ Hallo, maybe I shouldn't have marked this as answered. I still need a workaround because CurrentValue[] command doesn't work in version 9. And also i wonder if there is a possibility to get this NUMBER, which is generete by the CounterBox[] command and which is to be seeeen in the output. I tried a lot of things, even CopyToClipboard[%] an similar things. When I try to copy the selected number I always get the underlying CounterBox[] command. Has someone an idea? Don't want to post a question again. $\endgroup$ – Darwin1871 Mar 10 '16 at 17:32
  • $\begingroup$ @Darwin1871 Thanks for letting me know. Feel free to unaccept, if it doesn't solve your problem. I can't explore V9 as I have V10. You may edit the question to clarify your needs. Maybe someone with V9 will be able to help. My docs say that CurrentValue hasn't been updated since V9, so I'm surprised it doesn't work. Or maybe the docs are wrong. Who knows. $\endgroup$ – Michael E2 Mar 10 '16 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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