-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexamples.tex
288 lines (246 loc) · 8.07 KB
/
examples.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
\documentclass{article}
\usepackage{amsmath}
\usepackage{ulem}
\usepackage{asciimth}
\def\startTrace{\message{Starting trace...$}%
\tracingmacros=2\tracingassigns=2\tracingcommands=2%
}
\def\endTrace{\message{Ending trace...$}\tracingmacros=0\tracingassigns=0\tracingcommands=0}
\def\textbs{\char92\relax} % backslash
% OK, note this doesn't really test spaces well.
\begingroup
\catcode32=13%
\gdef\changeSpaces{%
\catcode32=13%
\catcode126=12
\let =\ %
}
\endgroup
%HACK
\def\changeSpacesBack{\catcode32=10\catcode126=13}
\def\testRow{\hline\changeSpaces\testRowA}
\def\testRowA#1{%
\changeSpacesBack
\exampleRow{\sanitizeVerbose#1\end}{`#1`}%
}
\def\exampleRow#1#2{%
{\tt\char18#1\char18}%
%& #2\tabularnewline%
& \mathcell{#2}\tabularnewline
}
% This is a little bit of a hack, but it was the easiest way I could
% figure out to get the math looking pretty inside of a table cell.
\def\mathcell#1{{
\fboxrule=0pt
\fbox{$\displaystyle #1$}%
}%
}
% We can't just set the catcodes of ^ and _ because we want them as letters
% in the \tt but as super/subscripts in the `...`.
\def\sanitizeVerbose{\futurelet\nextTok\sanitizeVerboseA}
\def\sanitizeVerboseA{%
\ifx\nextTok\bgroup\let\next=\sanitizeGroupAndRepeat
\else\let\next=\sanitizeVerboseB
\fi\next
}
\def\sanitizeGroupAndRepeat#1{%
\{\sanitizeVerbose#1\end\}\sanitizeVerbose
}
\def\sanitizeVerboseB#1{%
\ifx#1\end\let\next=\relax
\else\ifx#1^\def\next{\char94\sanitizeVerbose}%
\else\ifx#1_\def\next{\char95\sanitizeVerbose}%
% If it's a macro, unpack the name.
\else\ifcat\noexpand#1\def\def\next{\string#1\sanitizeVerbose}%
\else\def\next{#1\sanitizeVerbose}%
\fi\fi\fi\fi
\next
}
\def\rawExampleRow{\hline\changeSpaces\readFirstPart}
\def\readFirstPart#1{\changeSpacesBack\exampleRow{#1}}
\newenvironment{examples}[1]
{\renewcommand{\arraystretch}{1.5}
\renewcommand{\tabcolsep}{0.2cm}
\noindent\begin{tabular}{|p{6cm}|p{4cm}|}
\multicolumn{2}{c}{\textbf{#1}}\\}
{\hline\end{tabular}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{The {\tt asciimth} package}
\author{Judah Jacobson}
\begin{document}
\maketitle
\section{Introduction}
The {\tt asciimth} package provides a more readable way to typeset
mathematics in \LaTeX{}.
We provide a few environments to replace those provided by \LaTeX{} and {\tt amsmath}:
\begin{itemize}
\item The {\tt asciimth} and {\tt asciimth*} environments act like {\tt equation} and {\tt
equation*}, except that the math inside uses the asciimth syntax.
\item The {\tt alignA} and {\tt alignA*} environments act like {\tt align} and {\tt align*}:
formatting is done by \verb|&| and \verb|\\|, but the math inside is written using {\tt
asciimth}'s syntax.
\end{itemize}
For example, we can use the following code to typeset a formula for the root of a cubic polynomial (via Wikipedia):
\begin{verbatim}
When `x^3+a x^2+b x+c`, one of the roots is
\begin{asciimth*}
-1/3( a +root3( (m + sqrt(m^2-4k^3) ) / 2 )
+root3( (m - sqrt(m^2-4k^3) ) / 2 ))
\end{asciimth*}
where:
\begin{alignA*}
m &= 2a^3-9a,\\
k &= a^2-3b.
\end{alignA*}
\end{verbatim}
It renders as:
When `x^3+a x^2+b x+c`, one of the roots is
\begin{asciimth*}
-1/3( a +root3( (m + sqrt(m^2-4k^3) ) / 2 )
+root3( (m - sqrt(m^2-4k^3) ) / 2 ))
\end{asciimth*}
where:
\begin{alignA*}
m &= 2a^3-9a,\\
k &= a^2-3b.
\end{alignA*}
Additionally,
any text surrounded by
left-quotes (\char18\ldots\char18) will be parsed by the {\tt asciimth}
engine. For example, typing {\tt\char18 (x-1)\char94(2x)/(4-3)\char18} in
the middle of a paragraph produces `(x-1)^(2x)/(4-3)`.
That notation can be mixed with standard \TeX{} math commands by
inserting a left-quoted expression in the middle of an existing expression or
equation. For example, \verb|$\frac{1}{2}-`3/4`$| is typeset as
$\frac{1}{2}-`3/4`$. It can also be embedded into display math
(\verb|$$| or \verb|\[|) or a math environment such as {\tt multiline} or
\texttt{align}.
For compatibility with the common use of left-quotes, the empty expression
{\tt\char18\char18} is typeset as the begin-quotes symbol (``).
However, if you really need them, we provide the macros {\tt \textbs makeQuoteOther}
and {\tt\textbs makeQuoteActive} which turn that special behavior off and on, respectively.
This document displays a range of example equations as typeset by {\tt
asciimth}. It serves both as documentation and as a comprehensive
test of the package.
\begin{section}{Tables}
\begin{examples}{Simple commands}
\testRow{9+alpha}
\testRow{gamma>2 implies gamma*gamma>4}
\testRow{x ge 0 implies x x ge 0}
\testRow{t}
\testRow{1-a}
\testRow{1 234}
\testRow{a b - a\,b}
\testRow{ (9)}
\testRow{9+(4-(alpha))}
\testRow{(-)}
\testRow{[2,3)}
\testRow{"Im"(f) " such that " f>0}
\rawExampleRow{ }{` `}
\rawExampleRow{}{``}
\end{examples}
\begin{examples}{Fractions and parentheses}
\testRow{9/2}
\testRow{(1//2]/(7//4)}
\testRow{(9)/(7) + ((8))/(((15)))}
\testRow{ 24/3 + ((alpha+2)/2 * 5)/7}
\testRow{2/3/3}
\testRow{-5/zeta}
\testRow{z/((q*(2/beta to gamma)))}
\testRow{([2/3])/7}
\testRow{Phi = 1+1/(1+1/(1+cdots))}
\testRow{left< 2/3 right|}
\testRow{(7 middle| 2/3 right.}
\end{examples}
\begin{examples}{Fonts}
\testRow{hat(a) + tilde(b) + bar(c) + widehat(a b c)}
\testRow{cal(T) [bf(x)] in bb(R)^n}
\end{examples}
\begin{examples}{Exponents and subscripts}
\testRow{5^14}
\testRow{5_14}
\testRow{(9^-74)}
\testRow{ 125^-74}
\testRow{1/125^74}
\testRow{(1/125)^74}
\testRow{alpha^(2+3)/5}
\testRow{x^n y_1^-t alpha^-(beta-z)}
\testRow{(q r s)_(123)^-[456/z]}
\testRow{a_1^2}
\testRow{(x)_-i + q^r_(s)}
\testRow{(a+b)_(k_1)^(x+2)}
\testRow{sum_(n=1)^infty 1/n^2}
\testRow{int_pi^infty 1/(sin x)^2\,d x}
\testRow{lim_substack(x to 0\\ y to 1) x^2(y-1)^2}
\end{examples}
\begin{examples}{Square roots}
\testRow{sqrt 2}
\testRow{sqrt(2+4/5)}
\testRow{2/sqrt(3alpha)}
\testRow{sqrt sqrt 3}
\testRow{(2+3)/sqrt sqrt sqrt 3}
\testRow{root n (x^2+1)}
\testRow{(-b pm sqrt(b^2-4a c))/(2a)}
\testRow{sqrt x^3}
\end{examples}
\begin{examples}{Symbols}
\testRow{a_1...a_n}
\testRow{a_1,...,a_n}
\testRow{f:bb(R)^2->bb(R)}
\testRow{>= <= => != -= ~ ~= ~~ ~-}
\end{examples}
\begin{examples}{Matrices}
\testRow{matrix[y]}
\testRow{matrix(a,1,c)}
\testRow{matrix(3a;b^2;c-5d)}
\testRow{matrix[2, sqrt(x^3), x^3/(7-x); (d),e,f]}
\testRow{matrix[x;y; z right.}
\testRow{matrix[A_(1,1), ... ,A_(1,n); vdots,ddots,vdots; A_(m,1), ... ,A_(m,n)]}
\end{examples}
\begin{examples}{Embedded LaTeX environments}
\rawExampleRow
{x/env\{pmatrix\}(2 \& 3 \textbs\textbs 4 \& 5)}
{`x / env{pmatrix}(2&3\\4&5)`}
\rawExampleRow
{env\{cases\}(sqrt(x) \& " if " x >= 0\textbs\textbs "undefined" \& " otherwise.")}
{`env{cases}(sqrt(x) & " if " x >= 0\\ 0 & " otherwise.")`}
\end{examples}
\par
\par
The {\tt raw} command lets you embed raw TeX commands inside of an asciimth environment.
Unlike for other commands, curly braces must be used for {\tt raw}.
As a shortcut, you can also type \texttt{label\{equationName\}} inside of an {\tt asciimth} or {\tt alignA} environment. It will have the same effect as typing\\ {\tt raw\{\char92label\{equationName\}\}}
\begin{examples}{Braces and raw commands}
\testRow{2^(3+y) + raw{\frac{5}{6x}}}
\testRow{2^raw{\frac78}}
\rawExampleRow
{\relax2 + raw\{\textbs{}begin\{pmatrix\}2\textbs\textbs3
\textbs{}end\{pmatrix\}\}}
{`2 / raw{\begin{pmatrix}2\\3\end{pmatrix}}`}
\testRow{t*{2+alpha}^2}
\testRow{t*{(2+alpha)}^2}
\testRow{ {2+x}/{gamma^2beta}}
\testRow{ \{2/(x+y)\}^3}
\end{examples}
\end{section}
\begin{section}{Layout tests}
These examples cover a few issues which are caused by the fact that we always
use {\tt\string\left} and {\tt\string\right} delimiters:
\begin{itemize}
\item Using {\tt\string\left(\ldots\string\right)} causes different
spacing than
{\tt(\ldots)}. That issue has been resolved.
\item The parentheses around the inner `sum` in the last example
are too large; they unnecessarily grow
to cover the subscript `j`.
\end{itemize}
\begin{examples}{Parenthesis tests}
\testRow{f(x)+g(x/y)}
\testRow{(x+y)(x-y)}
\testRow{f(x^2)+f(2^(2/y))}
\testRow{(x^2)^2}
\testRow{sum(x_i)+sum(x/y).}
\testRow{sum_i(sum_j(2*x))}
\end{examples}
\end{section}
\end{document}