Skip to content

Commit 5ffbac5

Browse files
committed
Factor out duplication between note and example macros.
1 parent 98e474f commit 5ffbac5

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

source/layout.tex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@
3232
%%--------------------------------------------------
3333
%% Paragraph and bullet numbering
3434

35-
\newcounter{Paras}
36-
\counterwithin{Paras}{chapter}
37-
\counterwithin{Paras}{section}
38-
\counterwithin{Paras}{subsection}
39-
\counterwithin{Paras}{subsubsection}
40-
\counterwithin{Paras}{paragraph}
41-
\counterwithin{Paras}{subparagraph}
35+
% create a new counter that resets for each new subclause
36+
\newcommand{\newsubclausecounter}[1]{
37+
\newcounter{#1}
38+
\counterwithin{#1}{chapter}
39+
\counterwithin{#1}{section}
40+
\counterwithin{#1}{subsection}
41+
\counterwithin{#1}{subsubsection}
42+
\counterwithin{#1}{paragraph}
43+
\counterwithin{#1}{subparagraph}
44+
}
4245

46+
\newsubclausecounter{Paras}
4347
\newcounter{Bullets1}[Paras]
4448
\newcounter{Bullets2}[Bullets1]
4549
\newcounter{Bullets3}[Bullets2]

source/macros.tex

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
\or\let\s=\subparagraph\let\l=\label
9393
\fi%
9494
\s[#3]{#3\hfill[#2]}\l{#2}\addxref{#2}%
95-
\setcounter{note}{0}\setcounter{example}{0}}
95+
}
9696

9797
% A convenience feature (mostly for the convenience of the Project
9898
% Editor, to make it easy to move around large blocks of text):
@@ -267,16 +267,23 @@
267267
\newcommand{\leftshift}[1]{\ensuremath{\mathbin{\mathsf{lshift}_{#1}}}}
268268

269269
%% Notes and examples
270-
\newcounter{note}
271-
\newcounter{example}
272270
\newcommand{\noteintro}[1]{[\textit{#1}:\space}
273-
\newcommand{\noteoutro}[1]{\textit{\,---\,end #1}\kern.5pt]}
274-
\newenvironment{note}[1][Note]
275-
{\par\small\addtocounter{note}{1}\noteintro{#1 \thenote}}
276-
{\noteoutro{note}\par}
277-
\newenvironment{example}[1][Example]
278-
{\par\small\addtocounter{example}{1}\noteintro{#1 \theexample}}
279-
{\noteoutro{example}\par}
271+
\newcommand{\noteoutro}[1]{\textit{\,---\,#1}\kern.5pt]}
272+
273+
% \newnoteenvironment{ENVIRON}{BEGIN TEXT}{END TEXT}
274+
% Creates a note-like environment beginning with BEGIN TEXT and
275+
% ending with END TEXT. A counter with name ENVIRON indicates the
276+
% number of this kind of note / example that has occurred in this
277+
% subclause.
278+
\newcommand{\newnoteenvironment}[3]{
279+
\newsubclausecounter{#1}
280+
\newenvironment{#1}
281+
{\def\noteend{#3}\par\small\stepcounter{#1}\noteintro{#2}}
282+
{\noteoutro{\noteend}\par}
283+
}
284+
285+
\newnoteenvironment{note}{Note \arabic{note}}{end note}
286+
\newnoteenvironment{example}{Example \arabic{example}}{end example}
280287

281288
%% Library function descriptions
282289
\newcommand{\Fundescx}[1]{\textit{#1}}
@@ -624,11 +631,9 @@
624631

625632
%%--------------------------------------------------
626633
%% Definitions section for "Terms and definitions"
627-
\newcounter{termnote}
628634
\newcommand{\nocontentsline}[3]{}
629635
\newcommand{\definition}[2]{%
630636
\addxref{#2}%
631-
\setcounter{termnote}{0}%
632637
\let\oldcontentsline\addcontentsline%
633638
\let\addcontentsline\nocontentsline%
634639
\ifcase\value{SectionDepth}
@@ -642,6 +647,4 @@
642647
\let\addcontentsline\oldcontentsline%
643648
}
644649
\newcommand{\defncontext}[1]{\textlangle#1\textrangle}
645-
\newenvironment{defnote}
646-
{\small\addtocounter{termnote}{1}\noteintro{Note \thetermnote{} to entry}}
647-
{\noteoutro{note}\space}
650+
\newnoteenvironment{defnote}{Note \arabic{defnote} to entry}{end note}

0 commit comments

Comments
 (0)