[l2h] Making a new environemnt that wraps around rawhtml

Ross Moore ross at ics.mq.edu.au
Sat Jul 30 06:50:45 CEST 2005

Hi Travis,

On 30/07/2005, at 5:56 AM, Travis Spencer wrote:

> Hey All,
> In my quest to associate unique IDs with arbitrary sections of my
> LaTeX documents, I think I may have found a solution that will work.
> I read about the `rawhtml' environment, and, with it, I can wrap any
> LaTeX command, environment, etc. in a DIV with a specific ID.  Then I
> can style that DIV using a CSS ID selector.  Here is an example:
> \begin{rawhtml}
> <div id="docTitle">
> \end{rawhtml}
> \maketitle
> \begin{rawhtml}
> </div>
> \end{rawhtml}

Yes, this certainly works...

> This produces the HTML `<div id="docTitle">...</div>' witch I can
> style using a selector such as `DIV#docTitle'.  This is helpful but
> that's a lot of typing.  So, I read about how to create a new, custom
> environment in hopes of distilling the above example down do something
> like this:
> \begin{htmldiv}{docTitle}
> \maketitle
> \end{htmldiv}
> To that end, I hacked up this new environment:
> \newenvironment{htmldiv}[1]
>                {\begin{rawhtml}<div id="#1">\end{rawhtml}}
>                {\begin{rawhtml}</div>\end{rawhtml}
> }

  ... but this cannot work.
The reason is similar to not being able to have \verb commands
within the argument of a (La)TeX macro.

With LaTeX2HTML, all instances of environments that take their
content 'verbatim', are located early. Their contents are then
stored away separately, so as not to be disturbed by the usual
translation of TeX commands.

Hence above, the "#1" will remain ...

> The problem with this is that the nested rawhtml environment doesn't
> set the id attribute's value to that of the enclosing environment's
> first argument but rather to a literal `#1'.

   ... as the value of the ID attribute, as you found.

> Does anyone more experienced with LaTeX know a way to pass this value
> into the rawhtml environment?

You cannot do it that way.
Nor do you have to ----  make use of  \HTMLcode  instead.

e.g., use a construction like:

     ....  whatever ....

Parametrise it via:


then use it with the body of your LaTeX source as:

    ... whatever ...

This way you can assign a particular ID to a <DIV>....</DIV> block.

But there's an even easier way to assign an automatically generated
ID tag to some (not all) LaTeX environments.

Try the following:

    ... table data ...

This results in HTML tags:

    <TABLE class="tabular" id="tabular<num>">

where the <num> is an automatically generated number.
It also* writes lines to the .css file; e.g.,

   TABLE.tabular           {   }
   #tabular17              {   }

(where <num> is 17 in this example.)

* Beware: this is not quite true.
To get these lines written, you *must* remove any
existing copies of the .css file that may be left-over
from a previous run of your document.
(The reason for this is explained below.)

Note that the CSS entries are written, even if blank;
that is, not specifying any styles yet.
This is so that you can later edit that .css file yourself,
to add style information.

If you use a more complex  [...] argument, then some CSS entries
may not be blank.

    \begin[mytable]{tabular} ....


    TABLE.mytable           {   }
    #tabular17              {   }


    \begin[mytable|font:italic]{tabular} ....


    TABLE.mytable           {   }
    #tabular17              { font : italic }

The reason that  LaTeX2HTML does *not* overwrite any existing
copies of the .css file is precisely so that you do not lose
any of the styles that you carefully hand-edited into the
.css file.

The envisioned work-flow is:
    1.  process your LaTeX source into HTML, establishing its
        overall logical structure;
    2.  add CSS style information later, to enhance its look.

If you add/remove information in the body of document, then
the automatically-generated ID tags will most-likely change.
This will mean that styles may no longer apply to the intended

To get the IDs to correspond, delete the .css file before
processing again with LaTeX2HTML.
    But now you lose those hand-edited style rules!

    You have to cope with this situation yourself.

Best approach, IMHO, is to associate style rules to the 'CLASS'
attribute, rather than to the 'ID' attribute.
Then you can keep a copy of this in a separate file, so it
can be easily edited back into the .css .

Another approach is to store *all* the style rules within the
LaTeX source, using the optional  [...|...]  arguments.

Then you need to remember to delete the .css file whenever
you need to re-process your LaTeX document with LaTeX2HTML.
A  Makefile  helps to ensure this, at least under Unix/Linux.
Under Windows/DOS, you could achieve this with a  .bat file, I guess.

Hope this helps,


> TIA.
> -- 
> Regards,
> Travis Spencer
> _______________________________________________
> latex2html mailing list
> latex2html at tug.org
> http://tug.org/mailman/listinfo/latex2html

Ross Moore                                         ross at maths.mq.edu.au
Mathematics Department                             office: E7A-419
Macquarie University                               tel: +61 +2 9850 8955
Sydney, Australia  2109                            fax: +61 +2 9850 8114

More information about the latex2html mailing list