[tex4ht] is it possible to define a Latex environment, where one can issue direct HTML code in it for tex4ht only?

Michal Hoftich michal.h21 at gmail.com
Fri Jun 10 10:53:32 CEST 2016


""Nasser,

this is of course typical example of case when you should put your
macros to .sty file and redefinitions for tex4ht into .4ht file.

mycode.sty:
%%%%%%%%%%%%
\ProvidesPackage{mycode}

\RequirePackage{listings}
  \lstnewenvironment{code}
  {\lstset{language=matlab}}
  {}

\endinput

%%%%%%%%%%%%

tex4ht configurations in mycode.4ht:
%%%%%%%%%%%%
\ScriptEnv{code}
{\ifvmode\IgnorePar\fi\EndP\NoFonts\hfill\break\HCode{<pre>\Hnewline}}
{\HCode{</pre>}\EndNoFonts\endgraf}
\endinput

%%%%%%%%%%%%

and the modified TeX file:

%%%%%%%%%%%%
\documentclass[12pt]{book}%
\usepackage[T1]{fontenc}
\usepackage{fancyvrb}
\usepackage{mycode}

\begin{document}
some text
\begin{code}
X=10;
y=5;
\end{code}
another text
\end{document}

%%%%%%%%%%%%

tex4ht definitions are little bit more involved, in order to handle
the paragraphs correctly ("\ifvmode\IgnorePar\fi\EndP" and "\endgraf),
it contains also some minimal HTML insertions. There is no need to
define other environments, \ScriptEnv can be used to handle existing
environment and it can also be used to insert any HTML code.

Best regards,
Michal


More information about the tex4ht mailing list