Skip to content

Commit 4148449

Browse files
committed
[macros] Separate sections a bit more cleanly, document macro length
The macro length hints help align comments on codeblocks even in the presence of macro use, by providing the relevant offset between real and effective column number.
1 parent 475cc82 commit 4148449

File tree

1 file changed

+42
-23
lines changed

1 file changed

+42
-23
lines changed

source/macros.tex

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
11
%!TEX root = std.tex
2+
23
% Definitions and redefinitions of special commands
4+
%
5+
% For macros that are likely to appear inside code blocks, we may provide a
6+
% "macro length" correction value, which can be used to determine the effective
7+
% column number where an emitted character appears, by adding the macro length,
8+
% plus 2 for the escape-'@'s, plus 2 for the braces, to the real column number.
9+
%
10+
% For example:
11+
%
12+
% \newcommand{\foo[1]{#1} % macro length: 4
13+
%
14+
% \begin{codeblock}
15+
% int a = 10; // comment on column 20
16+
% int b = @\foo{x}@; // comment also on effective column 20
17+
%
18+
% Here the real column of the second comment start is offset by 8 (4 + macro length).
319

420
%%--------------------------------------------------
521
%% Difference markups
22+
%%--------------------------------------------------
623
\definecolor{addclr}{rgb}{0,.6,.6}
724
\definecolor{remclr}{rgb}{1,0,0}
825
\definecolor{noteclr}{rgb}{0,0,1}
@@ -18,25 +35,13 @@
1835
\newcommand{\remitem}[1]{\item\removed{#1}}
1936

2037
\newcommand{\ednote}[1]{\textcolor{noteclr}{[Editor's note: #1] }}
21-
% \newcommand{\ednote}[1]{}
2238

23-
\newenvironment{addedblock}
24-
{
25-
\color{addclr}
26-
}
27-
{
28-
\color{black}
29-
}
30-
\newenvironment{removedblock}
31-
{
32-
\color{remclr}
33-
}
34-
{
35-
\color{black}
36-
}
39+
\newenvironment{addedblock}{\color{addclr}}{\color{black}}
40+
\newenvironment{removedblock}{\color{remclr}}{\color{black}}
3741

3842
%%--------------------------------------------------
3943
%% Grammar extraction.
44+
%%--------------------------------------------------
4045
\def\gramSec[#1]#2{}
4146

4247
\makeatletter
@@ -50,12 +55,14 @@
5055

5156
%%--------------------------------------------------
5257
% Escaping for index entries. Replaces ! with "! throughout its argument.
58+
%%--------------------------------------------------
5359
\def\indexescape#1{\doindexescape#1\stopindexescape!\doneindexescape}
5460
\def\doindexescape#1!{#1"!\doindexescape}
5561
\def\stopindexescape#1\doneindexescape{}
5662

5763
%%--------------------------------------------------
5864
%% Cross references.
65+
%%--------------------------------------------------
5966
\newcommand{\addxref}[1]{%
6067
\glossary[xrefindex]{\indexescape{#1}}{(\ref{\indexescape{#1}})}%
6168
}
@@ -66,6 +73,7 @@
6673
% number, a name, and a short tag. The depth is an integer in
6774
% the range [0,5]. (If it proves necessary, it wouldn't take much
6875
% programming to raise the limit from 5 to something larger.)
76+
%%--------------------------------------------------
6977

7078
% Set the xref label for a clause to be "Clause n", not just "n".
7179
\makeatletter
@@ -112,6 +120,7 @@
112120

113121
%%--------------------------------------------------
114122
% Indexing
123+
%%--------------------------------------------------
115124

116125
% Layout of general index
117126
\newcommand{\rSecindex}[2]{\section*{#2}\pdfbookmark[1]{#2}{pdf.idx.#1.#2}\label{idx.#1.#2}}
@@ -201,6 +210,7 @@
201210

202211
%%--------------------------------------------------
203212
% General code style
213+
%%--------------------------------------------------
204214
\newcommand{\CodeStyle}{\ttfamily}
205215
\newcommand{\CodeStylex}[1]{\texttt{#1}}
206216

@@ -214,14 +224,14 @@
214224
\newcommand{\term}[1]{\textit{#1}}
215225
\newcommand{\gterm}[1]{\GrammarStylex{#1}}
216226
\newcommand{\fakegrammarterm}[1]{\gterm{#1}}
217-
\newcommand{\keyword}[1]{\tcode{#1}\indextext{\idxcode{#1}}}
227+
\newcommand{\keyword}[1]{\tcode{#1}\indextext{\idxcode{#1}}} % macro length: 8
218228
\newcommand{\grammarterm}[1]{\indexgram{\idxgram{#1}}\gterm{#1}}
219229
\newcommand{\grammartermnc}[1]{\indexgram{\idxgram{#1}}\gterm{#1\nocorr}}
220230
\newcommand{\regrammarterm}[1]{\textit{#1}}
221-
\newcommand{\placeholder}[1]{\textit{#1}}
222-
\newcommand{\placeholdernc}[1]{\textit{#1\nocorr}}
223-
\newcommand{\exposid}[1]{\tcode{\placeholder{#1}}}
224-
\newcommand{\exposidnc}[1]{\tcode{\placeholdernc{#1}}\itcorr[-1]}
231+
\newcommand{\placeholder}[1]{\textit{#1}} % macro length: 12
232+
\newcommand{\placeholdernc}[1]{\textit{#1\nocorr}} % macro length: 14
233+
\newcommand{\exposid}[1]{\tcode{\placeholder{#1}}} % macro length: 8
234+
\newcommand{\exposidnc}[1]{\tcode{\placeholdernc{#1}}\itcorr[-1]} % macro length: 10
225235
\newcommand{\defnxname}[1]{\indextext{\idxxname{#1}}\xname{#1}}
226236
\newcommand{\defnlibxname}[1]{\indexlibrary{\idxxname{#1}}\xname{#1}}
227237

@@ -238,10 +248,12 @@
238248

239249
%%--------------------------------------------------
240250
%% allow line break if needed for justification
251+
%%--------------------------------------------------
241252
\newcommand{\brk}{\discretionary{}{}{}}
242253

243254
%%--------------------------------------------------
244255
%% Macros for funky text
256+
%%--------------------------------------------------
245257
\newcommand{\Cpp}{\texorpdfstring{C\kern-0.05em\protect\raisebox{.35ex}{\textsmaller[2]{+\kern-0.05em+}}}{C++}}
246258
\newcommand{\CppIII}{\Cpp{} 2003}
247259
\newcommand{\CppXI}{\Cpp{} 2011}
@@ -259,6 +271,7 @@
259271

260272
%%--------------------------------------------------
261273
%% States and operators
274+
%%--------------------------------------------------
262275
\newcommand{\state}[2]{\tcode{#1}\ensuremath{_{#2}}}
263276
\newcommand{\bitand}{\ensuremath{\mathbin{\mathsf{bitand}}}}
264277
\newcommand{\bitor}{\ensuremath{\mathbin{\mathsf{bitor}}}}
@@ -462,10 +475,11 @@
462475

463476
%%--------------------------------------------------
464477
%% Environments for code listings.
478+
%%--------------------------------------------------
465479

466-
% We use the 'listings' package, with some small customizations. The
467-
% most interesting customization: all TeX commands are available
468-
% within comments. Comments are set in italics, keywords and strings
480+
% We use the 'listings' package, with some small customizations.
481+
% The most interesting customization: all TeX commands are available
482+
% within comments. Comments are set in italics, keywords and strings
469483
% don't get special treatment.
470484

471485
\lstset{language=C++,
@@ -530,12 +544,14 @@
530544

531545
%%--------------------------------------------------
532546
%% Indented text
547+
%%--------------------------------------------------
533548
\newenvironment{indented}[1][]
534549
{\begin{indenthelper}[#1]\item\relax}
535550
{\end{indenthelper}}
536551

537552
%%--------------------------------------------------
538553
%% Library item descriptions
554+
%%--------------------------------------------------
539555
\lstnewenvironment{itemdecl}
540556
{
541557
\lstset{escapechar=@,
@@ -562,6 +578,7 @@
562578

563579
%%--------------------------------------------------
564580
%% Bnf environments
581+
%%--------------------------------------------------
565582
\newlength{\BnfIndent}
566583
\setlength{\BnfIndent}{\leftmargini}
567584
\newlength{\BnfInc}
@@ -636,6 +653,7 @@
636653

637654
%%--------------------------------------------------
638655
%% Environment for imported graphics
656+
%%--------------------------------------------------
639657
% usage: \begin{importgraphic}{CAPTION}{TAG}{FILE}
640658

641659
\newenvironment{importgraphic}[3]
@@ -651,6 +669,7 @@
651669

652670
%%--------------------------------------------------
653671
%% Definitions section for "Terms and definitions"
672+
%%--------------------------------------------------
654673
\newcommand{\nocontentsline}[3]{}
655674
\newcommand{\definition}[2]{%
656675
\addxref{#2}%

0 commit comments

Comments
 (0)