Contents Previous Next

# Part VI - Mastering Macros

Macros are special purpose keywords, that are expanded on conversion time. They are used to insert dynamic information, for example the current date or information about the document source.

A macro is represented by the `%%` chars followed by its name, such as `%%date`. Some macros do accept an optional formatting string inside parenthesis, right after the macro name, such as `%%date(%Y-%m-%d)`. This format string mixes common text with special directives, identified by a percent sign % followed by an identification character. If no format string is given, the default format is used.

Macro Name | Expands to... | Default Format
--- | --- | ---
%%date | The current date | %Y%m%d
%%mtime | The source file modification time | %Y%m%d
%%infile | The source file path | %f
%%outfile | The output file path | %f
%%toc | The document TOC (Table of Contents) | -

General rules:

- The macro name is case-insensitive, so `%%date`, `%%DaTe` and `%%DATE` are identical
- Macros are valid at the document Header Area and Body Area, except %%toc that is valid on Body Area only
- A macro starts the Body Area if it is found in the Config Area
- A macro can be placed at any part of the line, including various per line (except %%toc, valid when alone in a line)
- A macro can be used inside links and images marks (except %%toc)
- Macros are not expanded in Titles, Verbatim, Raw and Tagged Areas

Full example (bold text are expanded macros):

This is the Txt2tags User Guide, converted to html by txt2tags from the userguide.t2t source file. The conversion was done at 2010-11-04 08:09:04, but the last change on the source document was made on 2010-10-31 00:26:16. Both source and converted file reside on the userguide directory.

Contents Previous Next