<div dir="ltr"><div class="gmail_default" style="color:rgb(51,102,255)">Hi Nasser,</div><div class="gmail_default" style="color:rgb(51,102,255)">Will this work for you:</div><div class="gmail_default" style="color:rgb(51,102,255)"><br></div><div class="gmail_default"><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\documentclass[12pt]{book}%</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\usepackage[T1]{fontenc}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\usepackage{listings}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">%\usepackage{fancyvrb}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\usepackage{moreverb}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\def\putVerb{%</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \HCode{<PRE>}%</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \verbatiminput{a.tex}%</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \HCode{</PRE>}%</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\ifdefined\HCode</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \newenvironment{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> {\verbatimwrite{a.tex}}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> {\endverbatimwrite</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \aftergroup\putVerb}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\else</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> \lstnewenvironment{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> {\lstset{language=matlab}}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"> {}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\fi</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace"><span style="color:rgb(51,102,255)">\begin{document}</span><br></font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\begin{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">X=10;</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">Y=10;</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\end{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">or</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\begin{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">X=100;</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">Y=200;</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\end{code}</font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace"><br></font></div><div class="gmail_default"><font color="#3366ff" face="monospace, monospace">\end{document}</font></div><div class="gmail_default"><font color="#3366ff"><br></font></div><div class="gmail_default"><font color="#3366ff">Regards</font></div><div class="gmail_default"><font color="#3366ff">Jagath</font></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 10 June 2016 at 11:53, Jagath AR <span dir="ltr"><<a href="mailto:jagathar@gmail.com" target="_blank">jagathar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="color:rgb(51,102,255)">Hi Nasser,</div><div class="gmail_default" style="color:rgb(51,102,255)">The error in your MWE case is due to undefined "\PRE" command, which should be "/PRE".</div><div class="gmail_default" style="color:rgb(51,102,255)"><br></div><div class="gmail_default" style="color:rgb(51,102,255)">Regards</div><span class="HOEnZb"><font color="#888888"><div class="gmail_default" style="color:rgb(51,102,255)">Jagath</div></font></span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 10 June 2016 at 11:41, Nasser M. Abbasi <span dir="ltr"><<a href="mailto:nma@12000.org" target="_blank">nma@12000.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am struggling with this. I need to be able to define<br>
an environment, where when Latex file is compiled to HTML<br>
does one thing, and when compiled to pdf does another thing.<br>
<br>
This sounds easy enough. The problem is it is for code<br>
listing. For pdf, I can use listing package no problem.<br>
<br>
For HTML, I'd like to use special HTML code to make<br>
the code more customized for HTML. The problem is<br>
that one can't define an environment for verbatim<br>
or listing content. So I am stuck. Here is a small<br>
example which shows what I mean:<br>
<br>
--------------------------<br>
\documentclass[12pt]{book}%<br>
\usepackage[T1]{fontenc}<br>
\usepackage{listings}<br>
\usepackage{fancyvrb}<br>
<br>
\ifdefined\HCode<br>
\newenvironment{code}<br>
{\HCode{<PRE>}}<br>
{\HCode{<\PRE>}}<br>
\else<br>
\lstnewenvironment{code}<br>
{\lstset{language=matlab}}<br>
{}<br>
\fi<br>
\begin{document}<br>
\begin{code}<br>
X=10;<br>
\end{code}<br>
\end{document}<br>
-----------------------------<br>
<br>
The above compiled ok to pdf, but ofcourse it gives<br>
error with tex4ht<br>
<br>
-----------------------<br>
(/usr/local/texlive/2015/texmf-dist/tex/generic/tex4ht/html4-math.4ht))<br>
(./foo2.aux)<br>
! Undefined control sequence.<br>
<argument> <\PRE<br>
><br>
l.19 \end{code}<br>
?<br>
---------------------------<br>
<br>
I used PRE above just an example. If I can this method<br>
to work, I wanted to use more complicate HTML code<br>
there for the start of the environment, which uses<br>
outside javascript library for code formatting, much<br>
nicer than what I can get from standard listings.<br>
<br>
Listings works ok for both html and pdf. I just wanted<br>
to use direct HTML environment for the code listing<br>
when compiling with tex4ht.<br>
<br>
I could of course duplicate the code itself, and use<br>
<br>
\ifdefined\HCode<br>
\ScriptEnv{html}<br>
{\NoFonts\hfill\break}<br>
{\EndNoFonts}<br>
\begin{html}<br>
my code here<br>
\end{html}<br>
\else<br>
\begin{lstlisting}<br>
code here<br>
\end{lstlisting}<br>
\fi<br>
<br>
But I am trying to avoid this.<br>
<br>
If some one has any idea how to do this, that will be great.<br>
<br>
I asked on this also at<br>
<br>
<a href="http://tex.stackexchange.com/questions/313994/defining-alternative-environment-for-code-listing-for-tex4ht-without-code-duplic" rel="noreferrer" target="_blank">http://tex.stackexchange.com/questions/313994/defining-alternative-environment-for-code-listing-for-tex4ht-without-code-duplic</a><br>
<br>
Thank you,<br>
--Nasser<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>