1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
% \iffalse
%%
%% File: ncccomma.dtx Copyright (C) 2005 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{ncccomma}
%<package> [2005/02/10 v1.0 Smart Math Comma Package (NCC)]
%
% \changes{v1.0}{2005/02/10}{Initial version}
%
%<*driver>
\let\makeindex\relax
\documentclass{ltxdoc}
\usepackage{ncccomma}
\GetFileInfo{ncccomma.sty}
\begin{document}
\title{The \textsf{ncccomma} package\thanks{This file
has version number \fileversion, last
revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{ncccomma.dtx}
\end{document}
%</driver>
% \fi
%
% The package implements the smart comma in math mode.
% Let us compare this solution with the concurrent solution from
% the |icomma| package by Walter Schmidt:
% \begin{itemize}
% \item In |icomma|, a comma in math works as the
% punctuation mark if a space goes after it. Otherwise,
% it work as an ordinary character;
% \item In |ncccomma|, a comma in math works as an ordinary
% character if a decimal character goes after it.
% Otherwise, it works as a punctuation mark.
% \end{itemize}
% The solution used in this package is more expansive because
% we compare the next character with up to ten decimal chars.
% But this solution needs less number of spaces to be inserted into
% original document (the space is only necessary in the place
% of a comma delimiting something and a decimal number).
%
% \DescribeMacro{\mathcomma}
% The original math comma is saved in the |\mathcomma| macro.
% This macro is useful together with the |dcolumn| package.
% If a comma should be \emph{printed} as the
% decimal separator in a column of type |D|, it must be specified
% as |{\mathcomma}|, rather than |{,}|, since the latter
% leads to an error. For example:
% \begin{quote}
% |\begin{tabular}{D{,}{\mathcomma}{-1}}|
% \end{quote}
%
% \DescribeMacro{\ordcommalist}
% The list of decimal characters is saved in the |\ordcommalist|.
% It initial definition is
% \begin{quote}
% |\newcommand\ordcommalist{0123456789}|
% \end{quote}
% You can redefine it if necessary.
%
% \StopEventually{}
%
% \section{The Implementation}
%
% We save the original comma in |\mathcomma| and then specify
% the comma to be an active char in math.
% \begin{macrocode}
%<*package>
\mathchardef\mathcomma\mathcode`\,
\mathcode`\,="8000
% \end{macrocode}
% No we define the meaning of comma using the well-known trick with
% upper case.
% \begin{macrocode}
\bgroup
\uccode`\~`\,%
\uppercase{%
\egroup
\def~}{\futurelet\@let@token\NCC@comma}
% \end{macrocode}
% The smart comma compares the next char with a character of the
% |\ordcommalist| in cycle. This cycle is a bit expansive,
% but it is the payment for smartness.
% \begin{macrocode}
\newcommand\ordcommalist{0123456789}
\def\NCC@comma{%
\let\@tempb\@empty
\expandafter\@tfor\expandafter\@tempa\expandafter:\expandafter=%
\ordcommalist\do{%
\expandafter\ifx\@tempa\@let@token
\let\@tempb\mathord \@break@tfor
\fi
}%
\@tempb\mathcomma
}
%</package>
% \end{macrocode}
\endinput
|