[l2h] Custom environments

Ross Moore ross at maths.mq.edu.au
Tue Jun 15 04:22:39 CEST 2004

Hello Prakash,

On 15/06/2004, at 6:20 AM, Prakash Countcham wrote:

>   Hello,
>   I have already sent this mail one week ago, but I retry as I didn't 
> find it in the archive. Sorry for duplicates.

The  latex2html  mailing list gets a lot of spam emails, and I don't 
a lot of spare time to sift them for the legitimate mails from people
who haven't subscribed.
So it's better to subscribe first, then send messages.

>   I try to use latex2html to convert a document with custom 
> environments.
> For example, here is a customized \input:
> \RequirePackage{stack}
> \NewStack{reldir}{.}
> \newcommand\relinput[2]{%
>   \Push{reldir}{\Stack{reldir}/#1}%
>   \input{\Stack{reldir}/#2}%
>   \Pop{reldir}}

No, customising  \input  in this way cannot not work with LaTeX2HTML.

This is because LaTeX2HTML builds a single large job from the
main document, and its \input and \include'd files *before*
starting to process macros and environments.

Since  \relinput  is seen as an ordinary macro, it will not be
expanded to reveal the  \input  that it contains,
until after the job files have been amalgamated.
At that time, it is *too late* to add new material to be
interpreted within the job.

However, if you just want to make an image of the file's
(La)TeX contents...

> First, I tried to let tex handle this command with:
> &process_commands_in_tex (<<_RAW_ARG_CMDS_);
> relinput # {} # {}

   ... then this approach can be made to work, ...

> But the file in question is said not to be found even if it exists (I 
> don't know exactly why -- I guess it's because the generated files are 
> in a different directory).

  ... but note that TeX processing takes place in a different
directory to where your document sources are located.

Usually this is just one level deeper, so an extra  '../'
in the directory path should be sufficient.

> Then, I tried to adapt the subroutine do_cmd_input in the following 
> way,
> but I have got the same problem.
> $relinput_rep = ".";

First try testing using
      $relinput_rep = "..";

> sub do_cmd_relinput {
>     local($_) = @_;
>     local($rep,$file,$output,$oldrep);
>     (s/\s*(.*)\s*\n/$rep =$1;''/s) unless (
> 	(s/$next_pair_pr_rx/$rep=$2;''/eo)
> 	||(s/$next_pair_rx/$rep=$2;''/eo));
>     (s/\s*(.*)\s*\n/$file =$1;''/s) unless (
> 	(s/$next_pair_pr_rx/$file=$2;''/eo)
> 	||(s/$next_pair_rx/$file=$2;''/eo));
>     local($after) = $_;
>     $oldrep = $relinput_rep;
>     $relinput_rep = "$relinput_rep$dd$rep";
>     $file = &revert_to_raw_tex("\\input{$relinput_rep$dd$file}\n") if 
> $file;
>     if ($PREAMBLE) { &add_to_preamble('include',$file)}
>     elsif (!($file=~/^\s*$/)) {
> 	$output = &process_undefined_environment('center'
> 		, ++$global{'max_id'},"\\vbox{$file}");
>     }
>     $relinput_rep = $oldrep;
>     $output.$after;
> }
> Any idea?

If no other errors were reported, then I think you just
need to sort out the path to the files to be read within
this context.

Hard-coding   $relinput_rep = "..";
is not the most robust solution, since it'll be incompatible
with general settings for  $DESTDIR .

More robust would be something like:

   $relinput_rep = $RELINPUT_DIR||'..';

where, if necessary,  you can set  $RELINPUT_DIR
as a Perl variable in an initialization file.

> I've also got other questions: Can I add a custom directory with my own
> perl subroutines? Where can I find a documentation on how to add 
> personal
> subroutines to latex2html (I tried to read the code, but a clear
> documentation would be better)?

Initialization files are implemented for precisely this purpose.
See the   -init_file  <filename>  switch.
You can use as many of these as you like; they'll be read,
and their Perl coding interpreted, in the order in which
they occur on the command-line.

There is a lot of documentation on this in the LaTeX2HTML
chapter of the book:  The LaTeX Web Companion  (Addison-Wesley).

> Thanks for your help,
>  Prakash

Hopefully you'll be able to get your jobs working correctly now.

It's great to see someone willing to tackle the Perl coding
to get the job done.

Best regards,


> _______________________________________________
> 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                                  fax: +61 +2 9850 8114

More information about the latex2html mailing list