On 6/8/2016 4:58 AM, Michal Hoftich wrote:
Follow-up Comment #1, bug #309 (project tex4ht):

Savetrees package redefines lot of internal LaTeX commands, so it is no
surprise that it crashes tex4ht. As the changes it does aren't useful in
conversion to HTML, an easy solution is to use conditional inclusion.

Another possibility I've just found is to block the loading of the package
from tex4ht. It seems that it is possible to call an action at \usepackage
call, tex4ht has list of packages which request it. It is possible to add a
package to this list in tex4ht-4ht.tex:

\<use package\><<<
savetrees,>>>

\<add to usepackage\><<<
\def\:temp{savetrees}\ifx \@currname\:temp
% code to be executed
\fi


these configurations are added to usepackage.4ht, which is included every time
\usepackage command is used. Now we need to block package loading.

I've found nice macro:

% http://tex.stackexchange.com/a/39418/2891
\newcommand{\dontusepackage}[2][]{%
  \@namedef{ver@#2.sty}{9999/12/31}%
  \@namedef{opt@#2.sty}{#1}}

the problem is, it needs to be called with the same package options as
\usepackage in the document, otherwise we would get option clash error
message. I've took a look at the LaTeX and tex4ht.sty sources and it seems
that the options aren't saved in any macro. In fact, I've found following
definition in tex4ht.sty:

 \let\:onefilewithoptions\@onefilewithoptions
 \def\@onefilewithoptions#1[{%
   \let\:temp\@reset@ptions
   \def\@reset@ptions{%
      \let\@reset@ptions\:temp
      \edef\TivhTcats{%
   \catcode`:=\the\catcode`:%
   \catcode`@=\the\catcode`@}%
\catcode`\:=11 \catcode`\@=11
\a:usepackage
\TivhTcats
}%
\:onefilewithoptions#1[}

The original \@onefilewithoptions has following parameters

\def\@onefilewithoptions#1[#2][#3]#4{%

where the second argument are package options. We can change the tex4ht
redefinition slightly:


 \let\:onefilewithoptions\@onefilewithoptions
 \def\@onefilewithoptions#1[#2]{%
   \let\:temp\@reset@ptions
   \def\@reset@ptions{%
      \let\@reset@ptions\:temp
      \edef\TivhTcats{%
   \catcode`:=\the\catcode`:%
   \catcode`@=\the\catcode`@}%
\catcode`\:=11 \catcode`\@=11
\def\:currentoptions{#2}
\a:usepackage
\TivhTcats
}%
\:onefilewithoptions#1[#2]}


as you can see, new macro is defined, holding package options. We can then
define macro for blocking package loading like:

\newcommand{\:dontusepackage}[2][\:currentoptions]{%
  \@namedef{ver@#2.sty}{9999/12/31}%
  \@namedef{opt@#2.sty}{#1}
}

What do you think? Is that change safe?


hi Michal;

The above code is way over my head myself, but is the idea
for tex4ht to block loading the package and also issue an
error at same time and stop the compilation, so that the user
can correct it? Or the idea is to silently block loading a
package and go on with the compilation?

--Nasser


Reply via email to