{"id":23904775,"url":"https://github.com/mathpix/ios-client","last_synced_at":"2025-04-11T02:40:50.204Z","repository":{"id":62447624,"uuid":"101238367","full_name":"Mathpix/ios-client","owner":"Mathpix","description":"iOS Mathpix API client, installable via cocoapods.","archived":false,"fork":false,"pushed_at":"2023-09-28T07:21:29.000Z","size":1555,"stargazers_count":17,"open_issues_count":1,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-08T17:22:50.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mathpix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-08-24T00:58:36.000Z","updated_at":"2024-12-30T15:27:46.000Z","dependencies_parsed_at":"2024-01-18T04:06:52.009Z","dependency_job_id":"09841174-5b28-49f4-8c5f-96d029798ca1","html_url":"https://github.com/Mathpix/ios-client","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathpix%2Fios-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathpix%2Fios-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathpix%2Fios-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mathpix%2Fios-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mathpix","download_url":"https://codeload.github.com/Mathpix/ios-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248330991,"owners_count":21085815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-05T00:47:04.980Z","updated_at":"2025-04-11T02:40:50.164Z","avatar_url":"https://github.com/Mathpix.png","language":"Objective-C","readme":"# MathpixClient\n\n[![Language](https://img.shields.io/badge/swift-5.0-orange.svg)](https://developer.apple.com/swift)\n\nMathpixClient is a simple wrapper to get and recognize images by mathpix server https://mathpix.com.\n\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n\n\n## Installation\n\n#### CocoaPods\n\nMathpixClient is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"MathpixClient\"\n```\n\nand run \n\n```\npod install\n```\n\n\n## Usage\n\n#### Set api keys:\n\n```swift\nimport MathpixClient\n\nMathpixClient.setApiKeys(appId: \"demo_app\", appKey: \"demo_key\")\n```\n\nYou can request an API key for free from https://dashboard.mathpix.com.\n\n#### Launch camera:\n\nThe easiest way to use Mathpix on iOS is to launch our camera controller which can be done in a single line of code!\n\n```swift\nMathpixClient.launchCamera(source: self,\n                           outputFormats: [FormatLatex.simplified],\n                           backButtonCallback: {\n                                print(\"back button pressed\") },\n                           completion: { (error, result) in\n                                print(\"complete\") })\n```\n\n#### Recognize images:\n\nIf you want to use a custom camera controller, you can still use the MathpixClient to recognize images:\n\n```swift\nMathpixClient.recognize(image: UIImage(named: \"equation\")!, outputFormats: [FormatLatex.simplified]) { (error, result) in\n    print(result ?? error)\n}\n```\n\n#### Launch camera with custom UI/UX properties:\n\nYou can fine tune the camera controller we provide using the `MathCaptureProperties` instance:\n\n```swift\nlet properties = MathCaptureProperties(captureType: .gesture,\n                                               requiredButtons: [.flash, .back],\n                                               cropColor: UIColor.green,\n                                               errorHandling: true)\n        \nMathpixClient.launchCamera(source: self,\n                           outputFormats: [FormatLatex.simplified],\n                           withProperties: properties,\n                           backButtonCallback: {\n                                print(\"back button pressed\") },\n                           completion: { (error, result) in\n                                print(\"complete\") })\n\n```\n\n#### Subclass `MathCaptureViewController`\n\nIf you need more control, you can subclass `MathCaptureViewController`.\n\n```swift\nclass CustomCameraViewController: MathCaptureViewController {\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        // Add your UI elements here\n        \n    }\n}\n```\n\n## API\n\nWe now describe how to pass options to the Mathpix API via the iOS Mathpix SDK.  For more information regarding these options, please refer to the API documentation at: https://docs.mathpix.com/\n\n### MathpixFormat\n\nProtocol represents additional field \"formats\" in request body. Requested as parameter `outputFormats` array. You can set several values:\n\n#### FormatLatex\n\nThe latex field, if present, is one of “raw” (result is the unmodified OCR output), “defaultValue” (result is OCR output with extraneous spaces removed), or “simplified” (result has spaces removed, operator shortcuts, and is split into lists where appropriate):\n\n```swift\npublic enum FormatLatex {\n    case raw, defaultValue, simplified\n}\n```\n\n#### FormatMathml\nThe mathml field, if present and set to on, indicates the server should add a mathml field to the JSON result that is a string containing the MathML markup for the recognized math. In the case of an incompatible result, the server will instead add a mathml_error:\n\n```swift\npublic enum FormatMathml {\n    case on\n}\n```\n\n#### FormatWolfram\n\nThe wolfram field, if present and set to on, indicates the server should add a wolfram field to the JSON result that is a string compatible with the Wolfram Alpha engine. In the case of an incompatible result, the server will instead add a wolfram_error field:\n\n```swift\npublic enum FormatWolfram {\n    case on\n}\n```\n\n\n\n\n### MathCaptureProperties\n\nThe struct to incapsulate `MathCaptureViewController` properties. You can customize some UI/UX values:\n\nThe color of crop overlay bounds\n```swift\nlet cropColor: UIColor\n```\n\nThe icon of shutter button\n```swift\nlet shutterIcon : UIImage?\n```\n\nThe icon of flash button\n```swift\nlet flashIcon : UIImage?\n```\n\nThe icon of back button\n```swift\nlet backIcon : UIImage?\n```\n\nThe icon of cancel request button\n```swift\nlet cancelIcon : UIImage?\n```\n\nThe type of `RecognitionAnimator`. Used to provide animation for recognition process\n```swift\nlet animatorType : RecognitionAnimator.Type\n```\n\nThe type of UI capture action\n```swift\nlet captureType: CaptureType\n\npublic enum CaptureType {\n    /// Tap gesture is used to capture image.\n    case gesture\n    /// Shutter button is used to capture image.\n    case button\n}\n```\n\nThe buttons which will be presented in instantiated `MathCaptureViewController`\n```swift\nlet requiredButtons: [MathCaptureButton]\n\n public enum MathCaptureButton {\n    /// Back button\n    case back\n    /// Flash button\n    case flash\n}\n```\n\nThe size of `shutter` button\n```swift\nlet bigButtonSize: CGSize\n```\n\nThe size of buttons\n```swift\nlet smallButtonSize: CGSize\n```\n\nThe crop area insets\n```swift\nlet cropAreaInsets: UIEdgeInsets\n```\n\nIf enabled then errors will be handled by capture controller\n```swift\nlet errorHandling: Bool\n```\n\n### MathCaptureViewController\n\nYou can subclass it to get more control. See example app.\n\n## Error handling\n\nFor simple internal error handling add `errorHandling: true` parameter to **MathCaptureProperties**.\nErrors that you can get in callbacks represents by two main types:\n\n#### NetworkError\n\nError type will be thrown if network failed\n\n```swift\npublic enum NetworkError: Error {\n\n    /// Unknown or not supported error.\n    case unknown\n    \n    /// Not connected to the internet.\n    case notConnectedToInternet\n    \n    /// International data roaming turned off.\n    case internationalRoamingOff\n    \n    /// Cannot reach the server.\n    case notReachedServer\n    \n    /// Connection is lost.\n    case connectionLost\n    \n    /// Incorrect data returned from the server.\n    case incorrectDataReturned\n    \n    /// Request canceled.\n    case requestCanceled\n}\n\n```\n\n#### RecognitionError\n\nError type will be thrown if recognition failed\n\n```swift\npublic enum RecognitionError: Error {\n\n    /// Failed parse JSON, incorrect data returned\n    case failedParseJSON\n    \n    /// Server can't recognize image as math\n    case notMath(description: String)\n    \n    /// Invalid credentials, set correct api keys\n    case invalidCredentials\n}\n\n```\n\n### Example Error Handling:\n\n```swift\nMathpixClient.launchCamera(source: self,\n                           outputFormats: [FormatLatex.simplified],\n                           completion:\n                                { (error, result) in\n                                    if let error = error as? NetworkError {\n                                        handleNetworkError(error)\n                                    } else if let error = error as? RecognitionError {\n                                        handleRecognitionError(error)\n                                    } else if let error = error {\n                                        handleOtherError(error)\n                                    }\n                                    ...\n})\n```\n\n## Localization\n\nTo set labels or error messages add `Localizable.strings` file to your project if you haven't it. Then change values:\n\n```\n// Errors\n\"Error credintials title\" = \"Error\";\n\"Error credintials messages\" = \"Invalid credentials\";\n\"Error capture title\" = \"Error capture\";\n\"Error capture message\" = \"Capture image error\";\n\"Error timeout title\" = \"Timeout error\";\n\"Error timeout message\" = \"Send image timeout\";\n\"Error no connection tittle\" = \"Network error\";\n\"Error no connection message\" = \"No internet connection\";\n\"Error parse title\" = \"Error parse\";\n\"Error parse message\" = \"Error parse json\";\n\n// Tap info label\n\"Tap info label text\" = \"Tap anywhere to take a picture\";\n```\n\n\n## License\n\nMathpixClient is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathpix%2Fios-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathpix%2Fios-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathpix%2Fios-client/lists"}