How would I make the table of contents display a count of the number of pages in each section, so instead of
1. Foo 1
1.1 Bar 2
1.2 Baz 5
it would show
1. Foo 7
1.1 Bar 4
1.2 Baz 3
I guess something like resetting the page counter to 1 at the end the \section command? But that would capture the number of pages in the previous section, not the current one.
This is just for my own benefit (and discussion with my supervisor) rather than for readers so I don't mind if this looks sloppy or appears at the end of the document rather than the start; I just presumed that modifying the table of contents would be the easiest way to achieve it. My document consists of just chapters and sections (no subsections), so I would be happy if this just worked for sections.
It would be even better if it also worked for chapters though, because they won't necessarily equal the sum of section pages: the sum would tend to overcount because any page containing parts of more than one section will be counted twice, and on the other hand the "section 0" at the start of the chapter wouldn't be included.
If this were to work it would be nice if it could also avoid counting blank pages at the end of chapters finishing on an odd-numbered page. (I could avoid blank pages manually by just changing to one-sided layout.)