# how to use conditional to define different \begin and \end environment at compile time

I just need little help on the syntax for this. I am using tex4ht, and I get an error when I use empheq for the align environment.

I want to build this TeX file both in pdflatex and htlatex. I normally use \ifdefined\HCode to conditionally compile things. But in this case, it is not working.

I need to conditionally use empheq or not depending if compiling with tex4ht or not.

Here is MWE

\documentclass{article}
\usepackage{empheq}
\begin{document}

\ifdefined\HCode
\begin{align*}
\else
\begin{empheq}[box=\fbox]{align*}
\fi
%
\lambda_{spiral}  &  =-0.0551\\
\lambda_{rolling}  &  =-56.5025
%
\ifdefined\HCode
\end{align*}
\else
\end{empheq}
\fi

\end{document}


I am trying to avoid duplicating all the equations in both environments. This below would works

\documentclass{article}
\usepackage{empheq}
\begin{document}

\ifdefined\HCode
%
\begin{align*}
\lambda_{spiral}  &  =-0.0551\\
\lambda_{rolling}  &  =-56.5025
\end{align*}
%
\else
%
\begin{empheq}[box=\fbox]{align*}
\lambda_{spiral}  &  =-0.0551\\
\lambda_{rolling}  &  =-56.5025
\end{empheq}
%
\fi

\end{document}


I think one is not supposed to break the environment with conditional like the first case above? May be due to how LaTeX parses the code? I'm using TeX Live 2013.

• Haven't tested this but you could try: \ifdefined\HCode \renewenvironemnt{empheq}{\begin{align*}}{\end{align*}} \fi, and just use the empheq environment. Apr 1 '14 at 1:51

Grab the contents of the conditional environment using environ:

\documentclass{article}
\usepackage{empheq,environ}
\NewEnviron{pdfORht}[3][]{%
\ifdefined\HCode %htlatex
\begin{#3}
\BODY
\end{#3}
\else% pdflatex
\begin{#2}[#1]{#3}
\BODY
\end{#2}
\fi%
}
\begin{document}

\begin{pdfORht}[box=\fbox]{empheq}{align*}
\lambda_{spiral}  &  =-0.0551 \\
\lambda_{rolling}  &  =-56.5025
\end{pdfORht}

\end{document}


Of course, you can fiddle with the interface yourself.