# Can't use \left. … \right| in a custom environment

I'm writing a Hebrew (RTL) document with equations and I compile it with xelatex. The equation numbers are wrong and I have found that placing \LTR tag before the equation fix this. I have created an environment that with it but something is amiss. When I try to compile this for example:

\documentclass[11pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{xltxtra}
\usepackage{bidi}
\setmainfont{Arial}
\tolerance=1000
\newenvironment{ltreq}[1]{
\LTR
$${1}} {$$
\RTL}

\begin{document}
\RTL

\begin{ltreq}
\left . \frac{\partial f}{\partial y} \eta \right |_{x_1}^{x_2} -\int_{x_1}^{x_2} \frac{\partial f}{\partial y'} \eta dx
\end{ltreq}
\RTL

\end{document}


I get this error:

l.22 ...frac{\partial f}{\partial y} \eta \right |
_{x_1}^{x_2} -\int_{x_1}^{...


I guess that my approach was to naive there. How can I achieve this?

-
Side note: you should use \right\rvert instead of \right|. –  Jubobs Apr 3 '13 at 13:28

You specified that the ltreq environment has one argument, so it is swallowing the \left in the beginning of the equation. If you remove the [1] from the definition it works:

\documentclass[11pt]{article}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{xltxtra}
\usepackage{bidi}
\setmainfont{Arial}
\tolerance=1000
\newenvironment{ltreq}{
\LTR
$$} {$$
\RTL}

\begin{document}
\RTL

\begin{ltreq}
\left . \frac{\partial f}{\partial y} \eta \right |_{x_1}^{x_2} -\int_{x_1}^{x_2} \frac{\partial f}{\partial y'} \eta dx
\end{ltreq}
\RTL

\end{document}

-
Thanks. As a followup question. If I try to pull the same trick with align environment. Latex fail because \begin{align} on input line 304 ended by \end{ltral} Do you have any clue about this? –  Yotam Apr 3 '13 at 13:34
@Yotam No, I don't :) You should very much post that as a separate question though. –  marczellm Apr 3 '13 at 14:33
\LTR is group local AFAIK, so you could just do \newenvironment{ltreq$$}{$$\begingroup\LTR$$}{$$\endgroup‌​} –  kahen Apr 3 '13 at 16:47