MultiEd's Icon


Macros: Writing Macros with Menus

The tutorial looks at the writing macros with menus. Menus can be particularly helpful if you run out of unused tool buttons. It assumes that you are already familiar with macros. If not, it is suggested that you look at the first 3 lessons in the Introduction to macros tutorial.

Let's assume that you want to write some web pages that use a style sheet called "MyStyles.css". Moreover you know that it is going to include a "bordered" table with several rows having exactly 2 columns whose data is to be centered.
{Comment Setup options menu
}{MenuOption}{MenuOptionS Stylesheet}{MenuOptionT Table}{MenuOptionR Row}{Comment
Display option menu
}{IfOptionS {TAB}{Literal on}<link rel="stylesheet" type="text/css" href="MyStyles.css">
{Literal off}}{Comment
a new "border table"
}{IfOptionT {Literal on}<table class="borderTable">

{Literal off}{UP}}{Comment
A new "centered row"
}{IfOptionR {Literal on}  <tr class = "center">


{Literal off}{UP}{UP}{UP}{UP}{UP}}

If you copy or type this macro, make sure that you don't include any blank
spaces or lines at the of the macro. Right click to download HtmlTools.macro.

There are several possible way to set up macros for this situation. The macro shown on the right is possibly one of the simpler ones but may not be the most useful. The option commands are shown in red, Other macro commands and keys are in black. The html code that can actually be written into the file is shown in green.

Before looking at the code, here is the popup menu it sets up. Normally the menu will appear underneath the programmable tool buttons but if the MultiEd window is too narrow, it will appear in the upper right courner.
Option menu
Now let's look at some of the code:

Question: How would we install this macro? There are at least four ways.

Note: When typing the {MenuOptionX ... } or {IfOptionX ... }" commands, the option character must immediately follow "MenuOption" or "IfOption" and then be followed by blank before giving the menu item text or the commands and keys that are to be processed when the option is selected. Any non-blank character can be used for the option X. Just be sure that MenuOption and IfOption use the same character.

Using the macro

In the following example, we will assume that the macro is stored in a tool button.

The suggested way of using this macro would normally be as follows:

  1. Open a new .html file saved with an appropriate name. We used "Example".
  2. Click the template tool button and pick the appropriate template. We will assume that it is "template-XHTML1.0Strick.html". The boiler plate for the typical xhtml file is typed.
  3. Move the cursor just before the </head> and click the tool button for this macro and select "Stylesheet" to have the Style tag typed into the document.
  4. When one is ready for the table, move the cursor to the appropriate place and click the tool button and select "Table". The <table ...> and </table> tags are typed.
  5. The cursor will be in the appropriate location for the first row so click the macro's tool button again and select "Row".

    After completing these steps the result would be.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    <html xmlns="" xml:lang="en" lang="en">
    	<meta http-equiv="content-type"
    		content="text/html;charset=utf-8" />
    	<meta http-equiv="Content-Style-Type" content="text/css" />
    	<link rel="stylesheet" type="text/css" href="Flowers2009.css">
    <table class="borderTable">
      <tr class = "center">

    That is a lot of code written with just a little clicking. One could add extra rows as needed and type the rest of the page.

    To help writing these tutorials, a much more extensive macro, Tutorial macro, was develovoped. (The easiest way to use this macro would be to RIGHT click and download the file and then open the Macro Control and open the file in that control. It could then be saved in a tool button.) It is found in the Tutorial subfolder. It has 15 menu items that were designed to supply HTML tags and code used in when writing these macros. With minor changes it could be adopted for other uses.

    The next tutorial Submenus shows how to write macros with submenus.

    Return to the beginning of this file         Return to the tutorial home page

    Revised: 10/5/2011