-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrigTable2.tex
133 lines (117 loc) · 3.97 KB
/
TrigTable2.tex
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
\documentclass{article}
\usepackage[mathbf]{euler}
\usepackage{longtable}
\usepackage{geometry}
\geometry{head=14pt,hmargin=0.5in,vmargin=1.35in}
%% Set up indexing headers and footer for fast lookup while
%% flipping pages.
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength{\headheight}{14.0pt}
\renewcommand{\headrulewidth}{0pt}
\lhead{\large\mathversion{bold}\firstmark}
\rhead{\large\mathversion{bold}\botmark}
\begin{document}
%% This function is a utility to help the sprintf
%% function keep the number of digits after the decimal
%% place at the right level to come out to 9 digits in total
%% both before and after the decimal point.
{: def digs(x)
if ("%0.8f" % x) =~ /[-+]?([0-9]*)\./
l = 10 - $1.length #$
l = (l > 0 ? l : 0)
return l
end
return(0)
end
:}
\def\tstrut{\rule[-1pt]{0pt}{11pt}}
%% Set up the longtable environment by specifying the header for
%% each page and the footer.
\begin{longtable}[c]{c|llllll}
\hline\hline
\multicolumn{1}{c|}{\mathversion{bold}$x$}&
\multicolumn{1}{c}{\mathversion{bold}$\sin(x)$}&
\multicolumn{1}{c}{\mathversion{bold}$\cos(x)$}&
\multicolumn{1}{c}{\mathversion{bold}$\tan(x)$}&
\multicolumn{1}{c}{\mathversion{bold}$\cot(x)$}&
\multicolumn{1}{c}{\mathversion{bold}$\sec(x)$}&
\multicolumn{1}{c}{\mathversion{bold}$\csc(x)$}\\
\hline\hline
\endhead
\hline\hline
\endfoot
{:
## Set up variables needed for computing the values that go into
## the table, taking care to use ruby's BigDecimal class to ensure
## accuracy. The table is set up here to go from 0 to pi/2 in
## increments of step.
require 'bigdecimal'
require 'dms'
DMS.precision = 0
step = DMS.new(0, 0, 30)
one = BigDecimal("1.0")
d0 = DMS.new(0)
d90 = DMS.new(90)
-:}
%% Treat the first line of the table, for an x value of 0 specially
%% by giving exact answers in symbolic form.
{:= "\\multicolumn{1}{c|}{\\tstrut{\\mathversion{bold}\\mark{%s}$0$}}" % d0.to_tex :}&
{:= "\\multicolumn{1}{c}{{$0$}}" :}&
{:= "\\multicolumn{1}{c}{{$1$}}" :}&
{:= "\\multicolumn{1}{c}{{$0$}}" :}&
{:= "\\multicolumn{1}{c}{{$\\infty$}}" :}&
{:= "\\multicolumn{1}{c}{{$1$}}" :}&
{:= "\\multicolumn{1}{c}{{$\\infty$}}" :}\\
%% Here is the loop for the body of the table, which starts with
%% x one step beyond 0 and pre-computes some of the functions
{: x = d0 + step
while (x < d90) do
tanx = x.tan
cotx = x.cotan
secx = x.sec
cscx = x.csc
:}
{:
## Here is where each line of the main body of the table is set.
## We use the digs function defined above to make sure that every
## column has the same number of significant digits for the functions
## that tend toward infinity.
##
## NB: I could write this comment as a LaTeX comment outside a code
## segment, but then it would end up in the generated LaTeX file,
## TrigTable.etx. Doing so made that file about 6MB in size; by
## putting the comments inside this ruby code block, the size was
## around 2MB.
-:}
\mark{{:= x.to_tex :}}
\tstrut{:= "\\mathversion{bold}#{x.to_tex}" :}&
{:= "$%0.8f$" % x.sin :}&
{:= "$%0.8f$" % x.cos :}&
{:= "$%0.*f$" % [ digs(tanx), tanx ] :}&
{:= "$%0.*f$" % [ digs(cotx), cotx ] :}&
{:= "$%0.*f$" % [ digs(secx), secx ] :}&
{:= "$%0.*f$" % [ digs(cscx), cscx ] :}\\
%% Step and loop
{:
x += step
end
:}
%% This causes a LaTeX error, but nonetheless gets the final line of
%% the table squeezed onto the last page instead of on a page by
%% itself. Uncomment if that's what you want.
%{\enlargethispage{20pt}}
%% Finally, treat the last row of the table for pi/2 specially
%% by giving exact values symbolically.
{:= "\\multicolumn{1}{c|}{\\mark{%s}\\mathversion{bold}%s}" %
[d90.to_tex, d90.to_tex] :}&
{:= "\\multicolumn{1}{c}{$1$}" :}&
{:= "\\multicolumn{1}{c}{$0$}" :}&
{:= "\\multicolumn{1}{c}{$\\infty$}" :}&
{:= "\\multicolumn{1}{c}{$0$}" :}&
{:= "\\multicolumn{1}{c}{$\\infty$}" :}&
{:= "\\multicolumn{1}{c}{$1$}" :}\\
%% End the table and document---this version comes to 649 pages!
\end{longtable}
\end{document}
% Take /that/ Charles Babbage!