public void Start() { mathView = FindObjectOfType <MathView>(); for (int i = 0; i < inputSpots.Length; i++) { if (inputSpots[i] != null) { if (i == 0 || !restrictInputToInOrder) { inputSpots[i].AcceptingInput = true; } else { inputSpots[i].AcceptingInput = false; } } } //subscribe to all input template slot changed events MatrixInputTemplate[] inputTemplates = GameObject.FindObjectsOfType <MatrixInputTemplate>(); foreach (MatrixInputTemplate inputTemplate in inputTemplates) { inputTemplate.inputSlotChanged += new MatrixInputTemplate.InputSlotChangedHandler(TemplateInputChangedHandler); } renderManager = GameObject.FindObjectOfType <MatrixRenderManager>(); }
public EditorView() { // Basic functionality var view = new SKCanvasView { HeightRequest = 225 }; var keyboard = new MathKeyboard(Rendering.FrontEnd.PainterConstants.LargerFontSize); var viewModel = keyboard.Keyboard; viewModel.BindDisplay(view, new SkiaSharp.MathPainter { TextColor = SKColors.Black }, new SKColor(0, 0, 0, 153)); // Input from physical keyboard var entry = new Entry { Placeholder = "Enter keystrokes...", HorizontalOptions = LayoutOptions.FillAndExpand }; entry.TextChanged += (sender, e) => { entry.Text = ""; foreach (var c in e.NewTextValue) { // The (int) extra conversion seems to be required by Android or a crash occurs viewModel.KeyPress((Editor.MathKeyboardInput)(int) c); } }; // Evaluation var output = new MathView { FontSize = 32, EnableTouchEvents = true, EnablePanning = true }; keyboard.Keyboard.ReturnPressed += delegate { output.LaTeX = Evaluation.Interpret(keyboard.Keyboard.MathList); }; // Debug labels var latex = new Label { Text = "LaTeX = " }; var atomTypes = new Label { Text = "Atom Types = " }; var ranges = new Label { Text = "Ranges = " }; var index = new Label { Text = "Index = " }; viewModel.RedrawRequested += (sender, e) => Device.BeginInvokeOnMainThread(() => { latex.Text = "LaTeX = " + viewModel.LaTeX; atomTypes.Text = "Atom Types = " + string.Join (", ", viewModel.MathList.Select(x => x.GetType().Name)); ranges.Text = "Ranges = " + string.Join (", ", (viewModel.Display ?? throw new Structures.InvalidCodePathException("Invalid LaTeX")) .Displays.Select(x => x.Range)); index.Text = "Index = " + viewModel.InsertionIndex; });
private void OprostqvaneNaKorena1(double gorenkoren) { var view5 = new MathView(); view5.FontSize = 55; double inputNum = gorenkoren; //Check if it is a perfect square number if (!IsDecimal(Math.Sqrt(inputNum))) { lblOprastqvaneNaKornena.Text = "Опростяваме корена(В случея е точен):"; view5.LaTeX = @"\frac{S=" + Math.Sqrt(inputNum).ToString() + "}{" + DolenKoren(dolenkoren) + "}"; //mahame korena OprostenoLice.Children.Add(view5); return; } double testSquare = 0; for (int i = (int)Math.Floor(Math.Sqrt(inputNum)); i >= 2; i--) { testSquare = inputNum / (double)(i * i); if (!IsDecimal(testSquare)) { lblOprastqvaneNaKornena.Text = "Опростяваме корена:"; view5.LaTeX = @"S=" + @"\frac{" + i.ToString() + @"\sqrt{" + (inputNum / (i * i)).ToString() + "}" + "}{" + DolenKoren(dolenkoren) + "}"; OprostenoLice.Children.Add(view5); return; } } lblOprastqvaneNaKornena.Text = "Опростяваме корена (В случея няма нужда):"; view5.LaTeX = @"S=" + @"\frac{" + @"\sqrt{" + inputNum.ToString() + "}" + "}{" + DolenKoren(dolenkoren) + "}"; OprostenoLice.Children.Add(view5); }
private async void OptScale_Click(object sender, RoutedEventArgs e) { var ScaleItems = new ToggleMenuFlyoutItem[] { optScale100, optScale125, optScale133, optScale150, optScale200, optScale250, optScale300, optScale400 }; foreach (var item in ScaleItems) { if (item == sender) { item.IsChecked = true; var btnName = item.Name; CURRENT_SCALE = int.Parse(btnName.Substring("optScale".Length)); var ret = await MathView.InvokeScriptAsync("ChangeScale", new string[] { $"{CURRENT_SCALE}" }); } else { item.IsChecked = false; } } Settings.Set("MathScale", CURRENT_SCALE); }
private async Task <WriteableBitmap> GetMathCapture() { using (Windows.Storage.Streams.InMemoryRandomAccessStream rs = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { if (MathView.DefaultBackgroundColor.A == 0x00) { await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), Colors.White.ToCssRGBA() }); } await MathView.CapturePreviewToStreamAsync(rs); await rs.FlushAsync(); var wb = await rs.ToWriteableBitmap(); if (wb is WriteableBitmap) { wb = wb.Crop(2); } if (MathView.DefaultBackgroundColor.A == 0x00) { await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() }); } return(wb); } }
private async void OptColor_Click(object sender, RoutedEventArgs e) { var btn = sender as MenuFlyoutItem; var C_NAME = btn.Name.Substring(3); switch (C_NAME) { case "ResetColor": CURRENT_BGCOLOR = Color.FromArgb(0, 255, 255, 255); CURRENT_FGCOLOR = Colors.Black; // Color.FromArgb(255, 000, 000, 000); MathView.DefaultBackgroundColor = CURRENT_BGCOLOR; break; case "BgColor": CURRENT_BGCOLOR = await Utils.ShowColorDialog(CURRENT_BGCOLOR); MathView.DefaultBackgroundColor = CURRENT_BGCOLOR; break; case "FgColor": CURRENT_FGCOLOR = await Utils.ShowColorDialog(CURRENT_FGCOLOR); break; default: break; } var ret = await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() }); //await GetMathImage(true); }
private static async void InitMathView() { // MathView is really slow on first load, so arbitrarily initialise one in the background now. // After this, others load at acceptable speed. MathView initialiser = new MathView { LaTeX = @"\text{whatever}" }; }
private async Task <WriteableBitmap> GetMathImage(bool force = false) { if (CURRENT_IMAGE == null || force) { var scale = await MathView.InvokeScriptAsync("GetPageZoomRatio", null); var ratio = 1.0; double.TryParse(scale, out ratio); if (ratio <= 0.0) { ratio = 1.0; } //else ratio = Math.Ceiling(ratio); var wb = await MathView.ToWriteableBitmap(); if (wb is WriteableBitmap) { var space = 2; var tolerance = space * 2; var size = await MathView.InvokeScriptAsync("GetEquationRect", null); if (!string.IsNullOrEmpty(size)) { try { var sv = size.Split(','); var l = (int)Math.Floor(double.Parse(sv[0].Trim())); var t = (int)Math.Floor(double.Parse(sv[1].Trim())); var w = (int)Math.Ceiling(double.Parse(sv[2].Trim())); var h = (int)Math.Ceiling(double.Parse(sv[3].Trim())); l = (int)Math.Min(l * ratio, Math.Max(0, l - tolerance)); t = (int)Math.Min(t * ratio, Math.Max(0, t - tolerance)); w = (int)Math.Max(w + tolerance * 2, Math.Min(wb.PixelWidth, w * Math.Ceiling(ratio) + tolerance * 2)); h = (int)Math.Max(h + tolerance * 2, Math.Min(wb.PixelHeight, h * Math.Ceiling(ratio) + tolerance * 2)); wb = wb.Crop(l, t, w, h); } catch (Exception) { } } wb = wb.Crop(space); } CURRENT_IMAGE = wb; } return(CURRENT_IMAGE); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { var ret = await MathView.InvokeScriptAsync("ChangeColor", new string[] { CURRENT_FGCOLOR.ToCssRGBA(), CURRENT_BGCOLOR.ToCssRGBA() }); //var ret = await mathView.InvokeScriptAsync("LoadMathJax", null); //if (ret.Equals("OK", StringComparison.CurrentCultureIgnoreCase)) { //edSrc.IsEnabled = true; } } catch { } }
private async Task <Size> GetMathSize() { Size result = Size.Empty; var scale = await MathView.InvokeScriptAsync("GetPageZoomRatio", null); var ratio = 1.0; double.TryParse(scale, out ratio); if (ratio == 0.0) { ratio = 1; } else { ratio = Math.Max(0, ratio); } var space = 2; var tolerance = space * 2; var size = await MathView.InvokeScriptAsync("GetEquationRect", null); if (!string.IsNullOrEmpty(size)) { try { var sv = size.Split(','); var l = (int)Math.Floor(double.Parse(sv[0].Trim())); var t = (int)Math.Floor(double.Parse(sv[1].Trim())); var w = (int)Math.Ceiling(double.Parse(sv[2].Trim())); var h = (int)Math.Ceiling(double.Parse(sv[3].Trim())); l = Math.Max(0, l - tolerance); t = Math.Max(0, t - tolerance); w = Math.Max(w, (int)(w * ratio) + tolerance * 2); h = Math.Max(h, (int)(h * ratio) + tolerance * 2); result.Width = w; result.Height = h; } catch (Exception) { } } return(result); }
private async Task <bool> GeneratingMath() { bool result = false; var lines = edSrc.Text.Trim().Split(new char[] { '\n', '\r' }); StringBuilder sb = new StringBuilder(); foreach (var l in lines) { if (string.IsNullOrEmpty(l)) { continue; } var idx = l.Replace("\\%", "\\\\").IndexOf("%"); var line = idx >= 0 ? l.Substring(0, idx) : l; if (string.IsNullOrEmpty(line)) { continue; } //if (!line.EndsWith("\\\\")) line = $"{line} \\\\ "; line = await line.Decoder(TextCodecs.CODEC.HTML, Encoding.UTF8); sb.AppendLine(line); } var tex = string.Join(Environment.NewLine, sb); if (!string.IsNullOrEmpty(tex)) { try { ResetMathView(); var ret = await MathView.InvokeScriptAsync("ChangeEquation", new string[] { tex }); if (ret.Equals("OK", StringComparison.CurrentCultureIgnoreCase)) { result = true; } SetMathView(); CURRENT_FORMULAR = tex; } catch (Exception) { } } return(result); }
static MoreExamples() { var demoLabels = new Dictionary <byte, MathView>(); var labels = new Dictionary <byte, MathView>(); // Demo formulae // Quadratic formula demoLabels[0] = new MathView { LaTeX = @"x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[0].FontSize = 15; // This is first label so set the height from the top demoLabels[1] = new MathView { LaTeX = @"\color{#ff3399}{(a_1+a_2)^2}=a_1^2+2a_1a_2+a_2^2", HeightRequest = 75, FontSize = 22.5f }; demoLabels[2] = new MathView { LaTeX = @"\cos(\theta + \varphi) = \cos(\theta)\cos(\varphi) - \sin(\theta)\sin(\varphi)", HeightRequest = 75, FontSize = 22.5f }; demoLabels[3] = new MathView { LaTeX = @"\frac{1}{\left(\sqrt{\phi \sqrt{5}}-\phi\right) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1 +\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\cdots} } } }", HeightRequest = 150, FontSize = 22.5f }; demoLabels[4] = new MathView { LaTeX = @"\sigma = \sqrt{\frac{1}{N}\sum_{i=1}^N (x_i - \mu)^2}", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[5] = new MathView { LaTeX = @"\neg(P\land Q) \iff (\neg P)\lor(\neg Q)", HeightRequest = 75, FontSize = 22.5f }; demoLabels[6] = new MathView { LaTeX = @"\log_b(x) = \frac{\log_a(x)}{\log_a(b)}", HeightRequest = 75, FontSize = 22.5f }; demoLabels[7] = new MathView { LaTeX = @"\lim_{x\to\infty}\left(1 + \frac{k}{x}\right)^x = e^k", HeightRequest = 75, FontSize = 22.5f }; demoLabels[8] = new MathView { LaTeX = @"\int_{-\infty}^\infty \! e^{-x^2} dx = \sqrt{\pi}", HeightRequest = 75, FontSize = 22.5f }; demoLabels[9] = new MathView { LaTeX = @"\frac 1 n \sum_{i=1}^{n}x_i \geq \sqrt[n]{\prod_{i=1}^{n}x_i}", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[10] = new MathView { LaTeX = @"f^{(n)}(z_0) = \frac{n!}{2\pi i}\oint_\gamma\frac{f(z)}{(z-z_0)^{n+1}}\,dz", HeightRequest = 75, FontSize = 22.5f }; demoLabels[11] = new MathView { LaTeX = @"i\hbar\frac{\partial}{\partial t}\mathbf\Psi(\mathbf{x},t) = -\frac{\hbar}{2m}\nabla^2\mathbf\Psi(\mathbf{x},t) + V(\mathbf{x})\mathbf\Psi(\mathbf{x},t)", HeightRequest = 75, FontSize = 22.5f }; demoLabels[12] = new MathView { LaTeX = @"\left(\sum_{k=1}^n a_k b_k \right)^2 \le \left(\sum_{k=1}^n a_k^2\right)\left(\sum_{k=1}^n b_k^2\right)", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[13] = new MathView { LaTeX = @"{n \brace k} = \frac{1}{k!}\sum_{j=0}^k (-1)^{k-j}\binom{k}{j}(k-j)^n", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[14] = new MathView { LaTeX = @"f(x) = \int\limits_{-\infty}^\infty\!\hat f(\xi)\,e^{2 \pi i \xi x}\,\mathrm{d}\xi", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[15] = new MathView { LaTeX = @"\begin{gather} \dot{x} = \sigma(y-x) \\ \dot{y} = \rho x - y - xz \\ \dot{z} = -\beta z + xy \end{gather}", HeightRequest = 131.25, FontSize = 22.5f }; demoLabels[16] = new MathView { LaTeX = @"\vec \bf V_1 \times \vec \bf V_2 = \begin{vmatrix} \hat \imath &\hat \jmath &\hat k \\ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \end{vmatrix}", HeightRequest = 131.25, FontSize = 22.5f }; demoLabels[17] = new MathView { LaTeX = @"\begin{eqalign} \nabla \cdot \vec{\bf{E}} & = \frac {\rho} {\varepsilon_0} \\ \nabla \cdot \vec{\bf{B}} & = 0 \\ \nabla \times \vec{\bf{E}} &= - \frac{\partial\vec{\bf{B}}}{\partial t} \\ \nabla \times \vec{\bf{B}} & = \mu_0\vec{\bf{J}} + \mu_0\varepsilon_0 \frac{\partial\vec{\bf{E}}}{\partial t} \end{eqalign}", HeightRequest = 262.5, FontSize = 22.5f }; demoLabels[18] = new MathView { LaTeX = @"\begin{pmatrix} a & b\\ c & d \end{pmatrix} \begin{pmatrix} \alpha & \beta \\ \gamma & \delta \end{pmatrix} = \begin{pmatrix} a\alpha + b\gamma & a\beta + b \delta \\ c\alpha + d\gamma & c\beta + d \delta \end{pmatrix}", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[19] = new MathView { LaTeX = @"\frak Q(\lambda,\hat{\lambda}) = -\frac{1}{2} \mathbb P(O \mid \lambda ) \sum_s \sum_m \sum_t \gamma_m^{(s)} (t) +\\ \quad \left( \log(2 \pi ) + \log \left| \cal C_m^{(s)} \right| + \left( o_t - \hat{\mu}_m^{(s)} \right) ^T \cal C_m^{(s)-1} \right)", HeightRequest = 168.75, FontSize = 22.5f }; demoLabels[20] = new MathView { LaTeX = @"f(x) = \begin{cases} \frac{e^x}{2} & x \geq 0 \\ 1 & x < 0 \end{cases}", HeightRequest = 112.5, FontSize = 22.5f }; demoLabels[21] = new MathView { LaTeX = @"\color{#ff3333}{c}\color{#9933ff}{o}\color{#ff0080}{l}+\color{#99ff33}{\frac{\color{#ff99ff}{o}}{\color{#990099}{r}}}-\color{#33ffff}{\sqrt[\color{#3399ff}{e}]{\color{#3333ff}{d}}}", HeightRequest = 112.5, FontSize = 22.5f }; // Test formulae labels[0] = new MathView { LaTeX = @"3+2-5 = 0", HeightRequest = 75, FontSize = 22.5f }; labels[0].BackgroundColor = Color.FromHsla(0.15, 0.2, 1.0, 1.0); // Infix and prefix Operators labels[1] = new MathView { LaTeX = @"12+-3 > +14", HeightRequest = 75, FontSize = 22.5f }; labels[1].BackgroundColor = Color.FromHsla(0.15, 0.2, 1.0, 1.0); labels[1].TextAlignment = TextAlignment.Center; // Punct, parens labels[2] = new MathView { LaTeX = @"(-3-5=-8, -6-7=-13)", HeightRequest = 75, FontSize = 22.5f }; // Latex commands labels[3] = new MathView { LaTeX = @"5\times(-2 \div 1) = -10", HeightRequest = 75, FontSize = 22.5f }; labels[3].BackgroundColor = Color.FromHsla(0.15, 0.2, 1.0, 1.0); labels[3].TextAlignment = TextAlignment.Right; labels[4] = new MathView { LaTeX = @"-h - (5xy+2) = z", HeightRequest = 75, FontSize = 22.5f }; // Text mode fraction labels[5] = new MathView { LaTeX = @"\frac12x + \frac{3\div4}2y = 25", HeightRequest = 112.5, FontSize = 22.5f }; labels[5].LineStyle = LineStyle.Text; // Display mode fraction labels[6] = new MathView { LaTeX = @"\frac{x+\frac{12}{5}}{y}+\frac1z = \frac{xz+y+\frac{12}{5}z}{yz}", HeightRequest = 112.5, FontSize = 22.5f }; labels[6].BackgroundColor = Color.FromHsla(0.15, 0.2, 1.0, 1.0); // fraction in fraction in text mode labels[7] = new MathView { LaTeX = @"\frac{x+\frac{12}{5}}{y}+\frac1z = \frac{xz+y+\frac{12}{5}z}{yz}", HeightRequest = 112.5, FontSize = 22.5f }; labels[7].BackgroundColor = Color.FromHsla(0.15, 0.2, 1.0, 1.0); labels[7].LineStyle = LineStyle.Text; // Exponents and subscripts // Large font labels[8] = new MathView { LaTeX = @"\frac{x^{2+3y}}{x^{2+4y}} = x^y \times \frac{z_1^{y+1}}{z_1^{y+1}}", HeightRequest = 168.75, FontSize = 22.5f }; labels[8].FontSize = 30; labels[8].TextAlignment = TextAlignment.Center; // Small font labels[9] = new MathView { LaTeX = @"\frac{x^{2+3y}}{x^{2+4y}} = x^y \times \frac{z_1^{y+1}}{z_1^{y+1}}", HeightRequest = 56.25, FontSize = 22.5f }; labels[9].FontSize = 10; labels[9].TextAlignment = TextAlignment.Center; // Square root labels[10] = new MathView { LaTeX = @"5+\sqrt{2}+3", HeightRequest = 75, FontSize = 22.5f }; // Square root inside square roots and with fractions labels[11] = new MathView { LaTeX = @"\sqrt{\frac{\sqrt{\frac{1}{2}} + 3}{\sqrt5^x}}+\sqrt{3x}+x^{\sqrt2}", HeightRequest = 168.75, FontSize = 22.5f }; // General root labels[12] = new MathView { LaTeX = @"\sqrt[3]{24} + 3\sqrt{2}24", HeightRequest = 75, FontSize = 22.5f }; // Fractions and formulae in root labels[13] = new MathView { LaTeX = @"\sqrt[x+\frac{3}{4}]{\frac{2}{4}+1}", HeightRequest = 112.5, FontSize = 22.5f }; // Non-symbol operators with no limits labels[14] = new MathView { LaTeX = @"\sin^2(\theta)=\log_3^2(\pi)", HeightRequest = 112.5, FontSize = 22.5f }; // Non-symbol operators with limits labels[15] = new MathView { LaTeX = @"\lim_{x\to\infty}\frac{e^2}{1-x}=\limsup_{\sigma}5", HeightRequest = 112.5, FontSize = 22.5f }; // Symbol operators with limits labels[16] = new MathView { LaTeX = @"\sum_{n=1}^{\infty}\frac{1+n}{1-n}=\bigcup_{A\in\Im}C\cup B", HeightRequest = 112.5, FontSize = 22.5f }; // Symbol operators with limits text style labels[17] = new MathView { LaTeX = @"\sum_{n=1}^{\infty}\frac{1+n}{1-n}=\bigcup_{A\in\Im}C\cup B", HeightRequest = 112.5, FontSize = 22.5f }; labels[17].LineStyle = LineStyle.Text; // Non-symbol operators with limits text style labels[18] = new MathView { LaTeX = @"\lim_{x\to\infty}\frac{e^2}{1-x}=\limsup_{\sigma}5", HeightRequest = 112.5, FontSize = 22.5f }; labels[18].LineStyle = LineStyle.Text; // Symbol operators with no limits labels[19] = new MathView { LaTeX = @"\int_{0}^{\infty}e^x \,dx=\oint_0^{\Delta}5\Gamma", HeightRequest = 112.5, FontSize = 22.5f }; // Test italic correction for large ops labels[20] = new MathView { LaTeX = @"\int\int\int^{\infty}\int_0\int^{\infty}_0\int", HeightRequest = 112.5, FontSize = 22.5f }; // Test italic correction for superscript/subscript labels[21] = new MathView { LaTeX = @"U_3^2UY_3^2U_3Y^2f_1f^2ff", HeightRequest = 112.5, FontSize = 22.5f }; // Error labels[22] = new MathView { LaTeX = @"\notacommand", HeightRequest = 56.25, FontSize = 22.5f }; labels[23] = new MathView { LaTeX = @"\sqrt{1}", HeightRequest = 37.5, FontSize = 22.5f }; labels[24] = new MathView { LaTeX = @"\sqrt[|]{1}", HeightRequest = 37.5, FontSize = 22.5f }; labels[25] = new MathView { LaTeX = @"{n \choose k}", HeightRequest = 112.5, FontSize = 22.5f }; labels[26] = new MathView { LaTeX = @"{n \choose k}", HeightRequest = 56.25, FontSize = 22.5f }; labels[26].LineStyle = LineStyle.Text; labels[27] = new MathView { LaTeX = @"\left({n \atop k}\right)", HeightRequest = 75, FontSize = 22.5f }; labels[28] = new MathView { LaTeX = @"\left({n \atop k}\right)", HeightRequest = 56.25, FontSize = 22.5f }; labels[28].LineStyle = LineStyle.Text; labels[29] = new MathView { LaTeX = @"\underline{xyz}+\overline{abc}", HeightRequest = 56.25, FontSize = 22.5f }; labels[30] = new MathView { LaTeX = @"\underline{\frac12}+\overline{\frac34}", HeightRequest = 93.75, FontSize = 22.5f }; labels[31] = new MathView { LaTeX = @"\underline{x^\overline{y}_\overline{z}+5}", HeightRequest = 93.75, FontSize = 22.5f }; // spacing examples from the TeX book labels[32] = new MathView { LaTeX = @"\int\!\!\!\int_D dx\,dy", HeightRequest = 93.75, FontSize = 22.5f }; // no spacing labels[33] = new MathView { LaTeX = @"\int\int_D dxdy", HeightRequest = 93.75, FontSize = 22.5f }; labels[34] = new MathView { LaTeX = @"y\,dx-x\,dy", HeightRequest = 56.25, FontSize = 22.5f }; labels[35] = new MathView { LaTeX = @"y dx - x dy", HeightRequest = 56.25, FontSize = 22.5f }; // large spaces labels[36] = new MathView { LaTeX = @"hello\ from \quad the \qquad other\ side", HeightRequest = 56.25, FontSize = 22.5f }; // Accents labels[37] = new MathView { LaTeX = @"\vec x \; \hat y \; \breve {x^2} \; \tilde x \tilde x^2 x^2", HeightRequest = 56.25, FontSize = 22.5f }; labels[38] = new MathView { LaTeX = @"\hat{xyz} \; \widehat{xyz}\; \vec{2ab}", HeightRequest = 56.25, FontSize = 22.5f }; labels[39] = new MathView { LaTeX = @"\hat{\frac12} \; \hat{\sqrt 3}", HeightRequest = 93.75, FontSize = 22.5f }; // large roots labels[40] = new MathView { LaTeX = @"\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+\cdots}}}}}", HeightRequest = 150, FontSize = 22.5f }; labels[41] = new MathView { LaTeX = @"\begin{bmatrix} a & b\\ c & d \\ e & f \\ g & h \\ i & j \end{bmatrix}", HeightRequest = 225, FontSize = 22.5f }; labels[42] = new MathView { LaTeX = @"x{\scriptstyle y}z", HeightRequest = 56.25, FontSize = 22.5f }; labels[43] = new MathView { LaTeX = @"x \mathrm x \mathbf x \mathcal X \mathfrak x \mathsf x \bm x \mathtt x \mathit \Lambda \cal g", HeightRequest = 56.25, FontSize = 22.5f }; labels[44] = new MathView { LaTeX = @"\mathrm{using\ mathrm}", HeightRequest = 56.25, FontSize = 22.5f }; labels[45] = new MathView { LaTeX = @"\text{using text}", HeightRequest = 56.25, FontSize = 22.5f }; labels[46] = new MathView { LaTeX = @"\text{Mary has }\$500 + \$200.", HeightRequest = 56.25, FontSize = 22.5f }; Views = demoLabels.Concat(labels).Select(p => p.Value).ToList().AsReadOnly(); }
public async Task DoWork() { try { Expression PGcd1 = new Expression("lcm(" + BCPodZnamenatel.ToString() + "," + ACPodZnamenatel.ToString() + "," + ABPodZnamenatel.ToString() + ")"); double Pgcd = PGcd1.calculate(); var view = new MathView(); view.FontSize = 55; view.HorizontalOptions = view.VerticalOptions = LayoutOptions.FillAndExpand; view.LaTeX = @"P=a+b+c"; var view2 = new MathView(); var Preshenie1 = new MathView(); Preshenie1.FontSize = 55; if (ABPodZnamenatel == 1 && BCPodZnamenatel == 1 && ACPodZnamenatel == 1) { view2.LaTeX = @"P=\frac{" + ABNadZnamenatel.ToString() + "}" + "{" + ABPodZnamenatel.ToString() + "} + " + @"\frac{ " + BCNadZnamenatel.ToString() + "} " + "{ " + BCPodZnamenatel.ToString() + "} + " + @"\frac{ " + ACNadZnamenatel.ToString() + "} " + "{ " + ACPodZnamenatel.ToString() + "}=" + @"\frac{ " + (ABNadZnamenatel + BCNadZnamenatel + ACNadZnamenatel).ToString() + "} " + "{1}"; } else { view2.LaTeX = @"P=\frac{" + ABNadZnamenatel.ToString() + "}" + "{" + ABPodZnamenatel.ToString() + "} + " + @"\frac{ " + BCNadZnamenatel.ToString() + "} " + "{ " + BCPodZnamenatel.ToString() + "} + " + @"\frac{ " + ACNadZnamenatel.ToString() + "} " + "{ " + ACPodZnamenatel.ToString() + "}=" + @"\frac{" + (((Pgcd / ABPodZnamenatel) * ABNadZnamenatel) + ((Pgcd / ACPodZnamenatel) * ACNadZnamenatel) + ((Pgcd / BCPodZnamenatel) * BCNadZnamenatel)).ToString() + "}{" + Pgcd.ToString() + "}"; } view2.FontSize = 55; var view3 = new MathView(); view3.FontSize = 55; var view4 = new MathView(); view4.FontSize = 55; view3.LaTeX = @"S=\sqrt{p(p-a)(p-b)(p-c)}"; double p = (ABNadZnamenatel + BCNadZnamenatel + ACNadZnamenatel); if (ABPodZnamenatel == 1 && BCPodZnamenatel == 1 && ACPodZnamenatel == 1 && p % 2 == 0) { p = p / 2; view3.LaTeX = @"S=\sqrt{" + p.ToString() + "(" + p.ToString() + "-" + ABNadZnamenatel.ToString() + ")" + "(" + p.ToString() + "-" + BCNadZnamenatel.ToString() + ")" + "(" + p.ToString() + "-" + ACNadZnamenatel.ToString() + ")" + "}"; view4.LaTeX = @"S=\sqrt{" + p.ToString() + "(" + (p - ABNadZnamenatel).ToString() + ")" + "(" + (p - BCNadZnamenatel).ToString() + ")" + "(" + (p - ACNadZnamenatel).ToString() + ")" + "}=" + @"\sqrt{" + (p * (p - ABNadZnamenatel) * (p - ACNadZnamenatel) * (p - BCNadZnamenatel)).ToString() + "}"; double pready = (p * (p - ABNadZnamenatel) * (p - ACNadZnamenatel) * (p - BCNadZnamenatel)); OprostqvaneNaKorena(pready); } // else // { // view3.LaTeX = @"S=\sqrt{" + @"\frac{" + p.ToString() + "}{2}" + "(" + @"\frac{" + p.ToString() + "}{2}" + "-" + @"\frac{" + ABNadZnamenatel.ToString() + "}{" + ABPodZnamenatel.ToString() + "}" + ")" + "(" + @"\frac{" + p.ToString() + "}{2}" + "-" + @"\frac{" + BCNadZnamenatel.ToString() + "}{" + BCPodZnamenatel.ToString() + "}" + ")" + "(" + @"\frac{" + p.ToString() + "}{2}" + "-" + @"\frac{" + ACNadZnamenatel.ToString() + "}" + "{" + ACPodZnamenatel.ToString() + "}" + ")" + "}"; // double namiraneMe = p * (IzchislenienaZnamenatelSDveChisla1(NamiraneLCMSDveChisla(2, ABPodZnamenatel), ABPodZnamenatel, ABNadZnamenatel, 2, p)) * (IzchislenienaZnamenatelSDveChisla1(NamiraneLCMSDveChisla(2, BCPodZnamenatel), BCPodZnamenatel, BCNadZnamenatel, 2, p)) * (IzchislenienaZnamenatelSDveChisla1(NamiraneLCMSDveChisla(2, ACPodZnamenatel), ACPodZnamenatel, ACNadZnamenatel, 2, p)); // double gorenkoren = namiraneMe; // dolenkoren = NamiraneLCMSDveChisla(2, ABPodZnamenatel) * NamiraneLCMSDveChisla(2, BCPodZnamenatel) * NamiraneLCMSDveChisla(2, ACPodZnamenatel) * 2; // view4.LaTeX = @"S=\sqrt{" + @"\frac{" + p.ToString() + "}{2}" + "(" + (IzchislenienaZnamenatelSDveChisla(NamiraneLCMSDveChisla(2, ABPodZnamenatel), ABPodZnamenatel, ABNadZnamenatel, 2, p)).ToString() + ")" + "(" + (IzchislenienaZnamenatelSDveChisla(NamiraneLCMSDveChisla(2, BCPodZnamenatel), BCPodZnamenatel, BCNadZnamenatel, 2, p)).ToString() + ")" + "(" + (IzchislenienaZnamenatelSDveChisla(NamiraneLCMSDveChisla(2, ACPodZnamenatel), ACPodZnamenatel, ACNadZnamenatel, 2, p)).ToString() + ")" + "}=" + @"\sqrt{" + @"\frac{" + namiraneMe.ToString() + "}{" + NamiraneLCMSDveChisla(2, ABPodZnamenatel) * NamiraneLCMSDveChisla(2, BCPodZnamenatel) * NamiraneLCMSDveChisla(2, ACPodZnamenatel) * 2 + "}" + "}"; // OprostqvaneNaKorena1(gorenkoren); // } GridTomath.Children.Add(view); GridP2.Children.Add(view2); SReshenie.Children.Add(view3); Sreshenie2.Children.Add(view4); } catch (Exception ex) { await DisplayAlert("", "resh", "OK"); } }
public DerivationViewer(EquationItem equationItem, string backToName = "List") { InitializeComponent(); this.ViewerTitle.Text = equationItem.LabelText; this.BackButton.Text = $"Back to {backToName}"; MathView view = new MathView() { FontSize = equationItem.FontSize, HeightRequest = equationItem.HeightRequest }; view.LaTeX = $@"{equationItem.EquationLatex}"; this.ViewArea.Children.Add(view); BoxView boxView = new BoxView { HeightRequest = 1, BackgroundColor = Color.FromHex("#999"), Margin = new Thickness(0, 20, 0, 20) }; this.ViewArea.Children.Add(boxView); foreach (var s in equationItem.DerivationStepsLatex) { if (s.IsButton) { StackLayout infoArea = new StackLayout { Orientation = StackOrientation.Horizontal }; Label forTheAbove = new Label { Text = $"For the above: ", VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center, }; Label infoLabel = new Label { Text = $"See \"{s.ButtonNavigation}\"", VerticalOptions = LayoutOptions.Center, VerticalTextAlignment = TextAlignment.Center, }; Button infoButton = new Button { Text = "PEEK", Style = (Style)Application.Current.Resources["BlueButton"], VerticalOptions = LayoutOptions.Center, FontSize = 14, }; infoButton.Clicked += async(sender, args) => { var equationToShow = Equations.EquationsList.FirstOrDefault(x => x.LabelText == s.ButtonNavigation); if (equationToShow != null) { await this.Navigation.PushModalAsync(new DerivationViewer(equationToShow, equationItem.LabelText)); } }; infoArea.Children.Add(forTheAbove); infoArea.Children.Add(infoLabel); infoArea.Children.Add(infoButton); this.ViewArea.Children.Add(infoArea); } else { MathView newview = new MathView { FontSize = s.FontSize, HeightRequest = s.HeightRequest }; newview.LaTeX = $@"{s.Latex}"; this.ViewArea.Children.Add(newview); } } }