Debian Codegraph @

texmf-dist/doc/latex/fancynum/ctt.txt

raw
1 Some anwsers from comp.text.tex (Nov 99)
2 ========================================
3
4 $Id: ctt.txt,v 1.3 2000/03/15 18:31:04 ap1jjg Exp $
5
6 From: [email protected] (Heiko Oberdiek)
7 Subject: Re: TeX Macros
8 Newsgroups: comp.text.tex
9 Date: Wed, 03 Nov 1999 12:44:39 GMT
10 Organization: Rechenzentrum der Universitaet Freiburg, Germany
11
12 john green <[email protected]> wrote:
13
14 >The macro \split should take one argument which
15 >may or may not contain an "e". If the argument
16 >contains an e, say 123e45, then \split should expand
17 >to \a{123}{45}, and if not, say 12345, then \split
18 >should expand to \b{12345}.
19 >
20 >You can probably guess that I want to use TeX to format
21 >floating point numbers. This problem arises since the
22 >C call
23 >
24 > printf("%g",x)
25 >
26 >will write x in exponetial format only for x of large or
27 >small modulus.
28
29 %%% cut %%% test.tex %%% cut %%%
30 \def\floatsplit#1{\dofloatsplit#1e\END}
31 \def\dofloatsplit#1e#2\END{%
32 \ifx\\#2\\%
33 \ReturnAfterElseFi{%
34 \b{#1}%
35 }%
36 \else
37 \ReturnAfterFi{%
38 \RemoveE{#1}#2\END
39 }%
40 \fi
41 }
42 \def\RemoveE#1#2e\END{\a{#1}{#2}}
43 \long\def\ReturnAfterFi#1\fi{\fi#1}
44 \long\def\ReturnAfterElseFi#1\else#2\fi{\fi#1}
45
46 \def\a#1#2{$#1\cdot10^{#2}$}
47 \def\b#1{$#1$}
48 [\floatsplit{123e456}][\floatsplit{1}]
49 \bye
50 %%% cut %%% test.tex %%% cut %%%
51
52 Yours sincerely
53 Heiko <[email protected]>
54
55 =========================================================
56
57 From: Norman Gray <[email protected]>
58 Subject: Re: TeX Macros
59 Newsgroups: comp.text.tex
60 Date: 3 Nov 1999 12:01:02 -0000
61 Organization: University of Glasgow
62
63 Greetings,
64
65 john green <[email protected]> writes:
66
67 >The macro \split should take one argument which
68 >may or may not contain an "e". If the argument
69 >contains an e, say 123e45, then \split should expand
70 >to \a{123}{45}, and if not, say 12345, then \split
71 >should expand to \b{12345}.
72
73 How's about:
74
75 \documentclass{article}
76
77 \def\a#1#2{(A #1 #2)}
78 \def\b#1{(B #1)}
79
80 \makeatletter
81 \def\@split#1e#2e#3\end@split{%
82 \xdef\@gtempa{#2}%
83 \ifx\@gtempa\@empty
84 \b{#1}%
85 \else
86 \a{#1}{#2}%
87 \fi}
88 \def\split#1{\@split#1ee\end@split}
89
90 \begin{document}
91
92 \tracingmacros=2
93 \split{123e45}
94 \split{12345}
95 \tracingmacros=0
96
97 \end{document}
98
99 Norman
100
101 ------------------------------------------------------------------
102 Norman Gray http://www.astro.gla.ac.uk/users/norman/
103
104 =========================================================
105
106 From: Michael Downes <[email protected]>
107 Subject: Re: TeX Macros
108 Newsgroups: comp.text.tex
109 Date: 04 Nov 1999 12:40:21 -0500
110 Organization: American Mathematical Society
111
112 john green <[email protected]> writes:
113
114 > I used a modifed version of Heikos solution in the end
115 >
116 > \def\frealsplit#1e#2e#3 {%
117 > \xdef\fgtempa{#2}%
118 > \ifx\fgtempa\empty
119 > \fdecimal{#1}%
120 > \else
121 > \fexp{#1}{#2}%
122 > \fi}
123 > \def\freal#1{\frealsplit#1ee }
124
125 If you change your definition of \fdecimal slightly so that it takes two
126 arguments, but discards the second one, then you could let TeX's
127 argument scanning handle the branching and do without \fgtempa and \ifx:
128
129 \def\freal#1{\frealsplit#1ee\fexp\fdecimal\empty}
130 \def\frealsplit#1e#2e#3#4#5{#4{#1}{#2}}
131
132 E.g.:
133
134 \def\fdecimal#1#2{Decimal #1}
135 \def\fexp#1#2{Exponential #1 E #2}
136
137 Regards, Michael Downes
138
139 =========================================================
140
141 From: [email protected] (Heiko Oberdiek)
142 Subject: Re: TeX Macros
143 Newsgroups: comp.text.tex
144 Date: Fri, 05 Nov 1999 04:04:43 GMT
145 Organization: Rechenzentrum der Universitaet Freiburg, Germany
146
147 On 04 Nov 1999 12:40:21 -0500, Michael Downes <[email protected]>
148 wrote:
149
150 >john green <[email protected]> writes:
151 >
152 >> \def\frealsplit#1e#2e#3 {%
153 >> \xdef\fgtempa{#2}%
154 >> \ifx\fgtempa\empty
155 >> \fdecimal{#1}%
156 >> \else
157 >> \fexp{#1}{#2}%
158 >> \fi}
159 >> \def\freal#1{\frealsplit#1ee }
160 >
161 >If you change your definition of \fdecimal slightly so that it takes two
162 >arguments, but discards the second one, then you could let TeX's
163 >argument scanning handle the branching and do without \fgtempa and \ifx:
164 >
165 >\def\freal#1{\frealsplit#1ee\fexp\fdecimal\empty}
166 >\def\frealsplit#1e#2e#3#4#5{#4{#1}{#2}}
167
168 Beautiful!
169
170 >E.g.:
171 >
172 >\def\fdecimal#1#2{Decimal #1}
173 >\def\fexp#1#2{Exponential #1 E #2}
174
175 The second argument of \fdecimal can easily be removed:
176
177 \def\freal#1{\frealsplit#1ee\fexp\frealdecimal\empty}
178 \def\frealsplit#1e#2e#3#4#5{#4{#1}{#2}}
179 \def\frealdecimal#1#2{\fdecimal{#1}}
180
181 \def\fdecimal#1{Decimal #1}
182 \def\fexp#1#2{Exponential #1 E #2}
183
184 Best regards
185 Heiko <[email protected]>
186
187 =========================================================
188
189 From: [email protected] (Donald Arseneau)
190 Subject: Re: formatting numbers
191 Newsgroups: comp.text.tex
192 Date: 10 Nov 1999 16:55 PST
193 Organization: TRIUMF: Canada's National Meson Facility
194
195 In article <[email protected]>, john green
196 <[email protected]> writes...
197 >I've almost finished doing just this
198
199 That brings to mind your earlier question about splitting text at
200 an "e" (or E). There's no real need, and it may not be the best way.
201 Let me put on my \mathcode"8000 hat...
202
203 \newcommand\sn[1]{\ensuremath{\bgroup
204 % \mathcode`e="8000 \mathcode`E="8000 % Avoid characters ` and "
205 \mathcode 69=32768 \mathcode 101=32768
206 #1\egroup}}
207
208 \def\SciNotate{\egroup \times 10^\bgroup}
209 {
210 \def\\#1{\global\let#1\SciNotate}
211 \catcode 69=13 \catcode 101=13
212 \\e \\E
213 }
214
215
216 (I din't use one of the "nice" ways to define active characters,
217 such as \actively\let e=\SciNotate.)
218
219 Maybe you also have niceties like converting E+07 to \times 10^{7},
220 but that too could be added here.
221
222 I think there is a general benefit form not parsing the text of the
223 argument, but the benefit is small here, as I expect it is intended
224 for automatically typesetting computer output.
225
226 Another thing to look for is the dcolumn package, using "e" as the
227 "decimal" character. This will align numbers on the exponent in a
228 table.
229
230 Donald Arseneau [email protected]
231
232 End of returned message
233
234
235
236
237
238