Forum archive 2000-2006

Michael Gage - dangerousMacros.pl

Michael Gage - dangerousMacros.pl

by Arnold Pizer -
Number of replies: 0
inactiveTopicdangerousMacros.pl topic started 5/22/2000; 9:50:03 PM
last post 5/22/2000; 9:50:03 PM
userMichael Gage - dangerousMacros.pl  blueArrow
5/22/2000; 9:50:03 PM (reads: 2665, responses: 0)


NAME

        dangerousMacros.pl --- located in the courseScripts directory


SYNPOSIS

    loadMacros(macrofile1,macrofile2,...)
    insertGraph(graphObject);
returns a path to the file containing the graph image.
    tth(texString)
returns an HTML version of the tex code passed to it.
    alias(pathToFile);
returns URL which links to that file


DESCRIPTION

dangerousMacros.pl contains macros with potentially dangerous commands such as require and eval. They can reference disk files for reading and writing and can create links. It may be necessary to modify certain addresses in this file to make the scripts run properly in different environments.

dangerousMacros.pl is loaded and reinitialized every time a new problem is rendered.

Sharing modules:

Most modules are loaded by dangerousMacros.pl

The modules must be loaded using require (not use) since the courseScriptsDirectory is defined at run time.

 The following considerations come into play.
    * One needs to limit the access to modules for safety -- hence only
modules in the F<courseScriptsDirectory> can be loaded.
    * Loading them in dangerousMacros.pl is wasteful, since the modules
would need to be reloaded everytime a new safe compartment is created.
(I believe that using require takes care of this.)
    * Loading GD within a safeCompartment creates infinite recurrsion in AUTOLOAD 
(probably a bug)
hence this module is loaded by translate.pl and then shared with
the safe compartment.
    * Other modules loaded by translate.pl are C<Exporter> and C<DynaLoader.
    * PGrandom is loaded by F<PG.pl> , since it is needed there.

The module name spaces loaded in dangerousMacros are:

    PGrandom (if not previously loaded)
WWPlot
Fun
Label
Circle

in addition the subroutine &evaluate_units is shared from the module Units.

loadMacros

loadMacros(macrofile1,macrofile2,...)

loadMacros takes a list of file names and evaluates the contents of each file. This is used to load macros which define and augment the PG language. The macro files are searched for in the directories specified by ($macrosPath), which by default is the course macros directory followed by WeBWorK's pg/macros directory. The latter is where the default behaviour of the PG language is defined. The default path is set in the (global.conf) file.

An individual course can modify the PG language, for that course only, by duplicating one of the macro files in the courseScripts directory and placing this file in the macro directory for the course. The new file in the course macro directory will now be used instead of the file in the courseScripts directory.

The new file in the course macro directory can by modified by adding macros or modifying existing macros.

Modifying macros is for users with some experience.

Modifying existing macros might break other standard macros or problems which depend on the unmodified behavior of these macors so do this with great caution. In addition problems which use new macros defined in these files or which depend on the modified behavior of existing macros will not work in other courses unless the macros are also transferred to the new course. It helps to document the problems by indicating any special macros which the problems require.

There is no facility for modifying or overloading a single macro. The entire file containing the macro must be overloaded.

Modifications to files in the course macros directory affect only that course, they will not interfere with the normal behavior of WeBWorK in other courses.

insertGraph

    $filePath = insertGraph(graphObject);
returns a path to the file containing the graph image.

insertGraph(graphObject) writes a gif file to the html/tmp/gif directory of the current course. The file name is obtained from the graphObject. Warnings are issued if errors occur while writing to the file.

The permissions and ownership of the file are controlled by $main::tmp_file_permission and $main::numericalGroupID.

Returns: A string containing the full path to the temporary file containing the GIF image.

InsertGraph draws the object $graph, stores it in "${tempDirectory}gif/$gifName.gif (or .png)" where the $imageName is obtained from the graph object. ConvertPath and surePathToTmpFile are used to insure that the correct directory separators are used for the platform and that the necessary directories are created if they are not already present.

The directory address to the file is the result. This is most often used in the construct

    TEXT(alias(insertGraph($graph)) );

where alias converts the directory address to a URL when serving HTML pages and insures that an eps file is generated when creating TeX code for downloading.

tth

    tth(texString)
returns an HTML version of the tex code passed to it.

This macro sends the texString to the filter program tth created by Ian Hutchinson. The tth program was created by Ian Hutchinson and is freely available for non-commerical purposes at the tth main site: http://hutchinson.belmont.ma.us/tth/.

The purpose of tth is to translate text in the TeX or Latex markup language into HTML markup as best as possible. Some symbols, such as square root symbols are not translated completely. Macintosh users must use the "MacRoman" encoding (available in 4.0 and higher browsers) in order to view the symbols correctly. WeBWorK attempts to force Macintosh browsers to use this encoding when such a browser is detected.

The contents of the file tthPreamble.tex in the courses template directory are prepended to each string. This allows one to define TeX macros which can be used in every problem. Currently there is no default tthPreamble.tex file, so if the file is not present in the course template directory no TeX macro definitions are prepended. tth already understands most Latex commands, but will not, in general know AMS-Latex commands. Additional information on tth is available at the tth main site.

This macro contains code which is system dependent and may need to be modified to run on different systems.

The link to tth for non-commerical is http://hutchinson.belmont.ma.us/tth/. Binaries for many operating systems are available as well as the source code. Links describing how to obtain tth for commerical use are also available on this page.

math2img

math2img(texString) - returns an IMG tag pointing to an image version of the supplied TeX

alias

    alias(pathToFile);
returns A string describing the URL which links to GIF or html file
(in HTML and Latex2HTML modes).
or a path to the appropriate eps version of a GIF file
(TeX Mode)

alias allows you to refer to auxiliary files which are in a directory along with the problem definition. In addition alias creates an eps copy of GIF files when downloading hard copy (TeX mode).

As a rule auxiliary files that are used by a number of problems in a course should be placed in html/gif or html or in a subdirectory of the html directory, while auxiliary files which are used in only one problem should be placed in the same directory as the problem in order to make the problem more portable.

Files in the html subdirectory

When not in TeX mode:

If the file lies under the html subdirectory, then the approriate URL for the file is created. Since the html subdirectory is already accessible to the webserver no other changes need to be made. The file path for this type of file should be the complete file path. The path should start with the prefix defined in $Global:htmlDirectory.

When in TeX mode:

GIF files will be translated into an eps file (using system dependent code) and placed in the directory tmp/eps. The full path to this file is returned for use by TeX in producing the hard copy. (This should work even in a chrooted environment.) in producing the hard copy. (This should work even in a chrooted environment.)

The conversion is done by a system dependent script called gif2eps which should be in the scripts directory

The URL's for the other files are produced as in non-tex mode but will of course not be active.

Files in the tmp subdirectory

When not in TeX mode:

If the file lies under the tmp subdirectory, then the approriate URL for the file is created. Since the tmp subdirectory is already accessible to the webserver no other changes need to be made. The file path for this type of file should be the complete file path. The path should start with the prefix defined in $Global:tempDirectory.

When in TeX mode:

GIF files will be translated into an eps file (using system dependent code) and placed in the directory tmp/eps. The full path to this file is returned for use by TeX in producing the hard copy. (This should work even in a chrooted environment.)

The conversion is done by a system dependent script called gif2eps which should be in the scripts directory

The URL's for the other files are produced as in non-tex mode but will of course not be active.

Files in the course template subdirectory:

When not in TeX mode:

If the file lies under the course templates subdirectory, it is assumed to lie in subdirectory rooted in the directory containing the problem template file. An alias is created under the html/tmp/gif or html/tmp/html directory and linked to the original file. The file path for this type of file is a relative path rooted at the directory containing the problem template file.

When in TeX mode:

GIF files will be translated into an eps file (using system dependent code) and placed in the directory html/tmp/eps. The full path to this file is returned for use by TeX in producing the hard copy. (This should work even in a chrooted environment.)

The conversion is done by a system dependent script called gif2eps which should be in the scripts directory

The URL's for the other files are produced as in non-tex mode but will of course not be active.

File path = /ww/webwork/pg/macros/dangerousMacros.pl

<| Post or View Comments |>