TeX4ht: Low-level Commands

There are four commands which are very useful to write custom configuration for TeX4ht. They are:

  1. \NewConfigure
  2. \Configure
  3. \HCode
  4. \Tg

TeX4ht does not redefine environments or macros, instead, it inserts hooks into the definitions so that the original definitions remain undisturbed while hooks helping to insert HTML code at appropriate locations of content in the desired way. Hooks are nothing but macros which will expand to target markup as per our dictates. The \NewConfigure and \Configure commands allow us to seed the hooks into the original definitions. Let us look at an example.

  \def\one#1#2#3{#1\space#2\space#3}

We have a macro one which takes up three arguments. Now, suppose that we want to insert custom HTML elements at the

  1. beginning of all arguments
  2. end of all arguments
  3. between first and second arguments
  4. between second and third arguments

We shall make use of \NewConfigure command to define hooks.

 \NewConfigure{one}[4]%
     {\def\a@one{#1}\def\b@one{#2}%
      \def\c@one{#3}\def\d@one{#4}}

The syntax is

  \NewConfigure{name}[i]{body}

where name is the name of macro without the backslash, i is the number of hooks and body is where we define all the hooks. In the example, we want to define four hooks for the macro \one. Hence, we assign the first hook to \a@one (you can choose any name you like), second to b@one, so on and so forth. Then, we define another macro similar to \one with three arguments and insert the pre-defined hook macros at appropriate locations. So the definition starts with \a@one and ends with \b@one hooks. \c@one is inserted in between arguments #1 and #2. \d@one is inserted between the arguments #2 and #3. Once \@tempa is defined, we then equate \one with \@temp with a \let command. See the code below:

  \def\@temp#1#2#3{\a@one#1\c@one#2\d@one#3\b@one}
   \let\one\@tempa

Now, comes the real meat of the configuration process wherein we make use of \Configure command to insert required HTML markup.

  \Configure{one}
   {\Tg<span class="one">\Tg<code>}{\Tg</b>\Tg</span>}
   {\Tg</code>\Tg<em>}{\Tg</em>\Tg<b>} 

The above configuration inserts <span class“one”>= in the beginning and the corresponding closing element, </span> gets inserted in the end, <code> element is inserted after <span> to make the strings in first argument verbatim, </code><em> added after first argument which closes the verbatim mode and starts an emphasize for second argument, </em><b> are inserted between second and third which close the emphasize and start a bold face, in the end we close the </b> to complete the bold facing of third argument. Let us try this on a typical example of \one:

  one{verbatim}{emphasize}{boldface}

As you might have guessed, TeX4ht will generate following HTML from above source:

  <span class="one">
   <code>verbatim</code>
   <em>emphasize</em>
   <b>boldface</b>
  </span>

If you want to insert necessary css code to interpret <span class="one">, you might add the following line somewhere in your document or configuration file:

  \Css {.one {<your css code >}}

Pages: 1 2

2 Responses to “TeX4ht: Low-level Commands”


Leave a Reply