Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am making a book, with chapters titled "Week 1", "Week 2", "Week 3", etc., and sections titled "Activity 1", "Activity 2", "Activity 3", etc., and other sections titled "Presentation 1", "Presentation 2", "Presentation 3", etc.

  • The preceding numbers, e.g. "1.1 Activity 1", are not used.
  • No other text, e.g. "Week 1 Topic" appears in the text.
  • The numbers for sections never reset.

Here is a sample table of contents, showing how I hope it will appear:

 ______________________
|                      |
|      Contents        |
|                      |
| Week 1               |
|     Activity 1       |
|     Activity 2       |
|     Presentation 1   |
| Week 2               |
|     Activity 3       |
|     Activity 4       |
|     Presentation 2   |
|______________________|

The document occassionally has other orginary chapter and section titles as well. These should get the same font formatting, but otherwise, not be modified, and appear without any number, e.g., using chapter titles "Forward", "Conclusion", and a section title called "Notes":

 ______________________
|                      |
|      Contents        |
|                      |
| Forward              |
| Week 1               |
|     Activity 1       |
|     Activity 2       |
|     Presentation 1   |
| Week 2               |
|     Activity 3       |
|     Notes            |
| Conclusion           |
|______________________|

I have tried my own solution, by removing the preceding numbers using \setuphead[chapter][number=no], creating counters, e.g. \definenumber[weekcount], then defining custom macros which call for chapter titles to use these counters, however, my solution does not work:

\definenumber[weekcount]
\definenumber[activitycount]
\definenumber[presentationcount]
\setnumber[weekcount]{1}
\setnumber[activitycount]{1}
\setnumber[presentationcount]{1}
\define\week{\chapter{Week~\getnumber[weekcount]}\incrementnumber[weekcount]}
\define\activity{\section{Activity~\getnumber[activitycount]}\incrementnumber[activitycount]}
\define\presentation{\section{Presentation~\getnumber[presentationcount]}\incrementnumber[presentationcount]}
\setuphead[chapter][number=no]
\setuphead[section][number=no]
\starttext
    \week
        \activity
            This is some text.
        \activity
                This is some text.
        \presentation
            This is some text.
    \week
        \activity
            This is some more text.
        \activity
            This is some more text.
        \presentation
            This is some more text.
\stoptext

This results in this:

 ______________________
|                      |
|      Contents        |
|                      |
| Week                 |
|     Activity         |
|     Activity 1       |
|     Presentation     |
| Week                 |
|     Activity         |
|     Activity 1       |
|     Presentation     |
|______________________|

If you remove \setuphead[chapter][number=no], results are also unusual:

 ______________________
|                      |
|      Contents        |
|                      |
| 1. Week 1.           |
|  1.1 Activity 1.     |
|  1.2 Activity 1.1    |
|  1.2 Presentation 1. |
| 2. Week 2.           |
|  2.1 Activity 2      |
|  2.2 Activity 2.1    |
|  2.3 Presentation 2. |
|______________________|
  • Why is the numbering of the counters appear in this manner, when used inside section titles?
  • How can I create custom chapter titles using a "Week " format, and similarly formatted section titles?
share|improve this question
    
The counter groupcount appears to be unused in the example -- is this on purpose? –  phg Jun 11 '12 at 6:51
    
My document has many other such counters. I forgot to delete it from my example, to keep things simple. –  Village Jun 11 '12 at 7:08
1  
These look more like enumerations rather than section headings. Why not just use enumerations? –  Aditya Jun 11 '12 at 7:19
    
I thought treating these as section titles would be simplest. The weeks are essentially chapters or units, but I just call them “Week 1” and “Week 2” because those chapters are covered on those weeks. The entire book becomes the schedule. The area saying "This is some text." in the example, might be several pages long in the actual book. –  Village Jun 11 '12 at 7:32
add comment

1 Answer

up vote 2 down vote accepted

I agree with you that exploiting the document structure is a convenient choice for this end: it offers a high degree of configurability and comes with neat extras like list (read: table of contents) building by default. So the following will be a structure based solution, leaving the enumerations based approach to somebody else.


The trick is the ownnumbers key of structure headers. It allows precise control over the counter mechanism for every head. Headers that are defined with ownnumbers=yes take a mandatory first argument by means of which their counter value can be set explicitly. Counters created by \definecounter each have their own way key that allows fine-grained control of the reset, or disabling it as required by this question (way=text).

Once the counters are in place, all that’s left is to suppress placement of the structure title element. This is done in two parts: First, all headers are defined to be accessed only implicitly. The user level macros \week, \activity and \presentation are wrappers that at the same time pass the headers their “ownnumbers” and an empty title string. Second, placement method \activityhead is defined that chooses the display string from a mapping of labels, ignoring the structure title altogether.

(Coding style is mkiv for consistency as \defineheadplacement does not support named arguments.)

\unprotect
%% (1) define the base commands. Notice the “ownnumber” key in
%%     \base_presentation and \base_activity. This lets us supply an
%%     independent numbering scheme.
\definehead [base_week]         [chapter]
\definehead [base_activity]     [section]
\definehead [base_presentation] [section]

\setuphead [part]
           [sectionresetset=default]
\setuphead [base_week]
           [number=yes,alternative=activityhead,
            sectionsegments=chapter]
\setuphead [base_activity]
           [number=yes,alternative=activityhead,
            sectionsegments=section,ownnumber=yes,
            before={\blank[line]\incrementcounter[activity]},]
\setuphead [base_presentation]
           [number=yes,alternative=activityhead,
            sectionsegments=section,ownnumber=yes,
            before={\blank[line]\incrementcounter[presentation]},]

%% (2) define a placement method for headings that omits the title.
\defineheadplacement[activityhead][vertical]#1#2{%
  \labeltext{\currenthead}\hskip\numberheaddistance #1%
}

%% (3) heading text is static so we use labels.
%%     The following line is cramped due to an exception in option
%%     parsing.
%%     Cf. http://archive.contextgarden.net/message/20120611.090327.dd9b1347.en.html
\setuplabeltext[base_week=Week,base_activity=Activity,base_presentation=Presentation]

%% (4a) define counters for use with the “presentation” and “activity”
%%      heads.
\definecounter [presentation] [start=0,way=text]
\definecounter [activity]     [start=0,way=text]
%% (4b) define a reset trigger for the part structural.
\definestructureresetset [default] [0] [0]

%% (5) define a set of wrappers. These compensate for the fact that you
%%     can’t have a simple structure head without the mandatory
%%     argument. We start with a plain one.
\define    \week{\base_week{}}
%%     The “\presentation” and “\activity” macros need special treatment
%%     to make it respect the separate counter.
\define    \activity{\base_activity    {\rawcountervalue[activity]}    \empty}
\define\presentation{\base_presentation{\rawcountervalue[presentation]}\empty}

%% (6) side effect: the table of contents needs a placement method on
%%     its own in order to conform with the requirements. This step is
%%     optional if you don’t care for a toc.
\unexpanded\def\week_list#1#2#3{%
  \blank[line]%
  {\tfa\word\sc\labeltext{\currentlist}}%
  \space#1\hfill#3\par
}   
\unexpanded\def\activity_list#1#2#3{%
  \hskip\emwidth 
  \labeltext{\currentlist}%
  \space#1\hfill#3\par
}       

\setuplist [base_week]         [alternative=command,command=\week_list]
\setuplist [base_activity]     [alternative=command,command=\activity_list]
\setuplist [base_presentation] [alternative=command,command=\activity_list]
\protect

\starttext
\placelist[base_week, base_activity, base_presentation]\page
\part {My Life ...}
    \week
        \activity
            Dear diary. Today I was pompous and my sister was crazy.
        \activity
                This is some text.
        \activity
            This is some text.
    \week
        \activity
            This is some more text.
        \presentation
            This is some more text.
        \activity
            This is some more text.
        \activity
            This is some more text.
    \part{... the Exciting Story of a Great Man}
    \week
       \activity
            This is yet some more text.
        \presentation
            This is yet some more text.
        \activity
            This is yet some more text.
\stoptext

example

share|improve this answer
    
This works very well, but when I add \part{Introduction} to the document, the numbering of all of the "week" titles resets and becomes "Week 1.1", "Week 1.2", etc. –  Village Jun 13 '12 at 1:16
1  
Add sectionsegments=chapter (chapter is the second structure level) to the definition of \base_week for the prefix to disappear. But introducing a higher sectioning level (part) leads for the weeks to stop being numbered continuously. Is that ok? –  phg Jun 13 '12 at 4:48
    
Try it again, should handle parts nicely now. –  phg Jun 13 '12 at 4:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.