Implementing a general Table of Content across single paginated post pages

I am working on a blog and most of my posts are so long they require pagination. See one of my posts. This post has a lot of pages.

The only problem is that I can’t find a way to show a table of contents that will list all the headers consistently across multiple pages.

I’ve demarcated the single post into different pages with the tag:
<!--nextpage-->.

I’m currently using the “Table of Contents Plus (TOC+)” plugin and it works pretty well in single pages, but fails when the page is paginated using <!--nextpage-->.

I am actually hoping to find assistance in writing a plugin that can do the trick.

EDITED – PROPOSED SOLUTION/HACK

In a bid to solve this problem, I have mapped the following steps to resolve this issue:

  1. Check if the page is paginated – wordpress WordPress has a global variable, $multipage that will denote whether or not a post is paginated.

  2. if the post is paginated, then the table of content code (to be written or modified) will check for headers across each page.

  3. Headers found across each page will be stored in an array and will be used to display the TOC

  4. Also, for Paginated single Post the code will be set to display the same TOC consistently across every page as opposed to displaying different TOCs per page

THE CODE

<?php
/**
 * Determines whether or not the current post is a paginated post.
 * @return   boolean    True if the post is paginated; false, otherwise.
 */
function acme_is_paginated_post() {
    global $multipage;
    return 0 !== $multipage; 
} 
?>

If post is paginated, the following checks will be made in the single.php file:

<?php if ( acme_is_paginated_post() ) { ?>
<div class="post-pagination-toc">
        <!-- paginated post TOC  display that checks headers across different poages and the displays all headers in as TOC's content uniformly across all paginated pages -->
</div>
<?php else { ?>
<div class="normal-singlepage-toc">
    <!-- normal TOC display for single non-paginated post -->
</div>
<?php } ?>

In fact, I reduced the above code into a simple function TOC_new()

<?php 
function TOC_new () {
global $numpages;
if ( is_singular() && $numpages > 1 ) {
    // This is a single post
    // and has more than one page;
    // Implement a General TOC to be displayed consistently multiple Pages and return values
} else {
    // This is a single post
    // and has only one page;
    // implement TOC code for single pages.
}
?>

Solutions Collecting From Web of "Implementing a general Table of Content across single paginated post pages"

Just inspect the current post content for <!--nextpage-->:

function wpse_check_multi_page()
{
    $num_pages    = substr_count(
        $GLOBALS['post']->post_content,
        '<!--nextpage-->'
    ) + 1;
    $current_page = get_query_var( 'page' );
    return array ( $num_pages, $current_page );
}

On page 2 of 3 that returns:

Array
(
    [0] => 3
    [1] => 2
)

On an unpaged post it returns:

Array
(
    [0] => 1
    [1] => 0
)