From WeBWorK

Jump to: navigation


WeBWorK::PG::ImageGenerator - create an object for holding bits of math for LaTeX, and then to process them all at once.


FIXME: add this



Arguments to pass to dvipng.


If true, don't delete temporary files.


TeX to prepend to equations to be processed.


TeX to append to equations to be processed.



Returns a new ImageGenerator object. %options must contain the following entries:

 tempDir  => directory in which to create temporary processing directory
 latex    => path to latex binary
 dvipng   => path to dvipng binary
 useCache => boolean, whether to use global image cache

If useCache is false, %options must also contain the following entries:

 dir      => directory for resulting files
 url      => url to directory for resulting files
 basename => base name for image files (i.e. "eqn-$psvn-$probNum")

If useCache is true, %options must also contain the following entries:

 cacheDir => directory for resulting files
 cacheURL => url to cacheDir
 cacheDB  => path to cache database file

Options may also contain:

 dvipng_align    => vertical alignment option (a string to use like baseline, or 'mysql')
 dvipng_depth_db => database connection information for a "depths database"
 useMarkers      => if you want to have the dvipng images vertically aligned, this involves adding markers

Adds the string as part of the TeX preamble for all equations in the problem. For example $rh_envir->{imagegen}->addToTeXPreamble("\newcommand{\myVec}[#1]{\vec{#1}} ");

Will define a question wide style for interpreting \( \myVec{v} \)

If this statement is placed in then the backslashes must be doubled since it is a .pl file
not a .pg file

Forces every equation picture to be recalculated. Useful for debugging.

add($string, $mode)

Adds the equation in $string to the object. $mode can be "display" or "inline". If not specified, "inline" is assumed. Returns the proper HTML tag for displaying the image.


Uses LaTeX and dvipng to render the equations stored in the object.

The option body_text is a reference to the text of the problem's text. After rendering the images and figuring out their depths, we go through and fix the tags of the images to get the vertical alignment right. If it is left out, then we skip that step.

If the key "mtime" in %options is given, its value will be interpreted as a unix date and compared with the modification date on any existing copy of the first image to be generated. It is recommended that the modification time of the source file from which the equations originate be used for this value. If the key "refresh" in %options is true, images will be regenerated regardless of when they were last modified. If neither option is supplied, "refresh" is assumed.

NOTE: It's not clear to me that mtime has been implemented -- MEG - 2011/06