Browse Source

Add demo about LaTeX formulas in `ui.markdown` (#3860)

As @motorst1 noticed in
https://github.com/zauberzeug/nicegui/discussions/696#discussioncomment-10909097,
`ui.markdown` can display LaTeX formulas. This PR adds a demo with notes
about required packages.

Open tasks:

- [x] add latex2mathml to release.dockerfile? (and somewhere else?)
- [x] raise markdown2 requirement to version >=2.5? --> No, we leave it
as it is.

---------

Co-authored-by: Rodja Trappe <rodja@zauberzeug.com>
Falko Schindler 7 months ago
parent
commit
a82cdb7de5

+ 1 - 0
.devcontainer/Dockerfile

@@ -29,6 +29,7 @@ ENV CHROME_BINARY_LOCATION=/usr/bin/chromium
 RUN pip install -U pip && pip install poetry==$POETRY_VERSION
 COPY pyproject.toml poetry.lock README.md ./
 RUN poetry install --all-extras --no-root
+RUN pip install latex2mathml
 
 USER $USERNAME
 

+ 2 - 0
development.dockerfile

@@ -13,4 +13,6 @@ WORKDIR /app
 COPY . .
 RUN poetry install --all-extras
 
+RUN pip install latex2mathml
+
 CMD python3 -m debugpy --listen 5678 main.py

+ 2 - 0
fly.dockerfile

@@ -29,6 +29,8 @@ COPY pyproject.toml poetry.lock*  ./
 
 RUN poetry install --no-root --extras "plotly matplotlib highcharts sass"
 
+RUN pip install latex2mathml
+
 ADD . .
 
 # ensure unique version to not serve cached and hence potentially wrong static files

+ 1 - 0
release.dockerfile

@@ -26,6 +26,7 @@ RUN python -m pip install \
     itsdangerous \
     pytest \
     requests \
+    latex2mathml \
     selenium
 
 WORKDIR /app

+ 12 - 0
website/documentation/content/markdown_documentation.py

@@ -55,6 +55,18 @@ def markdown_tables():
     ''', extras=['tables'])
 
 
+@doc.demo('LaTeX formulas', '''
+    By activating the "latex" extra, you can use LaTeX formulas.
+    This requires markdown2 version >=2.5 as well as latex2mathml to be installed.
+''')
+def markdown_latex():
+    ui.markdown(r'''
+        Euler's identity:
+
+        $$e^{i\pi} = -1$$
+    ''', extras=['latex'])
+
+
 @doc.demo('Change Markdown content', '''
     You can change the content of a Markdown element by setting its `content` property or calling `set_content`.
 ''')