📜 ⬆️ ⬇️

Plugin for WordPress. Making LaTex image formulas using the Google API

After I read the article on Habré " Formula editor appeared in Google Docs ", I decided to write a plug-in for my WordPress blog that will display images instead of LaTex formulas. To do this, I use the undocumented Google API feature.


The plugin is easy to use, but it has a big minus. As I understood from the comments on the article, this Google API function is not documented. So you need to use the plugin carefully. Tomorrow it may stop working if Google wants it. But this is tomorrow :)

The plugin will work only in WordPress older than version 2.5. As far as I remember in versions younger there is no add_shortcode
')
After activating the plugin, it is ready to use, there are no settings. Formula in LaTex format should be surrounded by tags [latexg] [/ latexg]

For example, writing such a post in a post [latexg]\frac{1}{\sigma\sqrt{2\pi}}\exp\left(-\frac{(x-\mu)^2}{2\sigma^2}\right)[/latexg]

You will get this picture:


The plug-in code is ugly simple, but I don’t know how to complicate it:

  1. <? php
  2. / *
  3. Plugin Name: FormulaMath
  4. Plugin URI: http: //*****.ru
  5. Description: Converts LaTex formulas to images using the Google API
  6. Version: 0.0.1
  7. Author: Semenov Ivan
  8. Author URI: http: //*****.ru
  9. * /
  10. function latexg_shortcode ($ atts, $ content = null )
  11. {
  12. return "<img src = 'http: //chart.apis.google.com/chart? cht = tx & chs = 1x0 & chf = bg, s, FFFFFF00 & chco = 000000 & chl = $ content' alt = '$ content'>" ;
  13. }
  14. add_shortcode ( 'latexg' , 'latexg_shortcode' );
  15. ?>
* This source code was highlighted with Source Code Highlighter .


In the next version (if it will be) I will probably add a visual editor for entering formulas. This will make it easier to enter formulas for those unfamiliar with the LaTex language.

References:
About LaTex on WikiPedia

Download archive with plugin

PS
Plugin wrote for yourself. Use at your own risk. The author is not responsible for anything :)

Source: https://habr.com/ru/post/70188/


All Articles