{"id":26499687,"url":"https://github.com/stefano-meschiari/latex2exp","last_synced_at":"2025-04-04T14:05:08.589Z","repository":{"id":33621418,"uuid":"37273663","full_name":"stefano-meschiari/latex2exp","owner":"stefano-meschiari","description":"Use LaTeX in R graphics.","archived":false,"fork":false,"pushed_at":"2024-08-16T17:51:46.000Z","size":13153,"stargazers_count":189,"open_issues_count":9,"forks_count":10,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-28T13:05:18.259Z","etag":null,"topics":["cran","ggplot2","latex","latex-formulas","plotmath-expressions","r"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefano-meschiari.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}},"created_at":"2015-06-11T16:48:49.000Z","updated_at":"2025-03-11T02:07:42.000Z","dependencies_parsed_at":"2023-01-15T01:41:31.782Z","dependency_job_id":null,"html_url":"https://github.com/stefano-meschiari/latex2exp","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Flatex2exp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Flatex2exp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Flatex2exp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefano-meschiari%2Flatex2exp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefano-meschiari","download_url":"https://codeload.github.com/stefano-meschiari/latex2exp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247186117,"owners_count":20898096,"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":["cran","ggplot2","latex","latex-formulas","plotmath-expressions","r"],"created_at":"2025-03-20T15:18:31.650Z","updated_at":"2025-04-04T14:05:08.573Z","avatar_url":"https://github.com/stefano-meschiari.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/stefano-meschiari/latex2exp/workflows/R-CMD-check/badge.svg)](https://github.com/stefano-meschiari/latex2exp/actions)\n\u003c!-- badges: end --\u003e\n\n# latex2exp \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"200px\"\u003e\n\n**latex2exp** is an R package that lets you use LaTeX in plots. It\nparses and converts LaTeX to R’s custom [plotmath\nexpressions](http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/plotmath.html).\nYou can read the full documentation on the [package’s\nwebsite](https://stefano-meschiari.github.io/latex2exp).\n\nExpressions returned by `latex2exp` can be used to create formatted text\nand mathematical formulas and symbols to be rendered as axis labels,\nannotations, legends, titles, etc. throughout R’s plotting system.\n\n## Installation\n\nInstall this package from CRAN:\n\n``` r\ninstall.packages('latex2exp')\n```\n\nYou can also install the development version from GitHub using\n[devtools](http://cran.r-project.org/web/packages/devtools/index.html):\n\n``` r\ndevtools::install_github('stefano-meschiari/latex2exp')\n```\n\n## Usage\n\nThe `TeX` function takes a LaTeX string, parses it, and returns the\nclosest [plotmath\nexpression](http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/plotmath.html)\nsuitable for use in graphics. The return value of `TeX()` can be used\nanywhere a plotmath expression is accepted, including plot labels,\nlegends, and text for both base graphics and ggplot2.\n\nHere’s a simple example:\n\n``` r\n# Use raw strings, no need to escape backslashes.\nTeX(r\"(\\textbf{Euler's identity} is $e^{i\\pi} + 1 = 0$.)\")\n```\n\nIn this example, `\\textbf{}` is used to mark a fragment of text as bold,\n`$` introduces inline math mode, `^{}` typesets its contents as\nsuperscript, and `\\pi` typesets the letter *π*.\n\nStarting with R 4.0, it is recommended to use the new raw string literal\nsyntax (see `?Quotes`). The syntax looks like `r\"(...)\"`, where `...`\ncan contain any character sequence, including `\\`.\n\nAnother option is to escape the backslash character (`\\`) for LaTeX\ncommands, such that the command will be written as `\\\\command` rather\nthan `\\command`. This will also work on versions of R older than 4.0:\n\n``` r\n# Equivalent to the previous code fragment.\n# Use regular strings, but escape the backslashes.\nTeX(\"\\\\textbf{Euler's identity} is $e^{i\\\\pi} + 1 = 0$.\")\n```\n\nYou can quickly preview what a translated LaTeX string would look like\nby using `plot`:\n\n``` r\nplot(TeX(r'(A $\\LaTeX$ formula: $\\frac{2hc^2}{\\lambda^5}\\frac{1}{e^{\\frac{hc}{\\lambda k_B T}} - 1}$)'), cex=2, main=\"\")\n```\n\n\u003cimg src=\"man/figures/README-plot-formula-1.png\" width=\"480\" /\u003e\n\nThe following example shows plotting in base graphics:\n\n``` r\nx \u003c- seq(0, 4, length.out=100)\nalpha \u003c- 1:5\n\nplot(x, xlim=c(0, 4), ylim=c(0, 10), \n     xlab='x', ylab=TeX(r'($\\alpha  x^\\alpha$, where $\\alpha \\in \\{1 \\ldots 5\\}$)'), \n     type='n', main=TeX(r'(Using $\\LaTeX$ for plotting in base graphics!)', bold=TRUE))\n\nfor (a in alpha) {\n  lines(x, a*x^a, col=a)\n}\n\nlegend('topleft', \n       legend=TeX(sprintf(r'($\\alpha = %d$)', alpha)), \n       lwd=1, \n       col=alpha)\n```\n\n\u003cimg src=\"man/figures/README-base-plot-1.png\" width=\"672\" /\u003e\n\nThis example shows plotting in [ggplot2](https://ggplot2.tidyverse.org):\n\n``` r\nx \u003c- seq(0, 4, length.out=100)\nalpha \u003c- 1:5\ndata \u003c- map_df(alpha, ~ tibble(v=.*x^., x=x, alpha=.))\n\np \u003c- ggplot(data, aes(x=x, y=v, color=as.factor(alpha))) +\n    geom_line() + \n    ylab(TeX(r'($\\alpha  x^\\alpha$, where $\\alpha \\in 1\\ldots 5$)')) +\n    ggtitle(TeX(r'(Using $\\LaTeX$ for plotting in ggplot2. I $\\heartsuit$ ggplot!)')) +\n    coord_cartesian(ylim=c(-1, 10)) +\n    guides(color=guide_legend(title=NULL)) +\n    scale_color_discrete(labels=lapply(sprintf(r'($\\alpha = %d$)', alpha), TeX)) \n    # Note that ggplot2 legend labels must be lists of expressions, not vectors of expressions\n\nprint(p)\n```\n\n\u003cimg src=\"man/figures/README-ggplot-1.png\" width=\"672\" /\u003e\n\nHere are a few examples of what you can do with **latex2exp**:\n\n``` r\nlatex2exp_examples(cex=0.9)\n```\n\n\u003cimg src=\"man/figures/README-examples-1.png\" width=\"672\" /\u003e\n\n## Supported LaTeX commands\n\n[Table of supported\nLaTeX](https://www.stefanom.io/latex2exp/articles/supported-commands.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-meschiari%2Flatex2exp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefano-meschiari%2Flatex2exp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefano-meschiari%2Flatex2exp/lists"}