How to automate creating a TOC with active hyperlinks?

Everything related to our flagship word processor.
Post Reply
fgvs
Posts: 14
Joined: 2015-12-21 07:46:31

How to automate creating a TOC with active hyperlinks?

Post by fgvs » 2016-02-05 09:32:58

I just imported into NWP an essay that I'll be finishing here. I still can't quite believe how easy it was to apply styles to all parts of the text in this document using the tools NWP provides. It took me about five minutes. This is awesome!

This said, I've hit a minor bump in the road. I'm finishing a an essay that will be published online and is supposed to have a TOC with hyperlinks pointing to to the various headings and subheadings in the essay. (I mean hyperlinks that are active in the NWP document, not just in a PDF.) I'm aware that I can achieve this by creating a TOC with no page numbers, and then adding hyperlinks to each entry in the TOC, one by one. However, (i) this is a pretty tedious process, and (ii) I'm guessing that all the hyperlinks will vanish whenever I update the TOC.

So my question is, is it possible to automatically create a TOC with hyperlinks that will stick even if the TOC is updated? And, if not, then is it possible to at least automate the process of inserting hyperlinks to each and every level of the TOC?

Thank you in advance for any clues.

Francisco

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to automate creating a TOC with active hyperlinks?

Post by phspaelti » 2016-02-05 09:43:42

I'm not sure I understand the problem. A TOC in Nisus already gives you 'hyperlinks'. You can either use the TOC in the Navigator, or if you insert an actual TOC in the document, jump to the section by clicking on the page numbers of the TOC.

If you really wanted, it would be possible to create a macro that inserted hyperlinks automatically. But considering what I said above, I'm not going to rush out and write that macro right now.
philip

fgvs
Posts: 14
Joined: 2015-12-21 07:46:31

Re: How to automate creating a TOC with active hyperlinks?

Post by fgvs » 2016-02-05 10:09:23

Hi Philip, thanks for the swift reply. To clarify, what I need is a TOC in the document, with hyperlinks not pages (since this will be an html document in future). I actually did that already. I created a TOC with no page numbers, then applied the hyperlinks manually, one by one. But I thought that, next time, I'd like to be able to automate this process.

Francisco

User avatar
martin
Official Nisus Person
Posts: 4261
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: How to automate creating a TOC with active hyperlinks?

Post by martin » 2016-02-05 15:40:34

You can use Nisus Writer Pro's existing TOC feature to accomplish what you'd like. The only thing to change is that you need to set your TOC style so it doesn't display page numbers. Here are the details:

1. Show the TOC style editor using the menu Tools > Table of Contents > Configure TOC Styles.
2. Turn off the option "include page numbers" for the desired TOC style(s).
3. Click the button "Apply Changes" to confirm your changes and dismiss the dialog.
4. Insert a generated TOC into your document using the menu Tools > Table of Contents > Insert TOC.

You can now export your document to PDF or HTML and the TOC will maintain clickable links. If you later change your document, just rebuild the inserted TOC (using the main menu or contextual menu).

Please let us know if you have any questions.

fgvs
Posts: 14
Joined: 2015-12-21 07:46:31

Re: How to automate creating a TOC with active hyperlinks?

Post by fgvs » 2016-02-06 04:06:52

Thank you, Martin. I was hoping there was a convenient way to get a TOC without page numbers, and with clickable links, in the rtf document itself (as opposed to only in the pdf or html exports). But it's not important in the long run, that's not something I'd need often. And the existing panoply of flexible tools is superb. Thanks again.

Francisco

User avatar
phspaelti
Posts: 912
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to automate creating a TOC with active hyperlinks?

Post by phspaelti » 2016-02-08 08:59:08

Hello Francisco,
Well, I finally got around to the possibility of writing a macro to do this. Considering how the Nisus macro language is built this should be straightforward. But it turns out to be surprisingly difficult. Anyhow here's a macro that seems to do the job:
Hyperlinks for TOC.nwm
(6.3 KiB) Downloaded 49 times
Now here the caveats.

The macro turned out to be a bit complicated, because Nisus actually has no simple way to know where or what a TOC is. It can tell which text has been marked for inclusion in the TOC, but it can't see the generated TOC. So my macro uses the menu status to try to identify the TOC bits. (If the menu command "Rebuild TOC" is enabled for a given selection, it must be part of a TOC).

A related problem is that Nisus allows multiple TOCs (each with its own TOC style). I just wrote the macro to deal with the "first" one, which is probably the default TOC. I haven't tested it on a document with multiple TOCs. Most people probably only use one anyhow.

Another problem is the tab character. When a TOC is created the tabs are stripped from TOC marked text and replaced with a character (or characters) set in the TOC style dialog. The default is probably a space for most people, and that is what is assumed in this macro, but there is no way for the macro to know. If it's something else, this macro will probably not insert any links. (If your TOC marked text doesn't have any tabs, then this is presumably irrelevant.) If you are not using a space, then you should adjust this in the macro.

Finally I'm not sure what will happen if you run this macro multiple times. Probably Nisus will start accumulating bookmarks. (Note that the bookmarks are "hidden" bookmarks. They won't show in the bookmarks menu in the Navigator.) So theoretically the macro should clean out previous bookmarks, or reuse the ones already there. I haven't done this. If problems develop with a file because of this, one might have to write a clean-up macro.

Hope this is useful.
philip

fgvs
Posts: 14
Joined: 2015-12-21 07:46:31

Re: How to automate creating a TOC with active hyperlinks?

Post by fgvs » 2016-02-09 00:44:09

Many thanks, Philip! I appreciate the hark work. Despite all the caveats, in my case you just turned drudgery into a brilliant pass of magic. Clean and efficient! It's good to know there's an active macro wizard in this community. Thanks again.

Francisco

Post Reply