Page 1 of 1

number contents in the frontmatter of a dita book

Posted: Wed Feb 01, 2023 4:15 pm
by ThomasN
Hello,
I need to create a DITA Book that includes an Overview chapter before the TOC. So, I included a Topic Group (alternatively a referenced Map) in the frontmatter. The chapter is listed in the TOC but the numbering of chapters starts with the first chapter after the TOC, which is actually all right, however, the document I need to create has to follow an official template, which requires that the chapter numbering starts with the Overview chapter, which is before the TOC, and even the TOC itself requires a number. (1 Overview, 2 Table of Contents, 3 Introduction…). Is there a way to accomplish that? Thank you very much for your help.

Re: number contents in the frontmatter of a dita book

Posted: Thu Feb 02, 2023 12:27 pm
by julien_lacour
Hello,

This seems quite hard to realize: you can easily number the chapters before the TOC from a custom CSS stylesheet, but for the TOC itself that's different.
By default the TOC doesn't include itself, which will lead to a different numbering inside and outside the TOC:
  • The TOC will have:
    1 Overview
    2 Introduction
  • The Content and the Bookmarks will be:
    1 Overview
    2 Table of Contents
    3 Introduction
    ...
Regards,
Julien

Re: number contents in the frontmatter of a dita book

Posted: Fri Feb 03, 2023 12:43 am
by InspectorSpacetime
Chiming in...

I decided to give this problem a try. Here's what I got so far:
tocsample.png
tocsample.png (14.74 KiB) Viewed 908 times
My solution is pretty much a hack: The "Table of Contents" entry in the TOC is created as an :after pseudo element of the "Overview" entry. Also the toc-chapter counter is reset to a new value, so that the numbering aligns with the actual one in the PDF bookmarks.

There's 2 problems: The "Table of Contents" link doesn't work. Because it's a pseudo element of the first entry, the link also points to the "Overview" chapter. I don't suppose there's a way to change or erase the href in the :after element? Erasing would suffice, because you're already in the TOC if you're trying to click it...

Also, I wasn't able to change any of the page number styles in the PDF using the counter(page, decimal) command. Because of this, the TOC entry in the...well, TOC...is in roman numerals.

But if you can live with these I can share the CSS with you.

Re: number contents in the frontmatter of a dita book

Posted: Fri Feb 03, 2023 9:50 am
by ThomasN
Great, this would be a nice solution. I would be very glad if you could share the css with me.
Thank you very much.
Best
Thomas

Re: number contents in the frontmatter of a dita book

Posted: Fri Feb 03, 2023 12:16 pm
by InspectorSpacetime
Some requirements for this to work:

1) You must use the PDF Based on HTML5 & CSS transformation
2) You can have only one chapter before the TOC
3) Your bookmap should be arranged like this:

Code: Select all

<bookmap>
    <booktitle>
        <mainbooktitle>MapTitle</mainbooktitle>
    </booktitle>
    <frontmatter>
        <topicref href="topics/overview.dita"/>
        <booklists>
            <toc/>
        </booklists>
    </frontmatter>
    <chapter href="topics/introduction.dita"/>
    <chapter href="topics/installation.dita"/>
</bookmap>
So, no topicgroup in the frontmatter. Just a single topicref (Overview). I suspect using a topicgroup would break this solution.

Here's the CSS. I got the roman numeral thing fixed. Unfortunately I haven't yet commented the CSS at all:

Code: Select all

@page {
    @bottom-right-corner { 
        content: counter(page, decimal);
    }    
}

@page table-of-contents:left {
    @top-left {
      content: string(toc-header) " | " counter(page, decimal);
    }
  }
  
@page table-of-contents:right {
    @top-right {
      content: string(toc-header) " | " counter(page, decimal);
    }
  }

*[class ~= "toc/title"]:before {
    content: "2. Table of Contents" !important;
}

.topic[is-chapter] > .topictitle1:before {
    content: counter(chapter) ". " !important;
}

.topic[is-frontmatter] > .topictitle1:before {
    content: "1. ";
}

.topic[is-chapter]#unique_2 {
    counter-reset: chapter 2;
}



*[class ~= "map/topicref"].frontmatter {
    font-weight: bold;
}

*[class ~= "map/topicref"].frontmatter .navtitle:before {
    content: counter(toc-chapter) ". ";
}

*[class ~= "map/topicref"].frontmatter .navtitle:after(1) {
    content: leader(".") 2;
}

*[class ~= "map/topicref"].frontmatter .navtitle:after(2) {
    content: "2. Table of Contents" leader(".") counter(page);
    display: block;
    margin-top: 0.5em;
}

*[class ~= "map/topicref"][is-chapter]:not([is-part]) > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]:before {
    content: counter(toc-chapter) ". "; 
}

*[class ~= "map/topicref"][is-chapter]:nth-of-type(4) {
    counter-reset: toc-chapter 2;
}

*[class ~= "map/topicref"]:first-of-type {
    counter-increment: toc-chapter;
}
Do try it out and see if it works. I'm sure this is not the only solution, and this is certainly not the most elegant one. But before something else comes up, maybe this works as an intermediate solution?

Re: number contents in the frontmatter of a dita book

Posted: Fri Feb 03, 2023 1:27 pm
by ThomasN
Thank you very much for your help but unfortunately it doesn’t work this way for me. The entry for the TOC appears several times in the TOC and the numbering in the TOC differs from the numbering in the document. Part of the problem seems to be the subtopics in the frontmatter chapter. However even if I delete them it doesn't work.
If there is no simple solution I’d rather switch to Word to create the document. Thank you very much again for your time.
TOC.png
TOC.png (41.79 KiB) Viewed 868 times

Re: number contents in the frontmatter of a dita book

Posted: Fri Feb 03, 2023 1:53 pm
by InspectorSpacetime
I'm sorry it didn't work. The "issue" seems to be that your map structure is more complex than what I was using. Hope someone else can help.