....I have a latex document which I need to publish as both pdf and html. I'm using pdflatex to generate the pdf and latex2html to generate the html.
I thought that doing something like this:
\ifx\pdfoutput\undefined
\newenvironment{code}{\begin{verbatim}}{\end{verbatim}}
\else
\newenvironment{code}{\begin{lstlisting}}{\end{lstlisting}}
\fi
and using \begin{code} and \end{code} would solve my problem, but it doesn't seem to. For now I'm just trying to get the pdf version working and I'm getting really unhelpful errors like this:
Runaway argument?
^^MErrorDocument 404 http://www.yourdomain.com.au/notfound.html^^M\en\ETC.
! File ended while scanning use of [EMAIL PROTECTED]
The runaway arg is because you cant use the verbatim environment inside a command or a new environment. Why? Because generally you can't use a \begin or \end which are environments themselves inside a new environment. Here is how you get around it. Use this:
\newenvironment{code}{\minipage{100mm}\verbatim}{\endverbatim\endminipage}}Doing the above with your code env will solve the problem for running latex but isnt a solution for the PDF as there is no equivalent command like \lstlisting and \endlstlisting.
However you might be able to use the \lstinputlisting and \verbatiminput commands instead if your code is in files. In which case this works fine. I have tested it and it produced PDF, DVI and latex2html on it creates HTML.
\documentclass{article}\usepackage[english]{babel}
\usepackage{verbatim}
\usepackage{listings}%\ifx\pdfoutput\undefined
% This works OK
%\newenvironment{mycode}{\minipage{100mm}\verbatim}{\endverbatim\endminipage}
%\else
% This does not work :-(
%\newenvironment{mycode}[1]{\minipage{100mm}\begin{lstlisting}}{\end{lstlisting}\endminipage}
%\fi\newcommand{\mycode}[1]{%
\ifx\pdfoutput\undefined%
\verbatiminput{#1}%
\else%
\lstinputlisting{#1}%
\fi%
}\begin{document}
\section*{Test Listing}
\lstset{language=Perl}\noindent Using the user defined command:
\mycode{testperl}\end{document}where the testperl file is:
#!/usr/bin/perl -w usage(0) if $#ARGV != 0; print "enter a number, q to quit.\n"; print "Finished\n";
Hope this will help. Mike
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
