### Install simpletex package Source: https://github.com/chuxinyuan/simpletex/blob/master/README.md Install the package from CRAN or the development version from GitHub. ```r # Install development version from GitHub remotes::install_github("chuxinyuan/simpletex") # Install from CRAN install.packages("simpletex") ``` -------------------------------- ### API Configuration Source: https://context7.com/chuxinyuan/simpletex/llms.txt Configure SimpleTex API credentials by setting environment variables for authentication. This should be done once. ```APIDOC ## API Configuration Configure SimpleTex API credentials by setting environment variables for authentication. ```r # Add SimpleTex API credentials to your .Renviron file # Run this code once to configure your credentials permanently cat( '\n# ID and SECRET of SimpleTex', 'SIMPLETEX_APP_ID = "your_app_id_here"', 'SIMPLETEX_APP_SECRET = "your_app_secret_here"', file = '~/.Renviron', sep = '\n', append = TRUE ) # Restart R session for changes to take effect # Or reload environment variables manually: readRenviron("~/.Renviron") # Verify credentials are set Sys.getenv("SIMPLETEX_APP_ID") # [1] "your_app_id_here" ``` ``` -------------------------------- ### Configure SimpleTex API Credentials Source: https://context7.com/chuxinyuan/simpletex/llms.txt Sets the required SIMPLETEX_APP_ID and SIMPLETEX_APP_SECRET environment variables in the .Renviron file for persistent authentication. ```r # Add SimpleTex API credentials to your .Renviron file # Run this code once to configure your credentials permanently cat( '\n# ID and SECRET of SimpleTex', 'SIMPLETEX_APP_ID = "your_app_id_here"', 'SIMPLETEX_APP_SECRET = "your_app_secret_here"', file = '~/.Renviron', sep = '\n', append = TRUE ) # Restart R session for changes to take effect # Or reload environment variables manually: readRenviron("~/.Renviron") # Verify credentials are set Sys.getenv("SIMPLETEX_APP_ID") # [1] "your_app_id_here" ``` -------------------------------- ### Select Recognition Modes Source: https://context7.com/chuxinyuan/simpletex/llms.txt Illustrates the three available service modes: latex_ocr for high accuracy, latex_ocr_turbo for speed, and simpletex_ocr for general text. ```r library(simpletex) # latex_ocr (default) - High accuracy mathematical formula recognition # Best for complex equations, academic papers, research documents # Slower but more accurate complex_formula <- imgocr("complex_equation.png", mode = "latex_ocr") # Returns: "\\frac{\\partial^2 u}{\\partial t^2} = c^2 \\nabla^2 u" # latex_ocr_turbo - Fast mathematical formula recognition # Good for simple formulas, batch processing, real-time applications # Faster but slightly less accurate simple_formula <- imgocr("simple_equation.png", mode = "latex_ocr_turbo") # Returns: "a^2 + b^2 = c^2" # simpletex_ocr - General image text recognition # Use for documents, mixed content, non-mathematical text # Returns plain text instead of LaTeX document_text <- imgocr("scanned_page.jpg", mode = "simpletex_ocr") # Returns: "Chapter 1: Introduction to Calculus" ``` -------------------------------- ### Perform OCR with imgocr Source: https://context7.com/chuxinyuan/simpletex/llms.txt Demonstrates basic usage of the imgocr function for formula and text recognition, including batch processing and error handling. ```r library(simpletex) # Basic usage - recognize mathematical formula with default high-accuracy mode result <- imgocr("equation.png") # Returns: "E = mc^2" # Use in Markdown/LaTeX by wrapping with dollar signs formula <- imgocr("integral.jpg") markdown_formula <- paste0("$", formula, "$") # Returns: "$\\int_{0}^{\\infty} e^{-x^2} dx = \\frac{\\sqrt{\\pi}}{2}$" # Fast formula recognition for quicker processing result <- imgocr("formula.png", mode = "latex_ocr_turbo") # Returns: "\\sum_{i=1}^{n} x_i" # General text recognition for non-formula content text <- imgocr("document.bmp", mode = "simpletex_ocr") # Returns: "The quick brown fox jumps over the lazy dog" # Process multiple images images <- c("eq1.png", "eq2.png", "eq3.png") formulas <- sapply(images, imgocr) # Returns vector of recognized formulas # Error handling for missing credentials tryCatch({ result <- imgocr("test.jpg") }, error = function(e) { if (grepl("Configure ID and SECRET", e$message)) { message("Please set SIMPLETEX_APP_ID and SIMPLETEX_APP_SECRET environment variables") } }) ``` -------------------------------- ### Recognition Modes Source: https://context7.com/chuxinyuan/simpletex/llms.txt Three service modes are available for different recognition tasks, each optimized for specific use cases. ```APIDOC ## Recognition Modes Three service modes are available for different recognition tasks, each optimized for specific use cases. ### `latex_ocr` (Default) - **Description**: High accuracy mathematical formula recognition. - **Use Case**: Best for complex equations, academic papers, research documents. - **Performance**: Slower but more accurate. - **Example**: ```r complex_formula <- imgocr("complex_equation.png", mode = "latex_ocr") # Returns: "\\frac{\\partial^2 u}{\\partial t^2} = c^2 \\nabla^2 u" ``` ### `latex_ocr_turbo` - **Description**: Fast mathematical formula recognition. - **Use Case**: Good for simple formulas, batch processing, real-time applications. - **Performance**: Faster but slightly less accurate. - **Example**: ```r simple_formula <- imgocr("simple_equation.png", mode = "latex_ocr_turbo") # Returns: "a^2 + b^2 = c^2" ``` ### `simpletex_ocr` - **Description**: General image text recognition. - **Use Case**: Use for documents, mixed content, non-mathematical text. - **Output**: Returns plain text instead of LaTeX. - **Example**: ```r document_text <- imgocr("scanned_page.jpg", mode = "simpletex_ocr") # Returns: "Chapter 1: Introduction to Calculus" ``` ``` -------------------------------- ### Perform OCR on an image Source: https://github.com/chuxinyuan/simpletex/blob/master/README.md Use the imgocr function to recognize text or formulas from an image file. ```r imgocr(img = "path/to/image", mode = "latex_ocr") ``` -------------------------------- ### imgocr Function Source: https://context7.com/chuxinyuan/simpletex/llms.txt The primary function for performing OCR on images containing mathematical formulas or text. It sends the image to the SimpleTex API and returns the recognized content as LaTeX or plain text. ```APIDOC ## imgocr Function The primary function for performing OCR on images containing mathematical formulas or text. It sends the image to the SimpleTex API and returns the recognized content as LaTeX or plain text. ### Method POST (Implicitly, as it sends data to an API) ### Endpoint (Not explicitly defined, but assumed to be the SimpleTex API endpoint) ### Parameters #### Query Parameters - **mode** (string) - Optional - Specifies the recognition mode. Options include `"latex_ocr"` (default, high accuracy formula), `"latex_ocr_turbo"` (fast formula), and `"simpletex_ocr"` (general text). #### Request Body (Implicitly, the image file is sent as part of the request) ### Request Example ```r library(simpletex) # Basic usage - recognize mathematical formula with default high-accuracy mode result <- imgocr("equation.png") # Returns: "E = mc^2" # Use in Markdown/LaTeX by wrapping with dollar signs formula <- imgocr("integral.jpg") markdown_formula <- paste0("$", formula, "$") # Returns: "$\int_{0}^{\infty} e^{-x^2} dx = \frac{\sqrt{\pi}}{2}$" # Fast formula recognition for quicker processing result <- imgocr("formula.png", mode = "latex_ocr_turbo") # Returns: "\\sum_{i=1}^{n} x_i" # General text recognition for non-formula content text <- imgocr("document.bmp", mode = "simpletex_ocr") # Returns: "The quick brown fox jumps over the lazy dog" # Process multiple images images <- c("eq1.png", "eq2.png", "eq3.png") formulas <- sapply(images, imgocr) # Returns vector of recognized formulas # Error handling for missing credentials tryCatch({ result <- imgocr("test.jpg") }, error = function(e) { if (grepl("Configure ID and SECRET", e$message)) { message("Please set SIMPLETEX_APP_ID and SIMPLETEX_APP_SECRET environment variables") } }) ``` ### Response #### Success Response (200) - **string** (string) - The recognized content, typically in LaTeX format for formulas or plain text for general OCR. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.