Skip to main content
added 209 characters in body
Source Link
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages is:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

However when you print the page the counters for "page" and "LastPage" evaluate:

enter image description here

So it appears that page counts are not evaluated until you actually print. So if you require the page count to appear within your notebook working environment it doesn't appear to be possible.

Edit

@user1420372 has found that showing the page breaks makes the counters work. I guess the pages remain "uncounted" until required, e.g. either by printing or evaluating and displaying page breaks.

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages is:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

However when you print the page the counters for "page" and "LastPage" evaluate:

enter image description here

So it appears that page counts are not evaluated until you actually print. So if you require the page count to appear within your notebook working environment it doesn't appear to be possible.

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages is:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

However when you print the page the counters for "page" and "LastPage" evaluate:

enter image description here

So it appears that page counts are not evaluated until you actually print. So if you require the page count to appear within your notebook working environment it doesn't appear to be possible.

Edit

@user1420372 has found that showing the page breaks makes the counters work. I guess the pages remain "uncounted" until required, e.g. either by printing or evaluating and displaying page breaks.

added 287 characters in body
Source Link
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages is:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

I am obviously overlooking somethingHowever when you print the page the counters for "page" and "LastPage" evaluate:

enter image description here

So it appears that page counts are not evaluated until you actually print. Perhaps someone else can comment?So if you require the page count to appear within your notebook working environment it doesn't appear to be possible.

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

I am obviously overlooking something. Perhaps someone else can comment?

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages is:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

However when you print the page the counters for "page" and "LastPage" evaluate:

enter image description here

So it appears that page counts are not evaluated until you actually print. So if you require the page count to appear within your notebook working environment it doesn't appear to be possible.

Source Link
Mike Honeychurch
  • 37.8k
  • 3
  • 87
  • 161

If you evaluate:

Options[EvaluationNotebook[], PageHeaders]

You will see the underlying code that generates the total pages:

CounterBox["LastPage", CounterFunction :> Identity]

Counters can be added into a notebook via the menu:

enter image description here

enter image description here

However I was unable to get the counter to return the page count. When trying other counters such as input cells or sections everything worked fine but both "Page" and "LastPage" failed to return a count (although they worked as advertised in the page header when the page is printed). e.g.

CellPrint[Cell[TextData[CounterBox["Input"]]]]

works whereas

CellPrint[Cell[TextData[CounterBox["LastPage"]]]]

didn't work.

enter image description here

I am obviously overlooking something. Perhaps someone else can comment?