Display LaTeX using SwiftUI & LaTeX DSL

Related tags

Utility swift latex
Overview

Swift LaTeX

LaTeX_project_logo_bird Medium

Display LaTeX using MathJax. The package also provides a custom LaTeX DSL, which enables you write LaTeX the way you write SwiftUI Views.

LaTeX with SwiftUI

A View called LaTeXView is avaiable to display formulas in LaTeX.

import LaTeX
import SwiftUI

struct ContentView: View {
    
    var body: some View {
        LaTeXView(formula: "\\pi")
    }
    
}

example


As a javascript package was used to render LaTeX, the Outgoing network Connections needs to be enabled in Project Sandbox.

LaTeX DSL

This part was designed with the goal of writing LaTeX the way you write SwiftUI.

$$ \sum_{x = 1}^{10} {{{\color{3a81f6} x}}^2} $$

let formula = LaTeXBuilder.build {
    Sum("x", from: 1, to: 10) { x in
        x
            .colored(.blue)
            .squared()
    }
}

Note that the Components are translated to LaTeX only when .latexExpression is called.

print(formula)
// RangedLargeOperator<...>(...)

print(formula.latexExpression)
// \sum_{x = 1}^{10} {{{\color{3a81f6} x}}^2}

print(formula.evaluated())
// numeric(385.0)

$$ {{\nabla\times{\overrightarrow{\mathbf{B}}}}-{{\color{3a81f6} \frac{1}{C}}} \frac{\delta \overrightarrow{\mathbf{E}}}{\delta t}}={4 \pi \rho} $$

Equals {
    Subtraction {
        Multiplication {
            nabla
        } by: {
            "B".font(.mathbf).overRightArrowed()
        }
    } by: {
        Fraction(1, "C")
            .colored(.blue)
    }
    
    Fraction {
        delta
        "E".font(.mathbf).overRightArrowed()
    } denominator: {
        delta
        "t"
    }
} with: {
    4
    pi
    rho
}

$$ \int_{-N}^N {e^x \, \mathrm{d}x} $$

Integral("x", from: "-N", to: "N") { variable in
    Power {
        "e"
    } with: {
        variable
    }
}

$$ {R_\theta}={\begin{bmatrix}\cos\theta & -\sin\theta \\ \sin\theta & \cos\theta\end{bmatrix}} $$

Equals {
    Subscript {
        "R"
    } with: {
        theta
    }
} with: {
    LaTeXMatrix {
        [
            [cos(theta), -sin(theta)],
            [sin(theta),  cos(theta)]
        ]
    }
}

Using Swift LaTeX

If you are working on a Swift Package, use

// inside Package.swift
dependencies: [
    .package(url: "https://github.com/Vaida12345/Swift-LaTeX.git")
],

Otherwise, use the project link to find this package in Xcode.

Credits

You might also like...
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.
A simple Pokedex app written in Swift that implements the PokeAPI, using Combine and data driven UI.

SwiftPokedex SwiftPokedex is a simple Pokedex app written by Viktor Gidlöf in Swift that implements the PokeAPI. For full documentation and implementa

ResponderChain is a library that passes events using the responder chain.

ResponderChain ResponderChain is a library that passes events using the responder chain.

Swift code to programmatically execute local or hosted JXA payloads without using the on-disk osascript binary

Swift code to programmatically execute local or hosted JXA payloads without using the on-disk osascript binary. This is helpful when you have Terminal access to a macOS host and want to launch a JXA .js payload without using on-disk osascript commands.

Merges a given number of PDF files into one file using the PDFKit framework

Titanium iOS PDF Merge Merges a given number of PDF files into one file using the PDFKit framework Requirements iOS 11+ Titanium SDK 9+ API's Methods

AnimeListSwiftUI - Anime quote list built with MVVM Swift 5 using Async/Await

How To In SwiftUI Async/Await AnimeListSwiftUI - Anime quote list built with MVVM Swift 5 using Async/Await Clones Clubhouse - App clone built with Sw

This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to load remote images

iOS NOW ⭐ This is a app developed in Swift, using Object Oriented Programing, UIKit user interface programmatically, API Request and Kingfisher to loa

Using UI Table View With Swift
Using UI Table View With Swift

News-App - Apple 관련 기사를 보여주는 News app을 만들 것입니다. - 자세한 과정은 리드미에 있습니다. Table View와 Table view controller Table View : Table의 크기를 지정할 수 있다. Table View Co

Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Verify New Zealand COVID Passes in iOS apps using Swift

NzCovidPass-Swift Swift library for verification of the NZ Covid Vaccination Pas

Owner
Vaida
Vaida
A DSL for Data Manipulation

Underscore.m About Underscore.m Underscore.m is a small utility library to facilitate working with common data structures in Objective-C. It tries to

Robb Böhnke 1.5k Oct 4, 2022
The simplest way to display the librarie's licences used in your application.

Features • Usage • Translation • Customisation • Installation • License Display a screen with all licences used in your application can be painful to

Florian Gabach 51 Feb 28, 2022
Mac app to change .ipa file app icons and display names

IPAEdit Mac app to change .ipa file app icon, display name, and app version to avoid updates Compatible with macOS 10.11+ Install To install either cl

Ethan Goodhart 23 Dec 28, 2022
Headline News Widget for Pock.You can display the articles fetched by rss.

Headline News Widget for Pock This is a headline news widget plugin for Pock You can display the articles fetched by rss. Demo In the demo video, the

null 11 Aug 30, 2022
Software Dummy Display Adapter for Apple Silicon Macs to Have Custom HiDPI Resolutions.

BetterDummy Dummy Display for Apple Silicon Macs to achieve custom resolutions. About M1 macs tend to have issues with custom resolutions. Notoriously

Istvan T. 8k Jan 9, 2023
Project shows how to unit test asynchronous API calls in Swift using Mocking without using any 3rd party software

UnitTestingNetworkCalls-Swift Project shows how to unit test asynchronous API ca

Gary M 0 May 6, 2022
Unit-Converter-SwiftUI - A simple Unit Converter iOS app built in the process of learning SwiftUI

SwiftUI-Unit-Converter A simple Unit Converter iOS app built in the process of l

Ishaan Bedi 2 Jul 13, 2022
Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm

Differific is a diffing tool that helps you compare Hashable objects using the Paul Heckel's diffing algorithm. Creating a chan

Christoffer Winterkvist 127 Jun 3, 2022
Plugin and runtime library for using protobuf with Swift

Swift Protobuf Welcome to Swift Protobuf! Apple's Swift programming language is a perfect complement to Google's Protocol Buffer ("protobuf") serializ

Apple 4.1k Dec 28, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022