Global setting of Latex font size

Dear community, it’s my first app with streamline, so maybe I’ve overseen something. Streamlit is a great tool, love it! I extensively make use of the Latex capabilities in markdowns and have > 1000 text snippets with Latex code in my strings. The thing is that the standard text size of normal text and Latex text size have some mismatch: the Latex character are too big. Here an example of the code: “Wie groß ist die Gate-Source-Spannung in der gezeichneten Schaltung? $U_{\textrm{B}} = 44 V$; $R_1 = 10 k\Omega$; $R_2 = 1 k\Omega$; $R_3 = 2,2 k\Omega$ …” and the output in markdown:


My question is: is there a chance to globally set the Latex font size so that normal text size and Latex are comparable? Thanks for any help!

I don’t think there is a global setting for that, but you could target the span.math-inline and div.math-display classes with CSS.

Code:
import streamlit as st

with st.sidebar:
    st.title(R"Change $\LaTeX$ font size")
    inline_size = st.slider("math-inline size (rem)", 0.1, 5.0, 1.0, 0.1)
    display_size = st.slider("math-display size (rem)", 0.1, 5.0, 1.0, 0.1)

    css = f"""
    span.math-inline {{
        font-size: {inline_size}rem;
    }}

    div.math-display {{
        font-size: {display_size}rem;
    }}
    """

    st.html(f"<style>{css}</style>")

st.header("Inline style math")
st.markdown(
    "These are some inline equations: "
    R"$U_{\textrm{B}} = 44 V$; $R_1 = 10 k\Omega$; $R_2 = 1 k\Omega$; $R_3 = 2.2 k\Omega$. "
    "This is just more text to follow."
)

st.header("Display style math")
st.write("Here is another equation:")
st.latex(
    R"""
    \begin{align*}
    U_{\textrm{B}} &= 44 V \\
    R_1 &= 10 k\Omega \\
    R_2 &= 1 k\Omega \\
    R_3 &= 2.2 k\Omega
    \end{align*}    
    """
)
1 Like

This works perfectly for me - thank you so much for your kind support!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.