Skip to content

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

Open
charlesroddie opened this issue Nov 4, 2019 · 3 comments
Open

Recognized common functions #83

charlesroddie opened this issue Nov 4, 2019 · 3 comments
Labels
Aspect/Editor This is related to CSharpMath.Editor. Status/1. Blocked Requires another issue or pull request to be completed before being ready. Type/Enhancement

Comments

@charlesroddie
Copy link
Collaborator

In the editor, on encountering one of the character combinations:

log, ln, exp
sin, cos, tan
sinh, cosh, tanh
sec, csc, cosec, cot

the system should replace the sequence of characters with the formula (\log,... in TeX).

@charlesroddie charlesroddie added Type/Enhancement Aspect/Editor This is related to CSharpMath.Editor. labels Nov 4, 2019
@charlesroddie
Copy link
Collaborator Author

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.

@Happypig375
Copy link
Collaborator

The equivalent system in MathQuill is more complicated. It includes all of

{ "arccos", new LargeOperator("arccos", false, true) },
{ "arcsin", new LargeOperator("arcsin", false, true) },
{ "arctan", new LargeOperator("arctan", false, true) },
{ "arg", new LargeOperator("arg", false, true) },
{ "cos", new LargeOperator("cos", false, true) },
{ "cosh", new LargeOperator("cosh", false, true) },
{ "cot", new LargeOperator("cot", false, true) },
{ "coth", new LargeOperator("coth", false, true) },
{ "csc", new LargeOperator("csc", false, true) },
{ "deg", new LargeOperator("deg", false, true) },
{ "det", new LargeOperator("det", null) },
{ "dim", new LargeOperator("dim", false, true) },
{ "exp", new LargeOperator("exp", false, true) },
{ "gcd", new LargeOperator("gcd", null) },
{ "hom", new LargeOperator("hom", false, true) },
{ "inf", new LargeOperator("inf", null) },
{ "ker", new LargeOperator("ker", false, true) },
{ "lg", new LargeOperator("lg", false, true) },
{ "lim", new LargeOperator("lim", null) },
{ "liminf", new LargeOperator("lim inf", null) },
{ "limsup", new LargeOperator("lim sup", null) },
{ "ln", new LargeOperator("ln", false, true) },
{ "log", new LargeOperator("log", false, true) },
{ "max", new LargeOperator("max", null) },
{ "min", new LargeOperator("min", null) },
{ "Pr", new LargeOperator("Pr", null) },
{ "sec", new LargeOperator("sec", false, true) },
{ "sin", new LargeOperator("sin", false, true) },
{ "sinh", new LargeOperator("sinh", false, true) },
{ "sup", new LargeOperator("sup", null) },
{ "tan", new LargeOperator("tan", false, true) },
{ "tanh", new LargeOperator("tanh", false, true) },

{ "arsinh", new LargeOperator("arsinh", false, true) },
{ "arcosh", new LargeOperator("arcosh", false, true) },
{ "artanh", new LargeOperator("artanh", false, true) },
{ "arccot", new LargeOperator("arccot", false, true) },
{ "arcoth", new LargeOperator("arcoth", false, true) },
{ "arcsec", new LargeOperator("arcsec", false, true) },
{ "sech", new LargeOperator("sech", false, true) },
{ "arsech", new LargeOperator("arsech", false, true) },
{ "arccsc", new LargeOperator("arccsc", false, true) },
{ "csch", new LargeOperator("csch", false, true) },
{ "arcsch", new LargeOperator("arcsch", false, true) },

As the cursor can traverse inside individual characters of LargeOperators freely, you can e.g. insert c between si and n and break up \sin (one LargeOperator) into sicn (four Variables) and delete the c in sicn to convert back. You can also type arc before \sin to make an \arcsin, type h after \sin to make a \sinh, and delete that character to convert back.

@Happypig375 Happypig375 added the Status/1. Ready This issue has been confirmed and is ready to be worked on. label Jun 1, 2020
@Happypig375
Copy link
Collaborator

Blocked on #117 and #124

@Happypig375 Happypig375 added Status/1. Blocked Requires another issue or pull request to be completed before being ready. and removed Status/1. Ready This issue has been confirmed and is ready to be worked on. labels Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aspect/Editor This is related to CSharpMath.Editor. Status/1. Blocked Requires another issue or pull request to be completed before being ready. Type/Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants