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 »

Extra space and \phantom commands

tigran.saluev\′s Photo
11 Jul 11, 5:23PM
(4 replies)
Extra space and \phantom commands
Sorry if someone has already asked about this, but... There is a command in LaTeX, \vphantom{}; I tried to use it to make all images (for example, for or ) have a bottom space so that they could be displayed properly in HTML text with "vertical-align: baseline". But the renderer crops that extra space. The same thing with \hphantom{} placed at the beginning of a formula. Is there any way to fix that or some another way to place IMGs into HTML?
CodeCogs\′s Photo
11 Jul 11, 7:50PM
Hi,

You've asked a very interesting question that has certainly been asked before. Unfortunately using vphantom etc isn't going to work if you need to move the image downwards.

We do calculate the baseline of an image, you can see this if you use:
http://latex.codecogs.com/gif.json?-inline \frac{x}[y}
which gives:
ParseEqn({ "latex": { "type":"gif", "equation":"\\frac{x}[y}", "site":"unknown",
"file":"1d09ff81ad2211e00b9ffa4ded627666.gif",
"url":"http://www.codecogs.com/eq/1d/1d09ff81ad2211e00b9ffa4ded627666.gif", "width":"17", "height":"22", "baseline":"9" } });

We do have some trial code

Which searches an html pages (just like latexit.js here http://www.codecogs.com/latex/htmlequations.php) however we've never been particular happy about the performance.

If you've time to work on this, then we'd be very happy to receive suggestions
tigran.saluev\′s Photo
12 Jul 11, 5:10PM
Thanks a lot!

The script searching an html pages looks interesting but I think websites should cache generated images and therefore the script is not the best choice.

CodeCogs\′s Photo
12 Jul 11, 7:25PM
If you want to cache images, then you need access to the backend server technology (most often PHP or ASP). You can then make the same request as above, but within PHP and therefore extract from the JSON data

The following should achieve what you need. There is (somewhere) another forum post on much the same:

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=LLATEX_ENGINE.(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) && isset($object->latex->file))
		{
		  if(!isset($object->latex->local)) 	// then move from remote server to local machine
			{
				copy($object->latex->url, $_SERVER['DOCUMENT_ROOT'].$local.$object->latex->file);
			}
			else
			{
			  // otherwise this is on a codecogs machine 
				//this option isn't normally available for clients, so hard coded paths can be ignored.
				copy('/var/www/html/'.$object->latex->local,
$_SERVER['DOCUMENT_ROOT'].$local.$object->latex->file);
			}
		  $object->latex->local=$local.$object->latex->file;
		}
		else error_log($object->latex->error);
	}
	return <div class="orangebox">[$]</div>object;
}
stephem\′s Photo
13 Jul 11, 8:49AM
Vertical alignment of images is complicated by the fact that different browsers use different baselines for the image. However, Mike Boyle at http://boyle.black-holes.org/dokuwiki_latex has an ingenious way of getting LaTeX to output the vertical offset required and puts the amount required in the filename. He uses the ideas given at http://mactextoolbox.sourceforge.net/articles/baseline.html which uses raisebox to move the image vertically.

I have used Mike Boyle's method and indeed, supplied it with LatexRender. It works well. Again though remember it won't be perfect given the peculiarities of each browser.
Currently you need to be logged in to leave a message.