I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Products » LaTeX Equation Editor »

Center equation vertically at "="

CodeCogs\′s Photo
7 Feb 10, 5:46PM
Center equation vertically at "="
The key to your problem is a yet unpublished option, namely gif.json, i.e.
http://codecogs.izyba.com/gif.json?\inline%20x=\frac{12}{y^2}
will give you
ParseEqn({ "latex": { 
  "type":"gif", 
  "equation":"x=\\frac{12}{y^2}", 
  "site":"unknown", 
  "file":"4e5c90d35fd5adf0fa848bd31eb534ad8_110_2_11.gif",   
  "url":"http://www.codecogs.com/sites/unknown/4e5c90d35fd5adf0fa848bd31eb534ad8_110_2_11.gif", 
  "width":"50", 
  "height":"25", 
  "baseline":"8" } });
Notice the last parameter 'baseline' that tells you the offset you need to get the image in the right place. Please remember you only get this parameter if you use '\inline' at the start of the equation. We don't work this out for images that will be placed on their own in the middle of the page.

To save you recoding the PHP, this is roughly what we use
// $local - is the directory in which to place the equation locally. 
function latexEqn_json($latex_formula, $font_size='normal', $dpi=110, $local=NULL)
{
  // don't waste CodeCogs time if you've nothing to request. 
  $latex_formula=trim(str_replace("\n",' ',$latex_formula));
	if(empty($latex_formula)) return;
 
	$url='';
	if($font_size!='normal') $url.='\\'.$this->font_size.' ';
	if($dpi!=110) $url.='\\'.$dpi.'dpi ';
	$url.=$latex_formula;
 
	// encode the url so its safe for transmittion to codecogs
	$url='http://latex.codecogs.com/gif.json?'.(str_replace(array('+',' '),array('+','&space;'), $url));
 
	// tell CodeCogs who you are - you must keep this line in
	ini_set('user_agent', "PHP\r\nReferer: http://".$_SERVER['SERVER_NAME']);
	$json=file_get_contents($url); // the return will be in the form: ParseEqn({ ... }); So need to
trim this down.
 
	$object=json_decode(substr($json,9,strlen($json)-11));
 
	if($local!==NULL)
	{
		if(!isset($object->latex->error))
		{
    		  copy($object->latex->url, $_SERVER['DOCUMENT_ROOT'].$local.$object->latex->file);
		  $object->latex->local=$local.$object->latex->file;
		}
		else error_log($object->latex->error);
	}
	return $object;
}

This PHP script will also copy the image to any local path you specify so the final HTML page can pull the images from your servers rather than ours.

Other points:
  • Use print_r(object) to see what is returned
  • You can easily extend the function to include other options our service supports, like background colour, font colour
Currently you need to be logged in to leave a message.