Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I scale the rendered equation to match the surrounding text? #23

Open
OskarPersson opened this issue Aug 29, 2023 · 3 comments
Open

Comments

@OskarPersson
Copy link

Changing the font size doesn't affect the rendered equation:

import SwiftUI
import LaTeXSwiftUI

@main
struct iOSApp: App {
    var body: some Scene {
        WindowGroup {
            LaTeX("Solve the following: $(9-2)^2\\cdot9^2$")
            LaTeX("Solve the following: $(9-2)^2\\cdot9^2$").font(.system(size: 8))
        }
    }
}

Simulator Screenshot - iPhone 14 Pro - 2023-08-29 at 20 50 10

@rrrpdx
Copy link

rrrpdx commented Dec 15, 2023

Did you have any luck with this? I was able to change the font size within latex by, for example, doing $\\Huge\\pi$ ... I tried $\\fontsize{30}{36}\\pi$, but that didnt' seem to work.

@colinc86
Copy link
Owner

colinc86 commented Mar 6, 2024

The view needs to be able to measure/calculate the current font's x-height to correctly size the characters inside of the rendered LaTeX SVG. To do that, the view must use the UIFont/NSFont classes and do its best to convert SwiftUI's Font structure into the correct UIFont instance. Right now the only way I know how to do that is by limiting the functionality to SwiftUI's static largeTitle, title, title1, headline, etc fonts.

Long story short - if you use the statically declared fonts and not the .system(...) font initializers, then the rendered equation text should match.

I'm going to leave this issue open though because I think it's still worth investigating to come up with a better solution.

@m-yeroshenko
Copy link

Hi everyone!
Are there any updates on this matter?

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

No branches or pull requests

4 participants