How can I copy TeX code from a GIF?

How can I copy TeX code from a GIF?

by Dan Stowell -
Number of replies: 6

Once the TeX filter has turned some TeX into a pretty GIF, is there a straightforward way I can copy the TeX code back out? (e.g. if I want to include it in my thesis, which I might be writing in LaTeX...)

As far as I can tell, the only current way of doing it is to view the page source, then hunt around for the image's ALT tag which has the code in it.

It would be very neat if every GIF created by the filter was also a javascript link, which would pop up a window showing the TeX code. This could then be copied-and-pasted back out as required.

OK: My example is here: www.ucl.ac.uk/is/fiso/lifesciences/test/texpopup.htm. You'll see that when you click on the image you get a javascript popup of the type that can be copied-and-pasted.

Average of ratings: -
In reply to Dan Stowell

Re: How can I copy TeX code from a GIF?

by Zbigniew Fiedorowicz -
To obtain this functionality, modify the file filter/tex/filter.php as follows (new lines are indicated with the comment //new):
    if ($imagefile) {
if (!file_exists("$CFG->dataroot/$CFG->texfilterdir/$imagefile") && isadmin()) { //new
$output .= "<a href=\"$CFG->wwwroot/$CFG->texfilterdir/texdebug.php\">"; //new
} else { //new
$output .= "<a href=\"xxxprompt('The TeX code used to generate this formula is:','";//new
$output .= preg_replace('/(\\)/',"\$1\$1",$tex) . "')\">";//new
} //new
$output .= "<img border=\"0\" $title $height $width src=\"";
if ($CFG->slasharguments) { // Use this method if possible for better caching
$output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php/$imagefile";
} else {
$output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php?file=$imagefile";
}
$output .= "\" />";
$output .= "</a>";//new
} else {
$output .= "Error: must pass URL or course";
}
return $output;

I will put these changes in the CVS.

PS. Martin, could you move this discussion to Mathematics Tools, which is a more appropriate forum?
In reply to Zbigniew Fiedorowicz

Re: How can I copy TeX code from a GIF?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In the CVS code, Zig, the information text should use get_string() to be compliant with the user's language choice. The problem is that this will be cached, and will look bad on multi-language sites.

If possible, I'd get rid of the information prompt altogether and possibly the whole alert.

One method would be to use the new lib/overlib library in Moodle to create a DHTML floatover (documentation).  eg

<a href="java-script:void(0);" on-click="return overlib('TeX code here', STICKY, CAPTION,
'Sticky!', CENTER);" onmouse-out="nd();"><img src="linktotex.gif" /></a>


The other would be a normal popup window (like a help window) that calls a normal script to print the TeX code.
In reply to Martin Dougiamas

Re: How can I copy TeX code from a GIF?

by Zbigniew Fiedorowicz -
OK. I'll try to do it with the overlib stuff.  I'll put it in the CVS tomorrow or the day after.
In reply to Zbigniew Fiedorowicz

Re: How can I copy TeX code from a GIF?

by Zbigniew Fiedorowicz -
I wasn't able to get overlib to work. It seems that this requires modifying headers of pages served by Moodle.  I can't see how this could be done from a filter function.

So I've gone the help-style popup route.  The new code is in the CVS.
Average of ratings: Useful (1)
In reply to Zbigniew Fiedorowicz

Re: How can I copy TeX code from a GIF?

by Dan Stowell -
The help-style method sounds good to me. Thanks very much for putting the time in!