From ec0cf17081c06226f8cd846661624267b3ee47c7 Mon Sep 17 00:00:00 2001 From: anko9801 Date: Mon, 10 Oct 2022 15:08:44 +0900 Subject: [PATCH 1/4] add overarrow and underarrow --- src/accent.satyh | 142 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 135 insertions(+), 7 deletions(-) diff --git a/src/accent.satyh b/src/accent.satyh index a5dd2d9..025343c 100644 --- a/src/accent.satyh +++ b/src/accent.satyh @@ -23,6 +23,11 @@ module AZMathAccent : sig direct \widehat : [float?; math;] math-cmd direct \overline: [math;] math-cmd direct \overrightarrow: [math;] math-cmd + direct \overleftarrow: [math;] math-cmd + direct \overleftrightarrow: [math;] math-cmd + direct \underrightarrow: [math;] math-cmd + direct \underleftarrow: [math;] math-cmd + direct \underleftrightarrow: [math;] math-cmd end = struct @@ -122,6 +127,18 @@ end = struct in text-in-math MathOrd embedf + let path-leftarrowhead x-start wid-arrowhead = + start-path (x-start +' 2.5pt, wid-arrowhead) + |> bezier-to (x-start +' 2.0pt, wid-arrowhead *' 0.5) (x-start +' 1.5pt, wid-arrowhead *' 0.167) (x-start, 0pt) + |> bezier-to (x-start +' 1.5pt, 0pt -' wid-arrowhead *' 0.167) (x-start +' 2.0pt, 0pt -' wid-arrowhead *' 0.5) (x-start +' 2.5pt, 0pt -' wid-arrowhead) + |> terminate-path + + let path-rightarrowhead x-end wid-arrowhead = + start-path (x-end -' 2.5pt, wid-arrowhead) + |> bezier-to (x-end -' 2.0pt, wid-arrowhead *' 0.5) (x-end -' 1.5pt, wid-arrowhead *' 0.167) (x-end, 0pt) + |> bezier-to (x-end -' 1.5pt, 0pt -' wid-arrowhead *' 0.167) (x-end -' 2.0pt, 0pt -' wid-arrowhead *' 0.5) (x-end -' 2.5pt, 0pt -' wid-arrowhead) + |> terminate-path + let-math \overrightarrow m = let embedf ctx = @@ -137,21 +154,132 @@ end = struct let x-end = wid -' 1pt in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in + [ + stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); + ] + in + inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) + in + text-in-math MathOrd embedf - let path-arrowhead = - start-path (x-end -' 2.5pt, wid-arrowhead) - |> bezier-to (x-end -' 2.0pt, 1.5pt) (x-end -' 1.5pt, 0.5pt) (x-end, 0pt) - |> bezier-to (x-end -' 1.5pt, -0.5pt) (x-end -' 2.0pt, -1.5pt) (x-end -' 2.5pt, (0pt -' wid-arrowhead)) - |> terminate-path - in + let-math \overleftarrow m = + + let embedf ctx = + let fsize = get-font-size ctx in + let margin = fsize *' 0.25 in + let wid-arrowhead = 3pt in + + let deco (x, y) wid ht dp = + let text-color = get-text-color ctx in + let ht-base = y +' ht -' wid-arrowhead in + + let x-start = 0pt in + let x-end = wid -' 1pt in + + let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); - stroke 0.5pt text-color (path-arrowhead |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); ] in inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) in text-in-math MathOrd embedf + let-math \overleftrightarrow m = + + let embedf ctx = + let fsize = get-font-size ctx in + let margin = fsize *' 0.25 in + let wid-arrowhead = 3pt in + + let deco (x, y) wid ht dp = + let text-color = get-text-color ctx in + let ht-base = y +' ht -' wid-arrowhead in + + let x-start = 0pt in + let x-end = wid -' 1pt in + + let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in + [ + stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); + ] + in + inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) + in + text-in-math MathOrd embedf + + let-math \underrightarrow m = + let embedf ctx = + let fsize = get-font-size ctx in + let margin = fsize *' 0.25 in + let wid-arrowhead = 3pt in + + let deco (x, y) wid ht dp = + let text-color = get-text-color ctx in + let ht-base = y -' wid-arrowhead in + + let x-start = 0pt in + let x-end = wid -' 1pt in + + let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in + [ + stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); + ] + in + inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) + in + text-in-math MathOrd embedf + + let-math \underleftarrow m = + let embedf ctx = + let fsize = get-font-size ctx in + let margin = fsize *' 0.25 in + let wid-arrowhead = 3pt in + + let deco (x, y) wid ht dp = + let text-color = get-text-color ctx in + let ht-base = y -' wid-arrowhead in + + let x-start = 0pt in + let x-end = wid -' 1pt in + + let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in + [ + stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); + ] + in + inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) + in + text-in-math MathOrd embedf + + let-math \underleftrightarrow m = + let embedf ctx = + let fsize = get-font-size ctx in + let margin = fsize *' 0.25 in + let wid-arrowhead = 3pt in + + let deco (x, y) wid ht dp = + let text-color = get-text-color ctx in + let ht-base = y -' wid-arrowhead in + + let x-start = 0pt in + let x-end = wid -' 1pt in + + let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in + [ + stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); + ] + in + inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) + in + text-in-math MathOrd embedf end From 538bd01fb17fd0e4c9e78f8cfbfe2bc2630465d9 Mon Sep 17 00:00:00 2001 From: anko9801 Date: Mon, 10 Oct 2022 15:21:00 +0900 Subject: [PATCH 2/4] fix last position of rightarrowhead --- src/accent.satyh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/accent.satyh b/src/accent.satyh index 025343c..1287b0d 100644 --- a/src/accent.satyh +++ b/src/accent.satyh @@ -151,7 +151,7 @@ end = struct let ht-base = y +' ht -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ @@ -175,7 +175,7 @@ end = struct let ht-base = y +' ht -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ @@ -199,7 +199,7 @@ end = struct let ht-base = y +' ht -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ @@ -223,7 +223,7 @@ end = struct let ht-base = y -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ @@ -246,7 +246,7 @@ end = struct let ht-base = y -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ @@ -269,7 +269,7 @@ end = struct let ht-base = y -' wid-arrowhead in let x-start = 0pt in - let x-end = wid -' 1pt in + let x-end = wid in let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ From e63ffacea58186a14509b0a739395a6d281a33e0 Mon Sep 17 00:00:00 2001 From: anko9801 Date: Mon, 10 Oct 2022 15:27:29 +0900 Subject: [PATCH 3/4] fix commands.md --- commands.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/commands.md b/commands.md index c2e2d6e..00a9ef5 100644 --- a/commands.md +++ b/commands.md @@ -57,6 +57,11 @@ * `\widehat` * `\overline` * `\overrightarrow` +* `\overleftarrow` +* `\overleftrightarrow` +* `\underrightarrow` +* `\underleftarrow` +* `\underleftrightarrow` ## Matrices From 34a37201052f4aa90dd0513fd15480b902cdbc0c Mon Sep 17 00:00:00 2001 From: anko9801 Date: Mon, 10 Oct 2022 16:51:41 +0900 Subject: [PATCH 4/4] referctoring --- src/accent.satyh | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/accent.satyh b/src/accent.satyh index 1287b0d..4a0b23a 100644 --- a/src/accent.satyh +++ b/src/accent.satyh @@ -127,12 +127,12 @@ end = struct in text-in-math MathOrd embedf + let path-arrowline x-start x-end = Gr.line (x-start, 0pt) (x-end, 0pt) let path-leftarrowhead x-start wid-arrowhead = start-path (x-start +' 2.5pt, wid-arrowhead) |> bezier-to (x-start +' 2.0pt, wid-arrowhead *' 0.5) (x-start +' 1.5pt, wid-arrowhead *' 0.167) (x-start, 0pt) |> bezier-to (x-start +' 1.5pt, 0pt -' wid-arrowhead *' 0.167) (x-start +' 2.0pt, 0pt -' wid-arrowhead *' 0.5) (x-start +' 2.5pt, 0pt -' wid-arrowhead) |> terminate-path - let path-rightarrowhead x-end wid-arrowhead = start-path (x-end -' 2.5pt, wid-arrowhead) |> bezier-to (x-end -' 2.0pt, wid-arrowhead *' 0.5) (x-end -' 1.5pt, wid-arrowhead *' 0.167) (x-end, 0pt) @@ -140,7 +140,6 @@ end = struct |> terminate-path let-math \overrightarrow m = - let embedf ctx = let fsize = get-font-size ctx in let margin = fsize *' 0.25 in @@ -149,13 +148,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y +' ht -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); ] in @@ -164,7 +160,6 @@ end = struct text-in-math MathOrd embedf let-math \overleftarrow m = - let embedf ctx = let fsize = get-font-size ctx in let margin = fsize *' 0.25 in @@ -173,13 +168,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y +' ht -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); ] in @@ -188,7 +180,6 @@ end = struct text-in-math MathOrd embedf let-math \overleftrightarrow m = - let embedf ctx = let fsize = get-font-size ctx in let margin = fsize *' 0.25 in @@ -197,13 +188,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y +' ht -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); ] @@ -221,13 +209,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); ] in @@ -244,13 +229,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); ] in @@ -267,13 +249,10 @@ end = struct let deco (x, y) wid ht dp = let text-color = get-text-color ctx in let ht-base = y -' wid-arrowhead in - let x-start = 0pt in let x-end = wid in - - let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in [ - stroke 0.5pt text-color (path-line |> shift-path (x, ht-base)); + stroke 0.5pt text-color (path-arrowline x-start x-end |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-leftarrowhead x-start wid-arrowhead |> shift-path (x, ht-base)); stroke 0.5pt text-color (path-rightarrowhead x-end wid-arrowhead |> shift-path (x, ht-base)); ] @@ -281,5 +260,4 @@ end = struct inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m) in text-in-math MathOrd embedf - end