{"id":482,"date":"2010-09-22T15:33:49","date_gmt":"2010-09-22T10:03:49","guid":{"rendered":"http:\/\/www.cvr.cc\/?p=482"},"modified":"2010-09-22T15:33:49","modified_gmt":"2010-09-22T10:03:49","slug":"tex4ht-low-level-commands","status":"publish","type":"post","link":"https:\/\/cvr.cc\/?p=482","title":{"rendered":"TeX4ht: Low-level Commands"},"content":{"rendered":"<p>There are four commands which are very useful to write custom configuration for T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X4ht. They are: <!--more--><\/p>\n<ol>\n<li><code>\\NewConfigure<\/code><\/li>\n<li><code>\\Configure<\/code><\/li>\n<li><code>\\HCode<\/code><\/li>\n<li><code>\\Tg<\/code><\/li>\n<\/ol>\n<p>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X4ht does not redefine environments or macros, instead, it inserts <em>hooks<\/em> into the definitions so that the original definitions remain undisturbed while hooks helping to insert <small>HTML<\/small> 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 <code>\\NewConfigure<\/code> and <code>\\Configure<\/code> commands allow us to seed the hooks into the original definitions. Let us look at an example.<\/p>\n<pre>\n  \\def\\one#1#2#3{#1\\space#2\\space#3}\n<\/pre>\n<p>We have a macro <code>one<\/code> which takes up three arguments. Now, suppose that we want to insert custom <small>HTML<\/small> elements at the<\/p>\n<ol>\n<li>beginning of all arguments<\/li>\n<li>end of all arguments<\/li>\n<li>between first and second arguments<\/li>\n<li>between second and third arguments<\/li>\n<\/ol>\n<p>We shall make use of <code>\\NewConfigure<\/code> command to define hooks.<\/p>\n<pre>\n \\NewConfigure{one}[4]%\n     {\\def\\a@one{#1}\\def\\b@one{#2}%\n      \\def\\c@one{#3}\\def\\d@one{#4}}\n<\/pre>\n<p>The syntax is<\/p>\n<pre>\n  \\NewConfigure{name}[i]{body}\n<\/pre>\n<p>where <em>name<\/em> is the name of macro without the backslash, <em>i<\/em> is the number of hooks and <em>body<\/em> is where we define all the hooks. In the example, we want to define four hooks for the macro <code>\\one<\/code>. Hence, we assign the first hook to <code>\\a@one<\/code> (you can choose any name you like), second to <code>b@one<\/code>, so on and so forth. Then, we define another macro similar to <code>\\one<\/code> with three arguments and insert the pre-defined hook macros at appropriate locations. So the definition starts with <code>\\a@one<\/code> and ends with <code>\\b@one<\/code> hooks. <code>\\c@one<\/code> is inserted in between arguments <code>#1<\/code> and <code>#2<\/code>. <code>\\d@one<\/code> is inserted between the arguments <code>#2<\/code> and <code>#3<\/code>. Once <code>\\@tempa<\/code> is defined, we then equate <code>\\one<\/code> with <code>\\@temp<\/code> with a <code>\\let<\/code> command. See the code below:<\/p>\n<pre>\n  \\def\\@temp#1#2#3{\\a@one#1\\c@one#2\\d@one#3\\b@one}\n   \\let\\one\\@tempa\n<\/pre>\n<p>Now, comes the real meat of the configuration process wherein we make use of <code>\\Configure<\/code> command to insert required <small>HTML<\/small> markup.<\/p>\n<pre>\n  \\Configure{one}\n   {\\Tg&lt;span class=\"one\"&gt;\\Tg&lt;code&gt;}{\\Tg&lt;\/b&gt;\\Tg&lt;\/span&gt;}\n   {\\Tg&lt;\/code&gt;\\Tg&lt;em&gt;}{\\Tg&lt;\/em&gt;\\Tg&lt;b&gt;} \n<\/pre>\n<p>The above configuration inserts <code>&lt;span class<\/code>&#8220;one&#8221;&gt;= in the beginning and the corresponding closing element, <code>&lt;\/span&gt;<\/code> gets inserted in the end, <code>&lt;code&gt;<\/code> element is inserted after <code>&lt;span&gt;<\/code> to make the strings in first argument verbatim, <code>&lt;\/code&gt;&lt;em&gt;<\/code> added after first argument which closes the verbatim mode and starts an emphasize for second argument, <code>&lt;\/em&gt;&lt;b&gt;<\/code> are inserted between second and third which close the emphasize and start a bold face, in the end we close the <code>&lt;\/b&gt;<\/code> to complete the bold facing of third argument. Let us try this on a typical example of <code>\\one<\/code>:<\/p>\n<pre>\n  one{verbatim}{emphasize}{boldface}\n<\/pre>\n<p>As you might have guessed, T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X4ht will generate following <small>HTML<\/small> from above source:<\/p>\n<pre>\n  &lt;span class=\"one\"&gt;\n   &lt;code&gt;verbatim&lt;\/code&gt;\n   &lt;em&gt;emphasize&lt;\/em&gt;\n   &lt;b&gt;boldface&lt;\/b&gt;\n  &lt;\/span&gt;\n<\/pre>\n<p>If you want to insert necessary <code>css<\/code> code to interpret <code>&lt;span class=\"one\"&gt;<\/code>, you might add the following line somewhere in your document or configuration file:<\/p>\n<pre>\n  \\Css {.one {&lt;your css code &gt;}}\n<\/pre>\n<p>\n<!--nextpage-->\n<\/p>\n<h4 style=\"color: #27d;\"><code>\\HCode<\/code> and <code>\\Tg<\/code><\/h4>\n<p>These are the two commands used in T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X4ht to insert target markup elements as <code>\\special<\/code>s into the <code>dvi<\/code> file which are then extracted while post-processing with <code>tex4ht<\/code> binary program. <code>\\Tg<\/code> has the following syntax:<\/p>\n<pre>\n  \\Tg&lt;#1&gt;\n<\/pre>\n<p>Between the angle brackets, you might add whatever markup you need to insert. The examples sited above to explain the functionality of <code>\\Configure<\/code> command make use of <code>\\Tg<\/code>. It is fit for inserting a single element with or without attributes. The angle brackets act as delimiters.<\/p>\n<p>The functionality of <code>\\HCode<\/code> command is also the same, except that there are no delimiters, which allows one to insert any kind of arbitrary code as arguments to <code>\\HCode<\/code>.<\/p>\n<pre>\n  \\HCode{&lt;section id=\"}%\n    \\stepcounter{sctr}sec.\\thesctr%\n   \\HCode{\"&gt;}\n<\/pre>\n<p>This will generate the following <small>HTML<\/small> element in the output, assuming that we have <code>9<\/code> as the value for <code>\\thesctr<\/code>:<\/p>\n<pre>\n  &lt;section id=\"sec.9\"&gt;\n<\/pre>\n<p>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X4ht has already defined <code>\\Configure<\/code> with different numbers of hooks for commonly used commands in L<span style=\"position: relative; bottom: 0.3ex; margin-left: -0.36em; margin-right: -0.15em; text-transform: uppercase\"><small>a<\/small><\/span>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X and several popular packages used in L<span style=\"position: relative; bottom: 0.3ex; margin-left: -0.36em; margin-right: -0.15em; text-transform: uppercase\"><small>a<\/small><\/span>T<span style=\"position: relative; top: 0.5ex; margin-left: -0.1667em; margin-right: -0.125em; text-transform: uppercase\">e<\/span>X. However, if you want to manipulate any of the default structure or want to add extra functionality over those already available, <code>\\NewConfigure<\/code> comes handy and above explanation might be of help to explore further.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are four commands which are very useful to write custom configuration for TeX4ht. They are:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,23,29,17],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-configure","category-hcode","category-newconfigure","category-tg"],"_links":{"self":[{"href":"https:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=482"}],"version-history":[{"count":0,"href":"https:\/\/cvr.cc\/index.php?rest_route=\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cvr.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}