Page 1 of 1

Title numbering in Chemistry?

Posted: Mon Dec 11, 2017 4:10 pm
by Timber
Hi!

I started using Chemistry supposing that css makes PDF publishing easier than before. I guess it does but hunting down details of how to do things now seems difficult because Chemistry is so new and in Beta.

So: I found out how it is done the old way, but how do I add title numbering (1.0, 1.1., 2.1., 2.1.1 etc.) to PDF -WYSIWYG using Chemistry? I am not very professional with css, so please pay attention to all possible levels that have to be taken into consideration. (Words like 'Chapter' or 'Part' should be removed and I already managed to do that.)

Thank you,


Timo Laaksosaari

Re: Title numbering in Chemistry?

Posted: Tue Dec 12, 2017 4:49 pm
by radu_pisoi
Hi,

The default DITA Map PDF - WYSIWYG transformation display numbers before the titles of DITA chapters an parts.

To display numbers before any topic's title with a pattern like 1.0, 1.1., 2.1, you need to develop a customization CSS. For your use case, yo can use the CSS counter-reset, counter-increment properties and counter/counters CSS functions. A documentation these properties can be found:
https://developer.mozilla.org/en-US/doc ... S_counters

As a sample, I have developed a customization CSS that adds numbers before topic's titles. If you want to test it, please save the following CSS in a separate file and import it from your main custom CSS.

Code: Select all


/*
* ================================================
*
* Page numbers and titles.
*
* ================================================
*/

@media print{

/* Reset the counters */
*[class ~= "map/map"] {
counter-reset: page 1 part 0 figcount 0 tablecount 0;
}

/*
Reset the page counter on the first topic that follows the TOC placeholder:
<ot-placeholder:toc xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder" />
The page counter was used in the p-toc generating numbers for the TOC pages.
*/
*[class ~= "map/map"] > toc + *[class ~= "topic/topic"]{
counter-reset: page 1;
}



/* Titles */


/* Collect the title of the map. */
*[class ~= "map/map"][title] {
string-set: maptitle attr(title);
}
/* The bookmap title may migrate in the opentopic:map element*/
map > *[class ~= "topic/title"] {
string-set: maptitle content();
}
/* Collect the chapter titles. */
*[class ~= "topic/topic"][is-chapter]:not([is-part]) > *[class ~= "topic/title"] {
string-set: chaptertitle " | " counters(chapter, '.') " - " content();
}
/* Collect the part titles. */
*[class ~= "topic/topic"][is-part] > *[class ~= "topic/title"] {
string-set: parttitle " | " counter(part, upper-roman) " - " content(), chaptertitle ""; /* Avoid propagating a past chapter title on a new part */
}



/*
The counters are used in the static parts of the page, and before the title.
*/
*[class ~= "topic/topic"]{
counter-increment:chapter;
}
*[class ~= "topic/topic"]:first-of-type{
counter-reset:chapter 0;
}


*[class ~= "topic/topic"] > *[class ~= "topic/title"]:before {
content: counters(chapter, '.') " ";
}

*[class ~= "topic/topic"][is-part]{
counter-increment:part;

}
*[class ~= "topic/topic"][is-part] > *[class ~= "topic/title"]:before {
content: "Part " counter(part, upper-roman) ". ";
}

*[class ~= "map/map"] > front-matter,
*[class ~= "map/map"] > back-matter{
counter-increment:none;
}


@page :left {
@top-left {
content: string(maptitle) string(parttitle) string(chaptertitle) " | " counter(page);
font-size:8pt;
}
@bottom-left {
/**/
}
@bottom-right {
/**/
}
}

@page :right{
@top-right {
content: string(maptitle) string(parttitle) string(chaptertitle) " | " counter(page);
font-size:8pt;
}
@bottom-right {
/**/
}
@bottom-left {
/**/
}
}
}
Please note that this customization does not affect TOC and page margins.

Re: Title numbering in Chemistry?

Posted: Tue Dec 12, 2017 5:37 pm
by Timber
Hi Radu and thank you for your quick response.

Although not recommended I have been editing the Chemistry css-files directly. In p-page-titles-and-numbers.css I removed the text "Chapter" and some of the headers or footers to make room for new ones. However, the section you offered is there intact but still only the top level is numbered, not the topics. Is the topic title considered a 'part' here or is topic title somehow undefined?

Thanks,

Timo


The p-page-titles-and-numbers.css looks like this:

/*
* ================================================
*
* Page numbers and titles.
*
* ================================================
*/



@media print {

/* Reset the counters */
*[class ~= "map/map"] {
counter-reset: page 1 part 0 figcount 0 tablecount 0;
}

/*
Reset the page counter on the first topic that follows the TOC placeholder:
<ot-placeholder:toc xmlns:ot-placeholder="http://suite-sol.com/namespaces/ot-placeholder" />
The page counter was used in the p-toc generating numbers for the TOC pages.
*/
*[class ~= "map/map"] > toc + *[class ~= "topic/topic"]{
counter-reset: page 1;
}



/* Titles */


/* Collect the title of the map. */
*[class ~= "map/map"][title] {
string-set: maptitle attr(title);
}
/* The bookmap title may migrate in the opentopic:map element*/
map > *[class ~= "topic/title"] {
string-set: maptitle content();
}
/* Collect the chapter titles. */
*[class ~= "topic/topic"][is-chapter]:not([is-part]) > *[class ~= "topic/title"] {white-space:pre;
string-set: chaptertitle " " counter(chapter) " - " content();
}


/* Collect the part titles. */
*[class ~= "topic/topic"][is-part] > *[class ~= "topic/title"] {
string-set: parttitle counter(part, upper-roman) " - " content(), chaptertitle ""; /* Avoid propagating a past chapter title on a new part */
}



/*
The counters are used in the static parts of the page, and before the title.
*/
*[class ~= "topic/topic"][is-chapter]{
counter-increment:chapter;
}
*[class ~= "topic/topic"][is-chapter] > *[class ~= "topic/title"]:before {
content: counter(chapter) ". ";
}
*[class ~= "topic/topic"][is-part]{
counter-increment:part;
counter-reset:chapter;
}
*[class ~= "topic/topic"][is-part] > *[class ~= "topic/title"]:before {
content: counter(part, upper-roman) ". ";
}

*[class ~= "map/map"] > front-matter,
*[class ~= "map/map"] > back-matter{
counter-increment:none;
counter-reset: chapter part ;
}


@page :left {
@top-left {
/**/}
@bottom-left {
/**/
}
@bottom-right {
/**/
}
}

@page :right{
@top-right {
/**/
}
@bottom-right {
/**/
}
@bottom-left {
/**/
}
}
}

Re: Title numbering in Chemistry?

Posted: Tue Dec 12, 2017 5:59 pm
by Timber
Hi again!

At first I made a stupid mistake copying only part of your example. Now it is working fine. I guess I can use the same stuff to add the numbers to TOC.

I would really appreciate it if you could also take a look at my other problem with the line breaks.

Thanks a lot,


Timo

Re: Title numbering in Chemistry?

Posted: Wed Dec 13, 2017 11:27 am
by Timber
Hi again,

I have to go to a css course. I simply can't figure out how to add the same numbering to p-toc.css.

Help?

B.R: Timo

Re: Title numbering in Chemistry?

Posted: Thu Dec 14, 2017 5:53 pm
by radu_pisoi
Hi,

Please save the following CSS in a separate file and import it from your main custom CSS to change the numbering in the TOC section.

Code: Select all


*[class ~= "map/map"] > map {
counter-reset:toc-part;
}

/*

The case of a plain map, not a bookmap.

*/
*[class ~= "map/topicref"] {
counter-increment:toc-chapter;
}

*[class ~= "map/topicref"] > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]:before,
*[class ~= "map/topicref"] > *[class ~= "map/topicmeta"] > *[class ~= "map/linktext"]:before {
content: counters(toc-chapter, ".") " " !important;
}

*[class ~= "map/topicref"][is-chapter] > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]:before,
*[class ~= "map/topicref"][is-chapter] > *[class ~= "map/topicmeta"] > *[class ~= "map/linktext"]:before {
content: counters(toc-chapter, ".") " " !important;
color:inherit;
}

map *[class ~= "map/topicref"]:first-of-type {
counter-reset: toc-chapter;
}

/*
Bookmap.

All the parts get a part number.
Each chapter gets a chapter number.
All other topicrefs following a part do not have a number.

*/
*[class ~= "map/topicref"][is-part] {
counter-increment:toc-part;
counter-reset:none !important;
}

*[class ~= "map/topicref"][is-part] > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]:before,
*[class ~= "map/topicref"][is-part] > *[class ~= "map/topicmeta"] > *[class ~= "map/linktext"]:before {
content: "Part " counter(toc-part, upper-roman) ". " !important;
}

/* All other topicrefs that follow a part should not have a number (i.e appendices) */
*[class ~= "map/topicref"][is-part] ~ *[class ~= "map/topicref"]:not([is-part]) > *[class ~= "map/topicmeta"] > *[class ~= "topic/navtitle"]:before,
*[class ~= "map/topicref"][is-part] ~ *[class ~= "map/topicref"]:not([is-part]) > *[class ~= "map/topicmeta"] > *[class ~= "map/linktext"]:before {
content: none !important;
counter-increment:none;
}

Re: Title numbering in Chemistry?

Posted: Thu Dec 14, 2017 8:49 pm
by Timber
Great!

Thank you very much!

Timo