Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add overarrow and underarrow #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
* `\widehat`
* `\overline`
* `\overrightarrow`
* `\overleftarrow`
* `\overleftrightarrow`
* `\underrightarrow`
* `\underleftarrow`
* `\underleftrightarrow`

## Matrices

Expand Down
126 changes: 116 additions & 10 deletions src/accent.satyh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -122,8 +127,39 @@ 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)
|> 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 =
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 in
[
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
inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m)
in
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
Expand All @@ -132,26 +168,96 @@ 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
[
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
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 x-end = wid in
[
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));
]
in
inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m)
in
text-in-math MathOrd embedf

let path-line = Gr.line (x-start, 0pt) (x-end, 0pt) in
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 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 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
[
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
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 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-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
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 in
[
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));
]
in
inline-frame-outer (0pt, 0pt, margin +' wid-arrowhead, 0pt) deco (embed-math ctx m)
in
text-in-math MathOrd embedf
end