WIMS technical documentation

This document is currently under indexed style. You may change it to integral or folding style. There is also a general help and a paper on WIMS.


Variables in a module

Definition and substitution of variables

WIMS variables have only one type: they are all string variables. Numerical evaluation can be done on variables via the variable command !eval.

A variable may be defined or modified in a variable processing file, or by the commands !let and !default.

Variable names can contain any alphanumeric character, as well as the underscore character _. There is a limit to the length of variable names, and a limit to the length of values. (Limits depending on server configuration.)

Variable substitution can be done anywhere in a variable processing file or a phtml file (even in the name field of a variable definition line). A word preceeded by the character $ is considered to be a variable name, and will be replaced by its value when the line containing it is processed.

Special rules of variable substitution:

  • If the character $ is followed by a space, it will be discarded.
  • The string $$ is replaced by a single $.
  • If the character $ is followed by the left parenthesis (, the matching ) will be located, the content of the pair of parentheses substituted. The result of the substitution will then be used as the name of variable, and finally the whole thing will be replaced by the value of the last variable. This allows nested substitutions, as well as substitution of a variable which is followed by an alphanumeric character.
    Example: if the variable i has value 3 and the variable alpha3beta has value pi, the string
    3*$(alpha$(i)beta)*x
    will become
    3*pi*x
    after substitution.

    Array addressing: if the variable i contains a comma-separated list a,b,c,d,e, then the string $(i[3]) gives c after substitution, and $(i[2 to 4]) gives b,c,d, etc.

    Two-dimensional array addressing is also available: if

    $M=x,y,z;a,b,c
    (a 2x3 matrix), then
    $(M[1;3,2])=z,y
  • If the character $ is followed by the left bracket [, the matching ] will be located, the content of the pair of brackets substituted then evaluated to a real number value whose precision depends on the value of print_precision. This value will replace the whole thing together with the leading $.
    It can be used for array subscripts.
    Example: if the variable i has value 3 and the variables
    a1 has value 3 and
    a2 has value pi,
    then the string
      $(a$[$i-1])*x+$(a$[$i-2])
    will become
      pi*x+3
    after substitution.
  • If the value of a variable being substituted contains the character $, this value will again be substituted, until no more substitution is needed. The server has a built-in limit of nested substitutions; infinite nested substitions will violate this limit and generate an error message.

Reserved variable names

The following names are reserved for their special meanings. They should not be used for internal needs of any module.
  • Do not use variables with names consisting only of numbers. They are reserved for future enhancements of the language.
  • Variables named cmd, module, session, lang, special_parm, user, useropts, worksheet, are reserved for special parameter passed by the user. A module's variable processing file or phtml file can read but cannot set them.
    Refer to the section Basic structure of WIMS for the meaning of these variables.
  • The variable no_name has a special use:
    Parameters in the user query string with no name (for example when the coordinate of a mappable image is passed this way to the http server) will be registered under this variable. For this reason, it should not be used for other purposes.
  • All variable names starting with wims_ will have special meanings for WIMS server. A module should read or write them only for the special meanings they are designed for.
  • Variable names starting with m_ are reserved for inline mathematical fonts. The module programmer may redefine them, but then their original meaning will be lost.
  • The variable module_dir has a value preset to the directory of the current module (with respect to the public home directory of the server). This value is usually $module_dir=module/$module (but may vary with the config of the installation).
  • Variable names starting with module_ will have special meanings: they are used to hold variables defined in the module's INDEX file. Currently implemented variables:
    VariablesMeaning
    module_titletitle of the module
    module_descriptionshort description of the module
    module_authorname(s) of author(s) of the module
    module_addresse-mail address of the (principal) author
    module_maintainername of the current maintainer
    module_maintainer_addresse-mail address of the maintainer
    module_copyrightcopyright notice of the module
    module_versioncurrent version of the module
    module_wims_versionminimal WIMS version required
    to run this module
    module_diraddress of the module to use inside the module for example to insert an image loaded in a subdirectory of the module
    module_languagelanguage of the module
    (en, fr, de, or ...)
    module_categorycategory of the module
    (exercise, tool, course, pedia, recreation, adm, other)
    module_levellevel of the module
    module_domainalgebra, analysis, geometry, ...
    module_keywordskeywords, to be placed in the html header
    module_scoring= yes if the module gives scores according to WIMS standard
    module_dataaddress of datamodule

    Also, variables module_has_intro, module_has_help and module_has_about have value "yes" if the module's directory contains the respective .phtml file. These variables are used in the command !homeref.
  • Some environment variables setup by httpd are readable by WIMS modules under names starting with httpd_. For example, the environment variable REMOTE_HOST becomes httpd_REMOTE_HOST under WIMS.
    Please refer to httpd protocol specifications for details of such variables.
  • All variable names starting with ins_, insplot_, instex_ will have special meanings for the corresponding dynamic insertion engines. A module should read or write them only for the special meanings they are designed for.
  • If your module uses an external package (e.g. pari), variable names starting with the name of the interface to that external package followed by _ will have special meanings for that interface, and should be reserved for that purpose.