Commit Graph

43 Commits

Author SHA1 Message Date
Nicolas Guillot
ca0c3fbe07 Add break quality scoring
Implement aesthetic break point selection to prefer natural break locations
  (e.g., after operators) rather than arbitrary positions when line wrapping
  mathematical expressions.
2025-11-14 12:23:27 +01:00
Nicolas Guillot
4441528f46 Implement line breaking for scripted atoms and fix atom ordering 2025-11-14 10:45:51 +01:00
Nicolas Guillot
15269e87e5 Fix large operator positioning causing incorrect atom ordering
When rendering large operators (e.g., sum, integral) with scripts in text
  mode, the operator glyph was incorrectly positioned after its subscripts
  and superscripts instead of before them. This caused expressions like
  \sum_{i=1}^{n} i = \frac{n(n+1)}{2} to render with the equals sign
  appearing visually misplaced.

  Root cause:
  The line-breaking refactoring introduced double-positioning of large
  operators. makeLargeOp() internally sets the operator position, advances
  currentPosition.x, and adds script displays. However, the calling code
  then overwrote the position and advanced currentPosition.x again, causing:
  - Double-advancement leading to incorrect width calculations
  - Scripts positioned before the operator instead of after

  Solution:
  Save and restore typesetter state before/after line break dimension checks,
  then call makeLargeOp() once at the correct position after handling line
  breaks and inter-element spacing.
2025-11-14 10:32:10 +01:00
Nicolas Guillot
8cf87ef703 inline layout for all complex atom types
Extends the width-checking pattern from fractions/radicals to ALL remaining
  complex atom types, completing Priority 1 of the multiline implementation.

  Changes:
  - Large operators (∑, ∫, ∏): Now stay inline with height+width checking
    (breaks only if height > fontSize * 2.5 OR width exceeds constraint)
  - Delimiters (\left...\right): Stay inline with maxWidth propagation to
    inner content for proper nested wrapping
  - Colors (.color, .textcolor, .colorBox): All 3 types now stay inline with
    maxWidth propagation for proper nested wrapping
  - Matrices/tables: Small matrices can now stay inline with surrounding content
  - Width constraint propagation: All recursive createLineForMathList() calls
    now properly pass maxWidth parameter

Impact:
  Before: Complex atoms always forced line breaks, even when they fit
  After: ALL complex atoms intelligently stay inline when width permits

  Examples:
  - a + ∑ xᵢ + b → 1 line instead of 3
  - (a+b) + \left(\frac{c}{d}\right) + e → stays inline with wrapping
2025-11-14 09:53:14 +01:00
Nicolas Guillot
c5b737d9bb Line breaking for fractions and radicals fixes
Implement smart width-checking for complex mathematical displays to enable
  inline rendering when space permits, dramatically improving multiline layout.

  Changes:
  - Add shouldBreakBeforeDisplay() helper to check width before line breaks
  - Add performLineBreak() helper for clean line transitions
  - Modify fraction handling to stay inline when they fit within maxWidth
  - Modify radical handling to stay inline when they fit within maxWidth
  - Support radicals with degrees (cube roots, nth roots, etc.)
2025-11-13 15:45:35 +01:00
Nicolas Guillot
9f6f5a2934 [multiple lines] inter atoms line breaking support 2025-11-13 14:52:11 +01:00
mgriebling
48fcb899fc Merge pull request #54 from nguillot/dfrac_support
Add support for dfrac and tfrac LaTeX commands
2025-11-04 09:54:02 -05:00
Nicolas Guillot
d2df078dc9 Add support for dfrac and tfrac LaTeX commands
Add display-style (dfrac) and text-style (tfrac) fraction commands
  to SwiftMath's LaTeX parser. These commands force fractions to render
  in specific styles regardless of context.

  Implementation:
  - Add dfrac parsing to prepend displaystyle to numerator/denominator
  - Add tfrac parsing to prepend textstyle to numerator/denominator
  - Implement in both parser functions in MTMathListBuilder.swift

  Testing:
  - Add testDisplayStyleFraction() for dfrac validation
  - Add testTextStyleFraction() for tfrac validation
  - Add testDisplayAndTextStyleFractions() for complex expressions
  - All 180 tests pass on macOS and iOS simulator

  Documentation:
  - Update MISSING_FEATURES.md (7/12 features now implemented, 58%)
  - Update README.md feature list to include dfrac and tfrac

  Fixes issue where equations like y'=-\dfrac{2}{x^{3}} would fail to
  parse with "Invalid command dfrac" error. This was blocking the
  StepByStep feature preview rendering.
2025-11-03 10:24:40 +01:00
Nicolas Guillot
ca0e514505 [multi line display] Fix line wrapping to respect width constraints and prevent text truncation 2025-10-27 13:33:29 +01:00
Nicolas Guillot
c7198ad9af [UI] add line wrapping functionality 2025-10-02 16:42:31 +02:00
Nicolas Guillot
11f57f7c6e add a fallback font system to render CJK text in the \text command 2025-10-01 14:11:00 +02:00
Nicolas Guillot
b67cc8fd38 [Test] fix MathFontTests on mac 2025-10-01 10:36:11 +02:00
Nicolas Guillot
fe00c5a96e add iiiint LaTeX command support 2025-10-01 10:30:03 +02:00
Nicolas Guillot
7a40cd704a pmatrix/bmatrix/vmatrix LaTeX command support 2025-10-01 10:22:56 +02:00
Nicolas Guillot
80db8c66fb smallmatrix LaTeX command support 2025-10-01 10:09:56 +02:00
Nicolas Guillot
e9ab64d844 substack LaTeX command support 2025-10-01 10:04:06 +02:00
Nicolas Guillot
7bd6ef660b [Test] add skipped tests to show what can be implemented 2025-09-30 20:20:59 +02:00
Nicolas Guillot
fc7e96acf5 [Test] increase LaTeX command coverage 2025-09-30 19:40:26 +02:00
Nicolas Guillot
61ef8dc4f8 supports all standard LaTeX math delimiters for both inline and display modes 2025-09-30 19:17:56 +02:00
Daniel Resnick
a73bf8d3f1 Add layout info to MathImage
This makes it possible to align images generated by MathImage alongside text, in an AttributedString for example.
2025-05-16 18:36:32 -06:00
Daniel Resnick
f6f4ebfa89 Fix crashes due to forced unwrapping 2025-04-16 18:10:56 -06:00
Richard
1c3bf9129a Added support for visionOS by adding to #if os(iOS) || os(visionOS) 2025-03-27 11:19:51 +01:00
Michael Griebling
d0b1ff94df Added support for accented and special characters in the input text stream. (e.g., áéíóúýàèìòùâêîôûäëïöüÿãñõçøåæœß'ÁÉÍÓÚÝÀÈÌÒÙÂÊÎÔÛÄËÏÖÜÃÑÕÇØÅÆŒ)
Also added some new commands to support special characters like \aa (å), etc.
2024-12-17 10:21:27 -05:00
Michael Griebling
07b110d07f Update internal changes. 2024-12-15 12:21:08 -05:00
Peter Tang
25938db765 Add NSLock to protect lazily loaded tables in multithread concurrent setting 2024-10-26 22:20:25 +08:00
Michael Griebling
428537b8d9 Put back Color code in place of txetcolor due to crashes. 2024-10-05 11:29:31 -04:00
Michael Griebling
a87d4b5a3c Remove Chinese support again 2024-10-05 11:03:29 -04:00
Michael Griebling
2809379401 Removed Chinese support (messed with root). Fixed tests. 2024-10-05 10:45:03 -04:00
Peter Tang
1cf614036f Fix concurrency thread-safe exception 2023-09-26 13:07:49 +08:00
Peter Tang
2f962f98c3 Fix concurrency thread-safe exception 2023-09-26 13:00:12 +08:00
Peter Tang
045c2aab72 clean up unnecessary test script messages. 2023-09-18 20:13:34 +08:00
Peter Tang
c6ea427bfb clean up unnecessary test script messages. 2023-09-18 20:10:52 +08:00
Peter Tang
b637b18ace resource loading is serialised, font and mathtable dictionaries in BundleManager are threadsafe protected. 2023-09-18 19:04:06 +08:00
Peter Tang
6306ab7c4b threadsafe MathImage and MTMathImag concurrent testScripts. 2023-09-18 14:47:45 +08:00
Peter Tang
5de5ea677e threadsafe MathFont, MTFontV2, MTFontMathTableV2 with concurrent testScripts. 2023-09-18 13:30:31 +08:00
Peter Tang
40a6896889 corrected some variable names within BundleManager functions, added onDemandBundle registration instead of loading all Resources at startup. 2023-09-15 17:06:06 +08:00
Peter Tang
cea2188310 Sunset MathTable, created MTFontV2, MTFontMathTableV2 and MathImage, about to sunset MTMathImage 2023-09-15 09:53:54 +08:00
Peter Tang
6049e93c07 added test case around UIFont family names. 2023-09-12 18:22:32 +08:00
Peter Tang
490790c06f fixed UIFont and NSFont issue, their names are different from the otf file names 2023-09-12 18:10:05 +08:00
Peter Tang
018ce0cd08 MathFont and MathTable added, both do not rely on existing SwifthMath code. 2023-09-12 07:55:46 +08:00
André Douzette
a482791f57 Fix crash when sqrt has no radicand 2023-07-06 11:33:12 +02:00
Michael Griebling
f23a5b9fb5 Updated comments and minor fixes. 2023-01-20 10:54:45 -05:00
Michael Griebling
c129258845 Renamed the package. 2023-01-18 11:42:38 -05:00