From 0d2480b40cef16a8cf30cce2c9e5eb7943804444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BAnar=20Berg?= Date: Thu, 30 Nov 2023 18:13:20 -0800 Subject: [PATCH] Make special case differential operator When an inputted d is most likely a part of a differential automatically map it to an italic operator with appropriate spacing. Also fix spacing issues around operators inside fractions and groups. **Output Changes** * Differential d now renders as an operator with and rspace of 0. If inside fractions it also has an lspace of 0. * First operators in groups now have an lspace of 0. This was true of all first operators in matricies. But now it applies to all operators in groups, unless it is a lone operator, in which case it has it by default. * Spaces after a singleton group element no longer puts the element in an unessisary . Resolves: #53 --- demo/test-cases.html | 30 +++++++-- docs/index.html | 17 +++-- docs/main.js | 10 +-- src/compiler/parser/handlers/command.js | 20 ++++-- src/compiler/parser/handlers/group.js | 42 ++++++++---- src/compiler/parser/handlers/index.js | 1 + src/compiler/parser/handlers/infix.js | 46 +++++++++++-- src/compiler/parser/handlers/prefix.js | 36 ++++++++-- src/compiler/parser/handlers/prefix.test.js | 2 +- src/compiler/parser/handlers/space.js | 6 +- src/compiler/parser/handlers/term.js | 62 ++++++++++++++++-- src/compiler/parser/parse.js | 3 + src/compiler/parser/utils.js | 34 ++++++++++ src/compiler/tokenizer/scanners/backslash.js | 5 +- .../transformer/transforms/matrix-group.js | 30 +-------- test/snapshots/groupings.js.md | 2 +- test/snapshots/groupings.js.snap | Bin 1025 -> 1029 bytes test/snapshots/matrices.js.md | 8 +-- test/snapshots/matrices.js.snap | Bin 922 -> 919 bytes test/snapshots/operators.js.md | 4 +- test/snapshots/operators.js.snap | Bin 1065 -> 1061 bytes test/snapshots/options.js.md | 4 +- test/snapshots/options.js.snap | Bin 597 -> 577 bytes test/snapshots/roots.js.md | 2 +- test/snapshots/roots.js.snap | Bin 605 -> 618 bytes test/snapshots/standard-functions.js.md | 2 +- test/snapshots/standard-functions.js.snap | Bin 699 -> 705 bytes test/snapshots/sub-supscripts.js.md | 2 +- test/snapshots/sub-supscripts.js.snap | Bin 666 -> 683 bytes test/standard-functions.js | 2 +- 30 files changed, 272 insertions(+), 98 deletions(-) create mode 100644 src/compiler/parser/utils.js diff --git a/demo/test-cases.html b/demo/test-cases.html index 23f705d..1978e57 100644 --- a/demo/test-cases.html +++ b/demo/test-cases.html @@ -76,7 +76,7 @@

Operators

- bf F @ bf G : U sube RR^3 -> RR^2 + bf F @ bf G : U sube RR^3 -> RR^2 e = sum_(n=0)^oo 1 / n! @@ -85,10 +85,12 @@

Operators

f'(x), f''(x), f'''(x), f''''(x) - p(a | b) = p(b | a)p(a) / p(b) + p(a | b) = p(b | a)p(a) / p(b) + + f(a) - f(b) = int_b^a f'(x) dx - P_k(x) = f(a) + f'(a)(x-a) + f''(a) / 2! (x-a)^2 + cdots + f^(k)(a) / k! (x-a)^k + P_k(x) = f(a) + f'(a)(x-a) + f''(a) / 2! (x-a)^2 + cdots + f^(k)(a) / k! (x-a)^k @@ -98,6 +100,10 @@

Operators

oint_(del S) bf F * d bf s = dint_S grad xx bf F * d bf s + + + oint_C (L dx + M dy) = dint_D ((del M)/(del x) - (del L)/(del y)) dx dy + @@ -109,6 +115,8 @@

Whitespace

a b a b a b + a b + a b @@ -181,6 +189,18 @@

Fractions

a/ b // + + df = df / dx dx + + + + f'(x) = df / dx (x) + + + + f''(x) = (d^2 f) / dx^2 (x) + + phi = 1+1/ 1+1/ 1+1/ 1+1/ 1+ddots @@ -237,7 +257,7 @@

Groupings

NN = {1, 2, 3, ...} - (: V(t)^2 :) = lim_(T->oo) 1/T int_(-T/2)^(T/2) V(t)^2 dt + (: V(t)^2 :) = lim_(T->oo) 1/T int_(-T/2)^(T/2) V(t)^2 dt @@ -254,7 +274,7 @@

Super and Subscripts

(X^T)_ i.,j = X_ j.,i - ln x = int_1^x 1/t dt + ln x = int_1^x 1/t dt diff --git a/docs/index.html b/docs/index.html index 7e19235..14edb42 100644 --- a/docs/index.html +++ b/docs/index.html @@ -31,7 +31,7 @@

Mathup

- +
@@ -441,6 +441,9 @@

Basics

write. If a character comes from one of the mathematical operator code blocks it will wrap it in an <mo> tag, otherwise it will be wrapped in an <mi> tag. + Additionally d will be wrapped in an + <mo> tag if it obviously a part of a + differential.