Skip to content

Title: sqrt(custom_symbol) does not render properly as \sqrt{} but as \mathrm{sqrt} #232

@SpazzNon

Description

@SpazzNon

Hi Connor,

First of all, thank you for creating handcalcs — since I discovered it, I haven't stopped using it! I'm from Peru, and I'm planning to run a small workshop to introduce this amazing tool to people who are just starting with Python.

I'm currently facing an issue when using custom_symbols with the square root function.

Here's my setup:

handcalcs.set_option("custom_symbols", {
    "fcmag": "\\left( f'_{c} \\right)",
    "fymag": "f_y",
    "rhobal": "\\overline{ \\rho_b }",
    "fraccion": r"\frac{k_x \text{Holaj}x}{r_x} "
})

I use Pint for units:

f_prime_c = 210 * kgf/cm**2
fcmag = f_prime_c.magnitude  # This is a float

The issue occurs with the square root:

%%render
As_min_1 = max(0.80*sqrt(fcmag)/fymag*b*d_1, 14/fymag*b*d_1)

Expected LaTeX Output:

\sqrt{f'_{c}}

Actual Output (from %%tex):

\mathrm{sqrt} f'_{c}

This incorrect rendering only happens when using fcmag (a custom_symbol). If I use f_prime_c directly in the formula, it renders correctly as \sqrt{210}.

It seems the symbolic substitution breaks proper detection of sqrt() and falls back to rendering it as \mathrm{sqrt} instead of \sqrt{}.

Would love to hear your thoughts or guidance on how to patch this. I’ve been customizing the library, so I’d also be happy to contribute a fix or test one if you have suggestions.

Thanks again for your work!

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions