The LaTeX2HTML Translator    Drakos/Moore 

previous up next To: Conditional Text index contents


Arbitrary Tags and Attributes

For version 97.1 of LATEX2HTML there is a new command which provides an extremely flexible way to include HTML 3.2 tags, along with any values for the ``attributes'' of that tag, if desired.
\HTMLcode[<attribs>]{<tag>}
\HTMLcode[<attribs>]{<tag>}{<contents>}
When the <tag> also needs a closing tag (e.g <I>...</I>) the <contents> must be given, enclosed in braces. Both the opening and closing tags then will be placed correctly.

Warning: In version 97.1 this command was actually called \HTML. However style files may well define \HTML to mean something else, like a styled version of the HTML acronym. So in version 98.1 the name has been changed to \HTMLcode.

If no other definition of \HTML exists, then this command will be defined, to work the same as \HTMLcode.

An important aspect of this is that any of the <tag>, <attribs> and <contents> may be given wholly by expanding a LATEX macro, or may contain arbitrary macros, perhaps including other \HTMLcode commands. The following table was constructed using this feature; its LATEX source follows.


Figure 6: Example use of macros for raw HTML code.
 

A listing of the different text styles available in HTML 3.2
  • a simple test of ``bold-face'', using <B> .
  • a simple test of ``italics'', using <I> .
  • a simple test of ``teletype-text'', using <TT> .
  • a simple test of ``underlining'', using <U> .
  • a simple test of ``strikeout'', using <STRIKE> .
  • a simple test of ``emphasis style'', using <EM> .
  • a simple test of ``strong style'', using <STRONG> .
  • a simple test of ``code style'', using <CODE> .
  • a simple test of ``citation style'', using <CITE> .
  • a simple test of ``definition style'', using <DFN> .
  • a simple test of ``sample style'', using <SAMP> .
  • a simple test of ``keyboard style'', using <KBD> .
  • a simple test of ``variable style'', using <VAR> .


\newcommand{\myalign}{center}
\newcommand{\mylist}{UL}
\newcommand{\myitem}[2]{\HTMLcode[disc]{LI}{\simpletest{#1}{#2}}}
\newcommand{\simpletest}[2]{%
 \HTMLcode{#1}{ a simple test of ``#2'',} using \HTMLcode{CODE}{<#1>} .}
\newcommand{\tableopts}{10,border=5}

\newcommand{\tablelist}[4][left]{\HTMLcode[#1]{DIV}{
\HTMLcode[\tableopts]{TABLE}{
\HTMLcode[bottom]{CAPTION}{
#3
}\HTMLcode{TR}{\HTMLcode{TD}{
\HTMLcode{#2}{
#4
}}}
}}\HTMLcode[all]{BR}}

\tablelist[\myalign]{\mylist}{%
\textbf{A listing of the different text styles available in HTML 3.2}}{%
\myitem{B}{bold-face}
\myitem{I}{italics}
\myitem{TT}{teletype-text}
\myitem{U}{underlining}
\HTMLcode[circle]{LI}{\simpletest{STRIKE}{strikeout}}
\myitem{EM}{emphasis style}
\myitem{STRONG}{strong style}
\myitem{CODE}{code style}
\myitem{CITE}{citation style}
\myitem{DFN}{definition style}
\HTMLcode[square]{LI}{\simpletest{SAMP}{sample style}}
\HTMLcode[square]{LI}{\simpletest{KBD}{keyboard style}}
\myitem{VAR}{variable style}}


The above code demonstrates many aspects of the way \HTML commands can be used.

* nesting:
\HTML commands can be nested to arbitrary depth.
* macros:
Macros can be used to specify all or part of each argument.
* within macros:
\HTMLcode commands work correctly within the expansions of other macros.
* attribute values:
Information within <attribs> can be specified in a very loose way, as a comma-separated list of key/value pairs or as single values.
Not even the commas are necessary: space(s), <tab>s or newlines are equally effective. Indeed the horizontal rules preceding and following the table were specified by:
\HTMLcode[50\% 3 noshade center]{HR}
* attribute names:
Usually it is not necessary to know the names of the attributes to the tags that are to be used. It is sufficient just to give the values; these will be matched to the appropriate attribute, according to the type of data required. (If names are given, these are case-insensitive.)
* newlines:
Although LATEX ignores linebreaks within the source code, this is not so with LATEX2HTML. The strange spreading-out of the definition of the \tablelist command above was done with the purpose solely of making the code in the resulting HTML files more easily readable, to a human. (As most browsers ignore those newlines anyway, more compact code would have rendered the same on-screen.)


Some further aspects of the use of this \HTML command are not apparent from the above example.

* invalid <tag>:
If a <tag> is specified that is not part of the HTML 3.2 specifications, then it and its attributes are not placed into the HTML document created by LATEX2HTML. Any <contents> is included as ordinary data; i.e. as text in paragraphs, etc.

* required attributes:
Some tags have attributes which are required to have values, if that tag is to be included in an HTML document. Using the \HTML command, if any such attribute is not given an appropriate value then the tag is ignored. Any <contents> are included in the document, as ordinary character data.

* valid HTML:
Currently there is no checking that the <contents> of a <tag> contains only data (perhaps including other tags) allowed by the DTD for HTML 3.2.
The requirement to produce valid HTML currently rests with the user.
This issue will be addressed in forthcoming revisions of LATEX2HTML.

* extra attributes and values:
The list of attributes for a <tag> can include key-value pairs whose keys do not match any valid attribute for the <tag>. Such key-value pairs are simply ignored. Similarly extra data values are ignored, as are values that do not match the requirements for any valid attribute.

* attributes with similar data-types:
Several attributes to a <tag> may use values having the same or similar data-types. First any key-value pairs are processed. Remaining values are allocated to those attributes which do not already have a value. An ordering of the attributes is used, based on a perceived likelihood of each attribute being required to be changed from its default setting.


previous up next To: Conditional Text index contents

 Ross Moore 1991-03-26    Processed by LaTeX2HTML-FU