# Defining HTML-like tags as TeX macros

I have to admit, my catcode skill are not that good.

I'm working with some templates that will be filled in by a programme (HTML::Template, made for HTML but very handy for LaTeX as well). I'd like my template to be compilable even without the tags being substituted.

Tags are of the form <TMPL_#1 #2> and </TMPL_#1>, any ideas as to how one can make these into macros themselfs?

Here is my current attempt where  does not work (and is thus outcommented) plus the catcode change affects the entire document whis is not really what I want.

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}

% enable this to make a WEB template compilable
% he <TMPL_VAR ..>'s will be replaced by the template system
\catcode\_=\active
\let\_\textunderscore%
\catcode<=\active
\gdef<TMPL_#1 #2>{\texttt{\textless TMPL\_#1 #2\textgreater}}
%\def</TMPL_#1>{\texttt{\textless /TMPL\_#1\textgreater}}

\begin{document}

<TMPL_VAR TEST>

<TMPL_IF NAME=TEST>
something
%</TMPL_IF>

\end{document}


any suggestions?

-
You could look at typehtml or for a more complete version xmltex –  David Carlisle Mar 5 at 10:35
\gdef<TMPL_#1 #2> just defines < and defines it so that it has to be followed by TMPL, and the commented redefinition would define < so that it had to be followed by /TMP –  David Carlisle Mar 5 at 10:40

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}

% enable this to make a WEB template compilable
% he <TMPL_VAR ..>'s will be replaced by the template system

\catcode<=\active
\catcode_=12
\gdef<#1>{\texttt{\textless #1\textgreater}}

\begin{document}

<TMPL_VAR TEST>

<TMPL_IF NAME=TEST>
something
</TMPL_IF>

\end{document}


If the catcode change should be local. just move the

\catcode<=\active
\catcode_=12


to the begin code of some environment eg \begin{template} .. \end{template} then surround you <> blocks with this environment

Or if you do not want to mess with the catcode of _ you can use

\catcode<=\active

\gdef<#1>{\texttt{\textless \detokenize{#1}\textgreater}}

-
This of course kills $x_2$, I'm not use if where will be any math in the templated documents, so I was hoping to avoid this. –  daleif Mar 5 at 11:41
@daleif as I say you can easily make the catcode change local to an environment if you want an environment that uses <> but no math. If you want an environment that mixes <> syntax and math can you give an example? –  David Carlisle Mar 5 at 11:54
@dale updated to use \detokenize rather than recatcode _ –  David Carlisle Mar 5 at 12:06
As it sits now, no I do not have an example. In reality it will not be that much of a deal, once the templating system has made its substitutions all the <TMPL...> stuff is gone. This was only to make the template itself compilable for when one is writing the template. The \detokenize version works well –  daleif Mar 5 at 12:11