react-native-math-view
                                
                                 react-native-math-view copied to clipboard
                                
                                    react-native-math-view copied to clipboard
                            
                            
                            
                        Formatting Issues (inlineMath and alignment within text)
Setting inline: false seems to add a margin in front of the formula. Alignment to flex-start does not work properly anymore. Do you have any idea how to fix it?
 
                                    
                                    
                                    
                                
Flew wrap perhaps. Look at the updated example
בתאריך יום ו׳, 8 בינו׳ 2021, 17:09, מאת zinnen [email protected]:
Setting inline: false seems to add a margin in front of the formula. Alignment to flex-start does not work properly anymore. Do you have any idea how to fix it?
[image: Bildschirmfoto 2021-01-08 um 16 04 27] https://user-images.githubusercontent.com/9108609/104030254-646ce080-51cb-11eb-91bb-21a3d6e513d0.png
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ShaMan123/react-native-math-view/issues/38, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIGAW4LGZ6WIVZN7K6ZXUQDSY4N3LANCNFSM4V2SDFDA .
I don't think it's related to wrapping. The formulas are too short for that. In the following example, the gap in front of the second formula changes when flex is set from 1 to 0. This should really only have an effect on the vertical expansion, or am I wrong? flexWrap has no effect.
 
                                    
                                    
                                    
                                
Could you add background color/borders for debugging?
 
                                    
                                    
                                    
                                
I don't know and don't really understand why to use flex: 0 or what it does.
Here is an example with FlatList, without flex: 0 (takes the size as it is). Also with a Flat-List with left-aligned content there is the gap before the 2nd formula.
 
                                    
                                    
                                    
                                
Why closing the issue if it still exists?
You should follow the examples. There's a Flatlist example.
This may be caused by the android shadow node, I can't say for sure.
However, I don't see a reason why not to use flex:1 if it fixes the issue.
Unfortunately, I can't offer any further help.
Thank you for the effort and the library. I close the issue, even if the simple example with FlatList does not run as it should. The reference to examples (the link contains a SectionLost and no FlatList) is not always helpful.
Dear Sir, the problem also occurs in the sample code. It is not related to my flex settings. If you call the MathView component with "config={inline: false}}" in "MathItem.tsx", high formulas (e.g. fraction, sum, product) above a certain length in the "MathSectionList.tsx" file are also displayed with the gap in front of the formula. Please close the issue if it is not relevant for you. In my opinion, displaying formulas with inline: false is necessary, since it conforms to the LaTeX standard and is supported by MathJax.
 
                                    
                                    
                                    
                                
I can't reproduce.
These gifs are with config={{ inline: false }}
 

Could it be the resolution of the smartphones? I tried three different ones in the emulator. It seems to work with small resolution, because then the elements are reduced in size. With larger ones it did not work for me. I have attached a screenshot with the three results as well as the settings in the emulator.
 
                                    
                                    
                                    
                                
This seems to be a deep problem. It might be caused by the resolution. If so this may be a problem with the android svg renderer. Look here I don't have the time to address the problem. You are welcome to PR.
There are problems with the Fallback component as well.
import Fallback from 'react-native-math-view/src/fallback
I don't have much time, but can do a little research for causes. My feeling is that for some formulas a smaller height is set than the actual one. This happens on both Android and IOS. If the actual height is larger, the SVG is reduced in size when displayed. This happens not left-aligned, but centered. This creates the gap on the left side. Are you just reading the height of the SVG directly in the code (based on MathJax), or is it calculated somewhere?
Sounds like a good direction.
I tested something using the Fallback renderer (react-native-svg) and came up with similar findings. I have noticed that when using react-native-svg the size doesn't match what mathjax outputs.
Gist
- If recall correctly, the android impl calculates it's size via the ShadowNode.
- The Fallback (which is used for iOS and can be used as opt-in) obtains it's size from Mathjax, see code.
Proposals
- Regarding android impl look at preserveAspectRatio and Alignment.
Maybe try passing different values and see how it behaves. It is exported to jshere. You can obtain it via the exported valueConstants, see this
- MathJax has very bad documentation - it's a guessing game to find a solution approaching core stuff.
Hope this helps.
It looks like this should be the default value preserveAspectRatio="xMinYMid meet"
try this 57d08c7
and make sure you don't override resizeMode. It should be set to contain
Is there a trick to get MathJax-generated SVG displayed with react-native-svg in the SvgXml element? I would play a bit with height, width, vertical-align, ..., but it does not show on the screen.
Here the svg code:
const xml = <svg style="vertical-align: -0.186ex" xmlns="http://www.w3.org/2000/svg" width="11.669ex" height="2.072ex" role="img" focusable="false" viewBox="0 -833.9 5157.7 915.9" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path id="MJX-1-TEX-I-1D44E" d="M33 157Q33 258 109 349T280 441Q331 441 370 392Q386 422 416 422Q429 422 439 414T449 394Q449 381 412 234T374 68Q374 43 381 35T402 26Q411 27 422 35Q443 55 463 131Q469 151 473 152Q475 153 483 153H487Q506 153 506 144Q506 138 501 117T481 63T449 13Q436 0 417 -8Q409 -10 393 -10Q359 -10 336 5T306 36L300 51Q299 52 296 50Q294 48 292 46Q233 -10 172 -10Q117 -10 75 30T33 157ZM351 328Q351 334 346 350T323 385T277 405Q242 405 210 374T160 293Q131 214 119 129Q119 126 119 118T118 106Q118 61 136 44T179 26Q217 26 254 59T298 110Q300 114 325 217T351 328Z"></path><path id="MJX-1-TEX-N-32" d="M109 429Q82 429 66 447T50 491Q50 562 103 614T235 666Q326 666 387 610T449 465Q449 422 429 383T381 315T301 241Q265 210 201 149L142 93L218 92Q375 92 385 97Q392 99 409 186V189H449V186Q448 183 436 95T421 3V0H50V19V31Q50 38 56 46T86 81Q115 113 136 137Q145 147 170 174T204 211T233 244T261 278T284 308T305 340T320 369T333 401T340 431T343 464Q343 527 309 573T212 619Q179 619 154 602T119 569T109 550Q109 549 114 549Q132 549 151 535T170 489Q170 464 154 447T109 429Z"></path><path id="MJX-1-TEX-N-2B" d="M56 237T56 250T70 270H369V420L370 570Q380 583 389 583Q402 583 409 568V270H707Q722 262 722 250T707 230H409V-68Q401 -82 391 -82H389H387Q375 -82 369 -68V230H70Q56 237 56 250Z"></path><path id="MJX-1-TEX-I-1D44F" d="M73 647Q73 657 77 670T89 683Q90 683 161 688T234 694Q246 694 246 685T212 542Q204 508 195 472T180 418L176 399Q176 396 182 402Q231 442 283 442Q345 442 383 396T422 280Q422 169 343 79T173 -11Q123 -11 82 27T40 150V159Q40 180 48 217T97 414Q147 611 147 623T109 637Q104 637 101 637H96Q86 637 83 637T76 640T73 647ZM336 325V331Q336 405 275 405Q258 405 240 397T207 376T181 352T163 330L157 322L136 236Q114 150 114 114Q114 66 138 42Q154 26 178 26Q211 26 245 58Q270 81 285 114T318 219Q336 291 336 325Z"></path><path id="MJX-1-TEX-N-3D" d="M56 347Q56 360 70 367H707Q722 359 722 347Q722 336 708 328L390 327H72Q56 332 56 347ZM56 153Q56 168 72 173H708Q722 163 722 153Q722 140 707 133H70Q56 140 56 153Z"></path><path id="MJX-1-TEX-I-1D450" d="M34 159Q34 268 120 355T306 442Q362 442 394 418T427 355Q427 326 408 306T360 285Q341 285 330 295T319 325T330 359T352 380T366 386H367Q367 388 361 392T340 400T306 404Q276 404 249 390Q228 381 206 359Q162 315 142 235T121 119Q121 73 147 50Q169 26 205 26H209Q321 26 394 111Q403 121 406 121Q410 121 419 112T429 98T420 83T391 55T346 25T282 0T202 -11Q127 -11 81 37T34 159Z"></path></defs><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><use xlink:href="#MJX-1-TEX-I-1D44E"></use></g><g data-mml-node="mn" transform="translate(529, 363) scale(0.707)"><use xlink:href="#MJX-1-TEX-N-32"></use></g></g><g data-mml-node="mo" transform="translate(1154.8, 0)"><use xlink:href="#MJX-1-TEX-N-2B"></use></g><g data-mml-node="msup" transform="translate(2155, 0)"><g data-mml-node="mi"><use xlink:href="#MJX-1-TEX-I-1D44F"></use></g><g data-mml-node="mn" transform="translate(429, 363) scale(0.707)"><use xlink:href="#MJX-1-TEX-N-32"></use></g></g><g data-mml-node="mo" transform="translate(3265.3, 0)"><use xlink:href="#MJX-1-TEX-N-3D"></use></g><g data-mml-node="msup" transform="translate(4321.1, 0)"><g data-mml-node="mi"><use xlink:href="#MJX-1-TEX-I-1D450"></use></g><g data-mml-node="mn" transform="translate(433, 363) scale(0.707)"><use xlink:href="#MJX-1-TEX-N-32"></use></g></g></g></g></svg> 
Running with SvgFromXml. Will try to play a bit in the next weeks though very busy.
You can use the fallback component, that does exactly that.
I wonder if we are making a fundamental mistake when rendering SVGs. When I display "= a^2 =", "= a =" and "= \sum_{i = 1}^{100} =" with alignItems set to flex-start, flex-end, center, these formulas are not rendered at the correct height. The = should be at the same height here. flex-end could fit if you could now consider vertical-align from the svg element. It's not clear to me how you could account for vertical displacement as given in the svg style element.
flex-start:
 center:
center:
 flex-end:
flex-end:

In this case I would try to use
alignItems: 'center',
justifyContent: 'flex-start'
I tried all combinations. Do you know if the vertical-align of the svg style element is automatically considered by react-native-svg?
https://github.com/react-native-svg/react-native-svg/commit/fe7e8b2b65badb78d3d69d4c689cf6a7092b0e27
https://github.com/react-native-svg/react-native-svg/issues/308
Maybe try opening an issue there
Thanks a lot. I will try to understand what is going on when rendering the SVG. The info to align it in a correct way should be in the svg element. Will keep you up to date
Von: ShaMan123 [email protected] Antworten an: ShaMan123/react-native-math-view [email protected] Datum: Montag, 18. Januar 2021 um 12:52 An: ShaMan123/react-native-math-view [email protected] Cc: Andreas Zinnen [email protected], State change [email protected] Betreff: Re: [ShaMan123/react-native-math-view] inline: true versus inline:false (#38)
Maybe try opening an issue there
— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHubhttps://github.com/ShaMan123/react-native-math-view/issues/38#issuecomment-762199834, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACFPZAJUSKJ4WMGEN6N7UC3S2QODNANCNFSM4V2SDFDA.
I can now display formulas very nicely side by side, taking into account the offset. Where do I configure the code so that the fallback is also used on Android?
It would be great if you could share your findings or PR!
I've exposed MathText in the fallback in v3.8.0 so make sure you've upgraded.
- import MathView, { MathText } from `react-native-math-view`;
+ import MathView, { MathText } from `react-native-math-view/src/fallback`;