-
Notifications
You must be signed in to change notification settings - Fork 67
Recognized common functions #83
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
Comments
This really hacky code works when consuming: let replace(chars:string, replacement:MathKeyboardInput) =
let rec nBefore (index:MathListIndex) n =
if n = 0 then index
else nBefore index.Previous (n-1)
let insertionIndex = keyboard.InsertionIndex
if keyboard.InsertionIndex.FinalIndex >= chars.Length
then
let found =
chars
|> Seq.mapi (fun i c -> (c,i))
|> Seq.forall (fun (c,i) ->
let indexToTest = nBefore insertionIndex (chars.Length - i)
let atom = keyboard.MathList.AtomAt(indexToTest)
atom.AtomType = MathAtomType.Variable && atom.StringValue = string c
)
if found then
for _ = 1 to chars.Length do
keyboard.KeyPress(MathKeyboardInput.Backspace)
keyboard.KeyPress(replacement)
static let replacements =
[ "ln", MathKeyboardInput.NaturalLogarithm
"log", MathKeyboardInput.Logarithm
//Need to change structure for "exp"
"sin", MathKeyboardInput.Sine
// Need to change structure for "sinh"
"cos", MathKeyboardInput.Cosine
"tan", MathKeyboardInput.Tangent
"sec", MathKeyboardInput.Secant
"csc", MathKeyboardInput.Cosecant
"cot", MathKeyboardInput.Cotangent
]
let sendKey(k:MathKeyboardInput) =
keyboard.KeyPress k
replacements |> List.iter replace I found it very hard to get a new index with the FinalIndex int replaced with an arbitrary one. Hence some of the hackiness. |
The equivalent system in MathQuill is more complicated. It includes all of CSharpMath/CSharpMath/Atom/LaTeXSettings.cs Lines 523 to 554 in abbd6ee
CSharpMath/CSharpMath/Atom/LaTeXSettings.cs Lines 168 to 178 in abbd6ee
As the cursor can traverse inside individual characters of |
In the editor, on encountering one of the character combinations:
the system should replace the sequence of characters with the formula (
\log,...
in TeX).The text was updated successfully, but these errors were encountered: