ForNeVeR / xaml-math

A collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks
MIT License
647 stars 105 forks source link

Add control with inline math rendering capabilities #77

Open illiteratePhD opened 7 years ago

illiteratePhD commented 7 years ago

Current custom control would be cumbersome to use to produce paragraphs of text with inline math or longer flowing text with math as separate lines. See example below

http://marked2app.com/help/images/mathjax2.jpg

A control based on, e.g., a textbox, but with added handles such as [$, $] that uses the renderer would be a very useful addition.

EDIT

Did some research on this. Perhaps a using BlockUIContainer and InlineUIContainer inside a FlowDocument is a better way to go.

ForNeVeR commented 7 years ago

Yes, that's right. Today WPF-Math doesn't help much with formatting whole TeX documents within WPF forms or documents.

I believe that FlowDocument is the way to go, but I'd like someone (probably myself) to conduct more research on that, and maybe even implement some simple prototype. I still don't know what changes that'll require, and we need to ascertain that before doing anything.

alexreg commented 7 years ago

I think this would be beyond the scope of the project. It would be great if someone implements this, but I think it's a big project, and probably best we stay clear of it for now.

illiteratePhD commented 7 years ago

I've looked at the FlowDocument tag a bit and it turns out adding WPF-Math is really not that hard, if you can accept not being able to use the standard $...$ pattern. By changing the <border> section of the example with the following:

<Border Margin="10,0,10,10" BorderBrush="LightGray" BorderThickness="1" Grid.Row="3" Grid.Column="0">
    <FlowDocumentScrollViewer>
        <FlowDocument>
            <Paragraph>
                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce faucibus odio arcu, luctus vestibulum tortor congue in. Lorem ipsum dolor sit amet, consectetur,
                <InlineUIContainer BaselineAlignment="TextBottom">
                    <controls:FormulaControl x:Name="formula1" Formula="\sum d\theta = \tan^{-1}\theta+C" Scale="12" SnapsToDevicePixels="True"/>
                </InlineUIContainer>
                adipiscing elit. Fusce nec lacinia neque. Donec malesuada, ligula non vestibulum cursus, urna purus pellentesque orci, 
                aliquet accumsan dui velit ac justo. 
            </Paragraph>
            <BlockUIContainer>
                <controls:FormulaControl x:Name="formula" Formula="L = \int_a^b \sqrt[4]{ \left| \sum_{i,j=1}^ng_{ij}\left(\gamma(t)\right) \left[\frac{d}{dt}x^i\circ\gamma(t) \right] \left{\frac{d}{dt}x^j\circ\gamma(t) \right} \right|}dt" Scale="12" SnapsToDevicePixels="True"/>
            </BlockUIContainer>
            <Paragraph>
                Nulla vitae suscipit tellus. Nunc sit amet tortor fermentum, sollicitudin enim cursus, sagittis lacus. Pellentesque tincidunt massa nisl, nec tempor nulla 
                consequat a. Proin pharetra neque vel dolor congue, at condimentum arcu varius. Sed vel luctus enim. Curabitur eleifend dui et arcu faucibus, sit amet 
                vulputate libero suscipit. 
            </Paragraph>
        </FlowDocument>
    </FlowDocumentScrollViewer>
</Border>

You actually get something that looks decent. The problem with the inline container is that the baseline, of course, is off. So essentially, what's needed, is a way to switch between the normal and in-line rendering of the formula.

Loving this project. Wish there was a way I could contribute in a meaningful way. Trying to get into the code, but it's a slow process :)

alexreg commented 7 years ago

Okay, well maybe we could created a contrib repository and put your control there, if you get it working a bit more smoothly. :) It's been a long time since I did anything with flow documents, but that's good you've made some initial success.

illiteratePhD commented 7 years ago

On the topic of inline vs. display. How are these things handled by existing TeX parsers? Are there two character sets or is the existing character set adjusted to a different environment?

ForNeVeR commented 7 years ago

@alexreg I don't think we need to split our project into more fragments at the moment. If we can have a decent and non-intrusive solution to use WPF-Math in <FlowDocument> context, I'll vote to accept such contribution and include in into the main code base.

Side note: I'll be absent from March 23rd to 24th on a small scientific trip; I hope you'll be fine here guys 😄

alexreg commented 7 years ago

Hmm, well it's your decision @ForNeVeR, but I think it should at the least be in a separate VSproj, if not a separate repository.

B3zaleel commented 6 years ago

I think I managed to create a control that can render the formula control with normal text, but a lot of the features are still under development. I Would push it when it is quite decent.

ForNeVeR commented 6 years ago

I would very much ask you to please create a separate branch for that.

B3zaleel commented 6 years ago

I will