2nd-level TOC entries as a single paragraph

Everything related to our flagship word processor.
Post Reply
David Sharp
Posts: 52
Joined: 2008-07-06 23:21:27
Location: Paris, France
Contact:

2nd-level TOC entries as a single paragraph

Post by David Sharp »

Hi,
I'm formatting a longish document with lots of subtitles within each chapter. This gives me an inordinately long multi-page TOC, which I'd like to reduce as much as possible.
I'd like to be able to present the second-level entries in the TOC as a single long paragraph, with a separating character such as an Em-dash.
Can anyone explain how I can modify the TOC-2 style so that it functions like a character style rather than a paragraph style? In other words, to make it look like this:
Chapter 1
— I start work at the factory — Problems with the boss — Fired just as the virus breaks out — An unexpected bonus
Chapter 2

etc.

Any help much appreciated.

User avatar
Hamid
Posts: 760
Joined: 2007-01-17 03:25:42

Re: 2nd-level TOC entries as a single paragraph

Post by Hamid »

Assuming there are only two levels of TOC entries in the document, the second-level TOC entries which are to appear in TOC as single paragraphs under their respective first-level entries will have "Do not include" applied in the Style Sheet.
When no more first-level entries remain to be added to the document, and the final TOC is created for the first time, only the first-level entries will appear in TOC. Then enter manually the second-level entries as single paragraphs under their first-level entries. You can continue to work on the document; the second-level entries thus added will remain in TOC with subsequent rebuilding of TOC provided the "Only update page numbers" option is applied.

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

Re: 2nd-level TOC entries as a single paragraph

Post by phspaelti »

Hamid is basically suggesting that you create the TOC "by hand" :?
Of course he is correct in that the thing you want to achieve can't be done with any built-in feature. He also points out one good feature here: You can tamper with the created TOC and still have it continue to work, sort of.
Adopting Hamid's basic approach, I would do as follows: Insert the TOC normally. Then use Find and Replace to reformat TOC level 2 as you suggest. This can be written as a macro. In the end as Hamid points out, if you edit further, Nisus will still let you update the page numbering without having to redo the changes to level 2. But if you have the editing part as a macro, you can just redo the whole thing easily as well.
Here are the steps as a macro:

Code: Select all

$doc = Document.active
$style2 = $doc.styleWithName 'TOC 2'
Find All $style2
Find and Replace '(^.+(?:\n.+)*)\t.*$', '\1', 'EasS'
Find and Replace '\t.*\n', ' — ', 'Eas'
philip

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

Re: 2nd-level TOC entries as a single paragraph

Post by phspaelti »

I also just wanted to ask: this way of formatting a TOC, is this still a thing? I mean, it was very popular in the 19th century. I'm getting flashbacks of Twain and Dickens. Is this maybe something that Nisus should consider as a feature?

Considering this problem: I was first wondering if one could mix TOC styles, e.g., have one style for Level 1 and another for Level 2, so that only Level 1 would get leaders and page numbers. This does not seem to be possible either. I have often wondered who actually needs more than one TOC style in a single document? What is it good for?

And finally I was surprised to (re-)discover that there is almost no way to check, control, use TOC styles with the macro language. TOC level does not show as an attribute on a paragraph style. The only way to find text included in the TOC is using the menu commands Select Next/Previous in TOC, and the only way to know the TOC level of such a selection is to check the menu. What's worst about this is that if you have adjacent paragraphs both included in TOC, then the command will select both together. It would be very tricky to try to collect the TOC from a document using a macro. The easiest way would presumably be to actually insert a TOC, copy it, and then delete it. Finally there is also no sure-fire way to find an inserted TOC in a document.
philip

David Sharp
Posts: 52
Joined: 2008-07-06 23:21:27
Location: Paris, France
Contact:

Re: 2nd-level TOC entries as a single paragraph

Post by David Sharp »

Many thanks to Hamid and Philip for these replies.

Two conclusions for me at this stage: Firstly, the feature I'm looking for doesn't currently exist in NWP (I was wondering if there was simply some bit of the manual or some forum message I'd missed).

Secondly, I don't feel able at this stage to implement the proposed workaround: I'm not all that good with macros, and I need to get this document formatted today. I can live with the longer-than-necessary TOC.
There's also a feature I want to implement, and which I'm not sure would be possible with the workaround: to have all the 2nd-level TOC entries become clickable when I convert the doc to PDF format. And as it's a document that's destined to evolve, I need the TOC to regenerate automatically each time I update it.

In trying to work out the problem for myself, I noted that it was possible to apply a character style, rather than a paragraph one, to the TOC—via the "based on" option in the style sheet view. I was disappointed, however, to find that doing that did not get rid of the return character at the end of each TOC entry.

Replying to Philip, indeed I see the same echoes of 19th-century publishing habits, which I rather like. However I would argue in favour of this becoming a feature of NWP, if resources permit.

On examining the PDF version of the NWP manual, I can't help noticing, in fact, that its TOC is extremely long: 11 pages. It's laid out to be printed, with page numbers, but I suspect that a majority of users, like me, probably open it on the screen and then click on its titles to go to the required page.
This could perhaps be a candidate for the type of function I'm looking for. (Of course in that case the page numbers would disappear, and the TOC would be laid out in a single column. I suppose a separate version could be produced for people who needed to print it out).
Just a thought.

User avatar
Hamid
Posts: 760
Joined: 2007-01-17 03:25:42

Re: 2nd-level TOC entries as a single paragraph

Post by Hamid »

phspaelti wrote:
2020-03-30 08:06:40
[...]
Considering this problem: I was first wondering if one could mix TOC styles, e.g., have one style for Level 1 and another for Level 2, so that only Level 1 would get leaders and page numbers. This does not seem to be possible either. I have often wondered who actually needs more than one TOC style in a single document? What is it good for?[...]
I had made a feature request on Oct 15, 2011, at 11:53 AM:
Allow the possibility to have a level in TOC where page numbers do not appear for an entry, while at the same time, page numbers appear for remaining levels of entries.
At that time I made three different TOC styles inserted on the same contents page. Here is an example (redacted):
Attachments
TOC w & wo p.jpg
TOC w & wo p.jpg (151.64 KiB) Viewed 3549 times

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

Re: 2nd-level TOC entries as a single paragraph

Post by martin »

David Sharp wrote:
2020-03-30 08:38:37
Firstly, the feature I'm looking for doesn't currently exist in NWP (I was wondering if there was simply some bit of the manual or some forum message I'd missed).
That's correct. Nisus Writer has no built-in way to format a generated TOC so that entries are not on a separate line. You'd need to use a macro or manual editing after generating the TOC.

I will certainly file your feature request as a potential future enhancement, thanks for sharing the idea.
It's laid out to be printed, with page numbers, but I suspect that a majority of users, like me, probably open it on the screen and then click on its titles to go to the required page.
That's right, a generated TOC is still useful for navigation even in the year 2020. Nisus Writer exports the TOC with clickable links in any generated PDFs or HTML.

In fact, if you open an exported PDF in compliant software (eg: Apple's Preview app) you can see the TOC in the sidebar, even if you never insert a generated TOC in the text itself. I'm guessing Twain and Dickens never used that feature ;)

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

Re: 2nd-level TOC entries as a single paragraph

Post by martin »

phspaelti wrote:
2020-03-30 08:06:40
Considering this problem: I was first wondering if one could mix TOC styles, e.g., have one style for Level 1 and another for Level 2, so that only Level 1 would get leaders and page numbers. This does not seem to be possible either.
This is partially possible, using a single TOC style. If you use the menu Tools > Table of Contents > Configure TOC Styles you can choose whether each level of a single TOC style includes leader tabs. Whether or not page numbers are inserted is currently controlled for the entire TOC, not on a per-level basis.
often wondered who actually needs more than one TOC style in a single document? What is it good for?
It's useful if you are cataloging multiple things within a document. For example, you might want a TOC for chapters and another TOC for all your figures.
And finally I was surprised to (re-)discover that there is almost no way to check, control, use TOC styles with the macro language.
To check the TOC level of text you'll want to work through the Attribute object and its "tocLevelForStyleName" command. You can get TOC style names from the Document object, via "activeTocStyleName" or "tocStyleNames".

But you're right that there's no way for a macro to detect an existing generated TOC.
The only way to find text included in the TOC is using the menu commands Select Next/Previous in TOC, and the only way to know the TOC level of such a selection is to check the menu. What's worst about this is that if you have adjacent paragraphs both included in TOC, then the command will select both together.
That's definitely undesirable behavior, even for regular usage outside of macros. I'll see about getting that fixed, thanks.

David Sharp
Posts: 52
Joined: 2008-07-06 23:21:27
Location: Paris, France
Contact:

Re: 2nd-level TOC entries as a single paragraph

Post by David Sharp »

Many thanks to Martin for these explanations. I very much appreciate all the clickable possibilities when transforming Nisus documents into PDFs, and I recognise that the specific problem I raised is probably not of very high priority, unless the shades of Twain and Dickens return to haunt us, and begin using computers.

Meanwhile I hope everyone's staying as safe as possible during the present crisis.

Post Reply
https://www.nisus.com/forum/viewtopic.php?f=18&t=11579
www.nisus.com
crawl=CC-MAIN-2021-04
58876
application/http; msgtype=response
sha1:RO3IWKMYE4NRQAAQVQOC2YZSNK7FDHTM
<urn:uuid:2026a24d-4909-417e-976d-d8dbc60d5878>
2021-01-17T02:49:40Z
66.33.209.86
text/html
sha1:44ZZZYLBOX753OWXMSLZUJS4SN7PZ6UW
<urn:uuid:27c3b6f7-9bb8-484f-bc0c-a912419c9b26>
https://www.nisus.com/forum/viewtopic.php?f=18&t=11579
response
<urn:uuid:1a33de9c-1b86-4781-bbd1-bdcc383eea15>
isPartOf: CC-MAIN-2021-04
publisher: Common Crawl
description: Wide crawl of the web for January 2021
operator: Common Crawl Admin (info@commoncrawl.org)
hostname: ip-10-67-67-103.ec2.internal
software: Apache Nutch 1.17 (modified, https://github.com/commoncrawl/nutch/)
robots: checked via crawler-commons 1.2-SNAPSHOT (https://github.com/crawler-commons/crawler-commons)
format: WARC File Format 1.1
conformsTo: http://iipc.github.io/warc-specifications/specifications/warc-format/warc-1.1/