<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/convert-hand-drawn-equations-to-latex-with-the-mathpix-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2017/09/convert-hand-drawn-equations-to-latex-with-the-mathpix-package.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Statistics involves a lot of mathematics, so one of the nice things about report-generation systems for R like <a rel="nofollow" href="http://rmarkdown.rstudio.com/" target="_blank">Rmarkdown</a> is that it makes it easy to include nicely-formatted equations by using the <a rel="nofollow" href="https://en.wikibooks.org/wiki/LaTeX/Mathematics" target="_blank">LaTeX syntax</a>.  So, if we want to include the density function of the Guassian Normal distribution: </p>
<p>$$ \frac{1}{{\sigma \sqrt {2\pi } }}  e^ { – \frac{ – \left( {x – \mu } \right)^2 }{2\sigma ^2} } $$</p>
<p>we can just add the following markup to the document:</p>
<pre>\[
\frac{1}{{\sigma \sqrt {2\pi} }} e^{-\frac{-(x-\mu)^2}{2\sigma ^2}}
\]
</pre>
<p>Creating that markup can be a little tricky, but it generally follows naturally from the mathematics, and it's much easier than other methods like including a screenshot of the equation. Still, a new R package makes it even easier: the <a rel="nofollow" href="http://mran.microsoft.com/package/mathpix/" target="_blank">mathpix package</a> will convert an image containing an equation to its LaTeX markup equivalent. That image might be a photo of a handwritten equation on paper of a whiteboard, or even a &quot;stattoo&quot;:</p>
<blockquote data-lang="en" class="twitter-tweet" data-conversation="none">
<p dir="ltr" lang="en">Mostly! Only \propto that didn't get recognized. Curious about results from <a rel="nofollow" href="https://twitter.com/kopshtik?ref_src=twsrc%5Etfw" target="_blank">@kopshtik</a> &amp; <a rel="nofollow" href="https://twitter.com/emhrt_?ref_src=twsrc%5Etfw" target="_blank">@emhrt_</a> <a rel="nofollow" href="https://t.co/1aoXq1je7h" target="_blank">pic.twitter.com/1aoXq1je7h</a></p>
<p>— Mikhail Popov (@bearloga) <a rel="nofollow" href="https://twitter.com/bearloga/status/913148595062194176?ref_src=twsrc%5Etfw" target="_blank">September 27, 2017</a></p></blockquote>
<p><br>
</p>
<p>The resulting LaTeX isn't quite perfect: it mistakes the proportionality symbol for the Greek letter alpha (a mistake I've seen a few typesetters make). With that correction, the rendered equation — used for Bayesian inference — looks like:</p>
<p> $$ p ( \theta | y) \propto p (y | \theta) p (\theta) $$  </p>
<p>The mathpix package was created by Jonathan Carroll and is an interface to the <a rel="nofollow" href="https://docs.mathpix.com/" target="_blank">Mathpix API</a>. (It's recommended you sign up for a free API key if you intend to use this package regularly.) The package is available now on CRAN, and you can find more details on its Github page, linked below.</p>
<p>Github (jonocarroll): mathpix : <a rel="nofollow" href="https://github.com/jonocarroll/mathpix" target="_blank">Query the mathpix API to convert math images to LaTeX</a></p>
</div>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2017/09/convert-hand-drawn-equations-to-latex-with-the-mathpix-package.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/ZiLut8jBpu0" height="1"></a></div>