WordPress: Install MathJax-LaTeX plugin


Step 1: Plugins -> add new
Step 2: Search: “MathJax-LaTeX”
Step 3: Click “Install now”
mathjax-latex-install

mathjax-latex-install-2

Installing Plugin: MathJax-LaTeX 1.3.3
Downloading install package from https://downloads.wordpress.org/plugin/mathjax-latex.1.3.3.zip…

Unpacking the package…

Installing the plugin…

Successfully installed the plugin MathJax-LaTeX 1.3.3.

mathjax-latex-install-3

Step 4: Click “Activate Plugin” to activate that plugin.

If your see the error below, you can fix following some steps below.

Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected T_FUNCTION in /home/tutorialspots/wp-content/plugins/mathjax-latex/mathjax-latex.php on line 234

Step a: Plugins -> Editor
Step b: select MathJax-LaTex
Step c: click “Select”

error mathjax 1

You can see in lines from 231 to 239

	public static function filter_br_tags_on_math( $content ) {
		return preg_replace_callback(
			'/(<math.*>.*<\/math>)/isU',
			function ( $matches ) {
				return str_replace( array( '<br/>', '<br />', '<br>' ) , '' , $matches[0] );
			},
			$content
		);
	}

solve mathjax error 1

Replace with:

	public static function filter_br_tags_on_math( $content ) {
		return preg_replace_callback(
			'/(<math.*>.*<\/math>)/isU',
			create_function ( '$matches',
				'return str_replace( array( \'<br/>\', \'<br />\', \'<br>\' ) , \'\' , $matches[0] );'
			),
			$content
		);
	}

Save file by click “Update file”

Edit Plugins
File edited successfully.

If you see “You need to make this file writable before you can save your changes. See the Codex for more information.” (Of course, you don’t see the button “Update file”) You must CHMOD file to 0777, go to FTP folder /wp-content/plugins/mathjax-latex/ and CHMOD file mathjax-latex.php to 0777.

solve mathjax error 2

solve mathjax error 3

Wow, now we can use the plugin MathJax-LaTex by clicking “Active” link in page “Installed plugins”.

We must understand why occur this error, because of the function preg_replace_callback of PHP<5.3 don't support the closures, you must use create_function, or write a static function and pass it as a callback.

preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] )

Usage: place the [latex] tag in your content of the post.

[ latex ]x[/ latex ]

Note: [ latex ] don’t use space: [latex].
Where “x” use the syntax following this

Related Post

,

No comments yet.

Leave a Reply