WebTeX Macros

If you are familiar with TeX, you know that the ability to define macros that represent frequently used or complicated expressions greatly simplifies authoring mathematical notation. Both the WebEQ Viewer Control and Publisher support the use of WebTeX macros.

Macros can be defined in any of three ways: they can be defined in an external file, in the header of the HTML document, or in applet parameter tags. Macros can also be processed in a variety of ways by the WebEQ Applet and Publisher. For details about macro processing, consult the documentation on WebEQ Publisher: Preparing Source Documents and WebEQ Viewer Control: Viewer Control Applet Parameters.

For illustrating the WebTeX syntax for macro definition, we will consider specifying macro definitions using applet parameters. The simplest method is to use the macros parameter. Its syntax is as follows:

<param name=macros value="\define{\plusfifty}{+ 50}">
Here we have used the WebTeX \define{}{} command to define a new keyword, \plusfifty, which can then be used in the equation to signify where the symbols + 50 should be placed. In other words, the new keyword \plusfifty will be replaced by the expression "+ 50". Thus, if the equation markup is
<param name=eq value="y \plusfifty = x \plusfifty ">
the end result is that the applet will display:
y + 50 = x + 50

Macros can also be written using arguments, just as in TeX. WebTeX macros use the symbols #1, #2, #3 and so on to represent the arguments passed to a macro. Thus, the macro definition

<applet codebase="classes" code="webeq3.ViewerControl"
           width=500 height=100>
<param name=macros value="\define{\plusN}[1]{+ {#1}}">
<param name=eq value="y \plusN{35} = x \plusN{z - w}">
</applet>
produces the output
y + 35 = x + z - w

Note that in the definition of \plusN, the number of arguments is specified in square brackets immediately after the braced expression containing the keyword. When using a macro that accepts arguments, it is generally a good idea to enclose the arguments in curly braces, to prevent unforeseen side effects that might arise when substituting unusual values.

The macrofile parameter is used to specify a file containing macro definitions. The value of the macrofile parameter is actually a URL, so several documents can share the same macro definition file in a central location. For example, if the file "my_macros.def" contains:

\define{\plusfifty}{+ 50}
one could write
<applet codebase="classes" code="webeq3.ViewerControl"
           width=500 height=100>
<param name=macrofile value="my_macros.def">
<param name=eq value="y \plusfifty = x \plusfifty">
</applet>
in a document living in the same directory as "my_macros.def", while a document on another computer might contain an applet call something like this:
<applet codebase="classes" code="webeq3.ViewerControl"
           width=500 height=100>
<param name=macrofile
          value="http://www.macros.com/my_macros.def">
<param name=eq value="y \plusfifty = x \plusfifty">
</applet>
The WebTeX Examples include a Macros example.


[WebEQ Developers Suite]

Created: Nov 05 1997 --- Last modified: Sat Mar 24 17:23:26 2001
Copyright © 1997-2002 Design Science, Inc. All rights reserved.