Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

LyX is giving a lot of error messages for my Latex code which runs in other places.

\[
\begin{array}{rl}
p_{Y \mid H_1}(y \mid H_1) & = f_X(g^{-1}(y))\left| \dfrac{dg^{-1}(y)}{dy} \right| \\ \\
& = \begin{cases} y>0 & : & f_X(\ln(y))\left| \dfrac{d \ln(y)}{dy} \right| = \dfrac{f_X(\ln(y))}{y} \\
\text{otherwise} & : & 0
\end{cases}
\end{array}
\]

LyX says:

Extra alignment tabs changed to \cr.
 & = \begin{cases} y>0 & : &
                                  f_X(\ln(y))\left| \dfrac{d \ln(y)}{dy} \ri...
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.

However the exact code works perfectly in the SE Mathematics domain to give this output:

should have been like this

What does LyX not like in my code?

share|improve this question
2  
The difference is that Lyx uses TeX to do the typesetting and MathJax as used on the math site does not. –  David Carlisle Mar 25 '13 at 23:44
add comment

2 Answers

up vote 12 down vote accepted

Here's a solution which (a) uses the align* environment instead of the array environment and (b) inverts the order of the arguments inside the cases environment (as I believe that this may be closer to general usage of this environment). It also defines a macro called \abs to simplify typesetting in the body of the example.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\abs}[1]{\left|#1\right|}
\begin{document}
\begin{align*}
p_{Y \mid H_1}(y \mid H_1) 
&= f_X(g^{-1}(y)) \abs{ \dfrac{dg^{-1}(y)}{dy} } \\ 
&= \begin{cases}
      f_X(\ln(y)) \abs{ \dfrac{d \ln(y)}{dy} } = \dfrac{f_X(\ln(y))}{y} & \text{if $y>0$}\\
      0 & \text{otherwise}
   \end{cases}
\end{align*}
\end{document}

If you want to state the condition part before the result part in the cases environment, you could write it as:

   \begin{cases}
      \text{if $y>0$} &:\  
        f_X(\ln(y)) \abs{ \dfrac{d \ln(y)}{dy} } = \dfrac{f_X(\ln(y))}{y}\\
      \text{otherwise} &:\ 0  
   \end{cases}

leading to the following result:

enter image description here

share|improve this answer
add comment

cases only takes one alignment point (that is, it is a two column table) and you have used two on each row. Deleting the extra ones makes it work. Please in future always post complete documents showing all relevant packages (amsmath here).

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

\[
\begin{array}{rl}
p_{Y \mid H_1}(y \mid H_1) & = f_X(g^{-1}(y))\left| \dfrac{dg^{-1}(y)}{dy} \right| \\ \\
& = \begin{cases} y>0  : & f_X(\ln(y))\left| \dfrac{d \ln(y)}{dy} \right| = \dfrac{f_X(\ln(y))}{y} \\
\text{otherwise}  : & 0
\end{cases}
\end{array}
\]

\end{document}

While this works it is misusing array (which intended for matrices not as an aligned display) You would be better to use the ams alignments such as align.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.