ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Ulf Martin <ulfmartin@web.de>
Subject: Re: Numbering
Date: Fri, 07 Jul 2006 10:55:44 +0200	[thread overview]
Message-ID: <44AE2190.6050206@web.de> (raw)
In-Reply-To: <2DDE0779-E922-4C59-8C55-F4798844EC58@cox.net>

Hi

David Arnold schrieb:
> All,
> 
> Let's say I have some enumerations that are numbered, for  
> definitions, examples, theorems, etc. Let's say I want everything in  
> a section numbered consecutively, except figures. So, numbering would  
> proceed like this:

Here is a possible solution.

Idea:
- Define own counters
- Use section type with "ownnumber" option
- Wrap them suitably

Lets call "Definition"s, "Example"s etc by the name "Topic" and assume 
you want to reset the topic number with each section.

Here is the code:

<contextcode>
%%%<Topic>

\newcount\SectionNum
\def\resetSection{\SectionNum=0}
\def\stepSection{\advance\SectionNum by 1 \resetTopic}
\def\theSection{\the\SectionNum}
\resetSection

\newcount\TopicNum
\def\resetTopic{\TopicNum=0}
\def\stepTopic{\advance\TopicNum by 1}
\def\theTopic{\theSection.\the\TopicNum}
\resetTopic

\definehead[TopicHead][section=section-7]
\setuphead[TopicHead]
    [ownnumber=yes,    % use own counter TopicNum
     % more setup
    ]

\def\Topic{\dotripleempty\doTopic}
% Usage: \Topic[topic type][topic text][label]
\def\doTopic[#1][#2][#3]{
    \stepTopic
    \ifthirdargument
       \TopicHead[#3]{#1~\theTopic}{ #2}%
    \else \ifsecondargument
       \TopicHead{#1~\theTopic}{ #2}%
    \else \iffirstargument
       \TopicHead{#1~\theTopic}{}%
    \else
       \TopicHead{\theTopic}{}%
    \fi \fi \fi}


%% Example for a convenient abbreviation:
%% \Def[...][...] instead of \Topic[Definition][...][...]

\def\Def{\dodoubleempty\doDef}
% Usage: \Def[title text][label]
\def\doDef[#1][#2]{
    \ifsecondargument
       \Topic[Definition][#1][#2]
    \else\iffirstargument
       \Topic[Definition][#1]
    \else
       \Topic[Definition]
    \fi\fi}


%% I don't know if one can access section counters directly
%% So we need a wrapper for the section level that resets the
%% topic counter.

\setuphead[section]
    [ownnumber=yes,
     % more setup
    ]

\def\Section{\dosingleempty\doSection}
% Usage: \Section[label]{title text}
\def\doSection[#1]#2{
    \stepSection
    \iffirstargument
       \section[#1]{\theSection}{#2}
    \else
       \section{\theSection}{#2}
    \fi}

%%%</Topic>

%%% Example

\starttext

\Section{Things Going Wrong}

\Def[(Murphy's Law)][law:murphy]
Everything that can go wrong will go wrong sometime.

\Topic[Example][(Bread of Butter)]
An example for \in[law:murphy] is that a bread of butter falling off a 
table universally lands with the buttered side on the carpet.

\Section{Motion}

\Def[(Silly Walk)][def:sillywalk]
Silly walking is a kind of walking made up of motions that do not 
necessarily contribute to the advancement of the walker.

\Topic[Corollary][][cor:goosestep]
Goose-step is a type of silly walking as defined in \in[def:sillywalk].

\Topic[Remark]
Prussians and Bolshewists may not agree with \in[cor:goosestep].

\stoptext

</contextcode>

(I had a similar problem: I wanted a type of sections with a numbering 
only affected by specified other structural elements.)

The solution is probably not the most ConTeXt-like -- I am still on my 
way from LaTeX...

Question to TeX experts: in the context of the above, how would one 
properly define a command like

    \ProvideTopicType[Definition]{Def}

after which

    \Def[(Murphy's Law)]

produces something like

    Definition 1.2 (Murphy's Law)

Cheers!
Ulf

  reply	other threads:[~2006-07-07  8:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-07  3:45 Numbering David Arnold
2006-07-07  8:55 ` Ulf Martin [this message]
2006-07-07 21:00 ` Numbering Mojca Miklavec
2006-07-10 18:49   ` Numbering Hans Hagen
2006-07-10 18:47 ` Numbering Hans Hagen
2006-07-10 19:10   ` Numbering David Arnold
  -- strict thread matches above, loose matches on Subject: below --
2004-06-10 10:35 Numbering techw
2004-06-21 14:14 ` Numbering Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44AE2190.6050206@web.de \
    --to=ulfmartin@web.de \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).