Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add LaTeX support in ft.Markdown#6069

Merged
FeodorFitsner merged 5 commits intoflet-dev:mainfrom
7576457:feat/latex
Jan 29, 2026
Merged

feat: add LaTeX support in ft.Markdown#6069
FeodorFitsner merged 5 commits intoflet-dev:mainfrom
7576457:feat/latex

Conversation

@7576457
Copy link
Contributor

@7576457 7576457 commented Jan 25, 2026

Description

The flutter_markdown package is officially deprecated and has been replaced by flutter_markdown_plus. In this PR, I updated the old package and also added flutter_markdown_plus_latex.

For the ft.Markdown component, two new attributes are now available:

Test Code

import flet as ft

markdown = """
# Flet Markdown & LaTeX Demo

**Markdown rendering** _with_ selectable text and **LaTeX math formulas**.

- [Flet website](https://docs.flet.dev)
- https://github.com/flet-dev/flet

## Styling

Style text as _italic_, __bold__, ~~strikethrough~~, or `inline code`.

- Use bulleted lists
- To better clarify
- Your points

## Math

Inline formula:
$E = mc^2$

Block formula:
$$
P + \\frac{1}{2} \\rho v^2 + \\rho g h = \\text{constant}
$$

$$
\\int_0^1 x^2 , dx = \\frac{1}{3}
$$

"""


def main(page: ft.Page):
    page.scroll = ft.ScrollMode.AUTO
    page.add(
        ft.Markdown(
            value=markdown,
            selectable=True,
            extension_set=ft.MarkdownExtensionSet.GITHUB_WEB,
            code_theme=ft.MarkdownCodeTheme.ATOM_ONE_DARK,
            latex_style=ft.TextStyle(color="purple"),
            latex_scale_factor=1.2,
        )
    )


ft.run(main)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I signed the CLA.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing tests pass locally with my changes
  • I have made corresponding changes to the documentation (if applicable)

Screenshots

image

Summary by Sourcery

Add LaTeX rendering support to the Markdown control and migrate to the new markdown packages.

New Features:

  • Enable LaTeX formulas rendering in the Markdown control with configurable text style and scale factor exposed as Markdown properties.

Enhancements:

  • Replace the deprecated flutter_markdown dependency with flutter_markdown_plus and integrate its LaTeX extension for markdown processing.

@FeodorFitsner
Copy link
Contributor

Great PR! Replacing deprecated package and LaTeX support is a great plus.

@yunguangli
Copy link

yunguangli commented Jan 26, 2026

Awesome, I have been waiting for LaTex support. An can this LaTex mark down can be integrated with Canvas Text too? It would be great for making educational apps.

@7576457
Copy link
Contributor Author

7576457 commented Jan 26, 2026

Awesome, I have been waiting for LaTex support. An can this LaTex mark down can be integrated with Canvas Text too? It would be great for making educational apps.

You can use ft.Markdown as a component:

math_text = r"$P + \frac{1}{2} \rho v^2 + \rho g h = \text{constant}$"
canvas = cv.Canvas(
    expand=False,
    shapes=[
        cv.Fill(ft.Paint(color=ft.Colors.YELLOW)),
    ],
    content=ft.Column(
        controls=[
            ft.Markdown(math_text),
        ]
    )
)

@7576457 7576457 marked this pull request as ready for review January 26, 2026 08:58
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@FeodorFitsner
Copy link
Contributor

@7576457 would you like to add an integration test for Markdown with LaTeX here: sdk/python/packages/flet/integration_tests/controls/material/test_markdown.py?

There is readme on how to run/make-golden-images integration tests: sdk/python/packages/flet/integration_tests/README.md

@7576457
Copy link
Contributor Author

7576457 commented Jan 26, 2026

yes, sure!

@FeodorFitsner
Copy link
Contributor

Oh, I haven't realized if you are not on macOS you won't be able to generate "golden" image. We are running integration tests on macOS for now.

OK, you write a test and do a golden image for your platform and I'll upload updated one once PR is merged.

@7576457
Copy link
Contributor Author

7576457 commented Jan 26, 2026

I added the test. Please let me know if something is missing.

I also had trouble running the tests because flet couldn't find flutter. Until I made this change:

(.venv) PS C:\Users\Jesuh\dev\flet\sdk\python> git diff packages/flet/src/flet/testing/flet_test_app.py
diff --git a/sdk/python/packages/flet/src/flet/testing/flet_test_app.py b/sdk/python/packages/flet/src/flet/testing/flet_test_app.py
index 16c6b921..3b41b8e4 100644
--- a/sdk/python/packages/flet/src/flet/testing/flet_test_app.py
+++ b/sdk/python/packages/flet/src/flet/testing/flet_test_app.py
@@ -223,7 +223,7 @@ class FletTestApp:
             stdout = None
             stderr = None
-        flutter_args = ["fvm", "flutter", "test", "integration_test"]
+        flutter_args = ["fvm", "flutter.bat", "test", "integration_test"]
         if self.__disable_fvm:
             flutter_args.pop(0)
(.venv) PS C:\Users\Jesuh\dev\flet\sdk\python> 

@ndonkoHenri ndonkoHenri linked an issue Jan 27, 2026 that may be closed by this pull request
@FeodorFitsner
Copy link
Contributor

In the terminal do you run fvm like fvm flutter.bat as well?

Updated several Flutter dependencies in pubspec.lock, including file_picker, path_provider_foundation, and others. Removed path_provider_foundation from macOS plugin registrant. Added a new golden image for markdown integration tests on macOS.
@7576457
Copy link
Contributor Author

7576457 commented Jan 28, 2026

I didn’t actually try to use FVM. I was just trying to create a golden test and run a test to verify it.

Here’s what I did for that (having pre-set flutter.bat as in the diff):

$env:FLET_TEST_GOLDEN = "1"
$env:FLET_TEST_DISABLE_FVM = "True"
uv run pytest .\packages\flet\integration_tests\controls\material\test_markdown.py

Then I simply ran the test to check that it worked:

$env:FLET_TEST_GOLDEN = "0"
uv run pytest .\packages\flet\integration_tests\controls\material\test_markdown.py

Everything worked fine in this case

@FeodorFitsner
Copy link
Contributor

Right, I see. Can you install fvm tool and check if .bat is also required or it should be run as fvm flutter?

@FeodorFitsner
Copy link
Contributor

You need fvm anyway as Flutter is progressing fast and we keep it fresh in .fvmrc in the root of repo.

@FeodorFitsner FeodorFitsner merged commit 61c523d into flet-dev:main Jan 29, 2026
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rendering of mathematical expressions (Latex, Mathjax)

3 participants