2

I am trying to create a systems of equation and I have the following:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{accents}
\usepackage[T1]{fontenc}
%Had to add the package above to enable ">" from appearing instead of upside down "?"
%Can also be written as "backslash greater than or less than depending on expression positioning"
\usepackage{mathtools}
%Allows me to format my systems of equations properly

Here, $L(\lambda) = \Pi_{1}^{n} (\lambda^{x_{i}}e^{-\lambda}/x_{i}!)$
 
$\ell(\lambda) = -n\lambda + \sum_{1}^{n} x_{i}Log\lambda$

$\ell ' (\lambda) = -n + (1/\lambda) \sum_{1}^{n}x_{i}$

$\ell ' (\lambda)$ = 
\begin{cases*}
    > 0, & for $\lambda  < \overline{X}_{n}$\\
    = 0,  & for $\lambda  = \overline{X}_{n}$\\
    < 0, & for $\lambda  > \overline{X}_{n}$
\end{cases*}

If anyone can point out my error. I apologize if this is dumb question. I am new to LaTeX.

6
  • cases is on math mode so you'll need either \text{for $\lambda < \overline{X}_{n}$} or lod the mathtools package and use cases* as it makes the second column into text. Additionally $\ell ' (\lambda)$ should be \ell ' (\lambda) and you should have some display math env around the whole thing like \begin{equation*}....\end{equation*}
    – daleif
    Commented Apr 22, 2021 at 16:50
  • 2
    Note that as a beginner it is a good idea to read some good introductory material like dickimaw-books.com/latex/novices , then it should be clear when to use $...$ and when not to.
    – daleif
    Commented Apr 22, 2021 at 16:52
  • I have changed it via using mathtools package and modifiying cases to cases*, but I am not getting an error in Package Amsmath. Additionally, shouldn't \lambda be in math mode? I will alos be sure to do some reading
    – PandaNinja
    Commented Apr 22, 2021 at 17:38
  • 1
    Please extend your example above to a full but minimal example including document class and preamble such that we know exactly what you're doing. At the moment we have to guess what you've done from your comments
    – daleif
    Commented Apr 22, 2021 at 17:59
  • 1
    That is why we ask for a minimal example. Note that your example is incomplete, I cannot copy that and test it as is. There is no begin/end document. Your commit in the code about > also suggest you haven't quite understood text vs math (as > is very seldomly used in the text). Also note my comment about using the equation* env, you need 5o learn the difference between math as part of the text and displayed math. Hence my suggestion that you read Nicolas book.
    – daleif
    Commented Apr 22, 2021 at 18:12

1 Answer 1

3

Always nice to hear that someone's looking to learn LaTeX to produce beautiful lecture notes! To help get you started, here's a somewhat cleaned-up version of your snippet above, with some comments and tips below:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{accents}
\usepackage[T1]{fontenc}
%Had to add the package above to enable ">" from appearing instead of upside down "?"
%Can also be written as "backslash greater than or less than depending on expression positioning"
\usepackage{mathtools} % Allows me to format my systems of equations properly
\begin{document} 
    Here,
        \begin{equation*}
            L(\lambda) = \prod_{i=1}^{n} \frac{ \lambda^{x_{i}} e^{-\lambda} }{ x_{i}! }
        \end{equation*}
    Taking logs,
        \begin{equation*}
            \ell(\lambda) = -n\lambda + \sum_{i=1}^{n} x_{i} \log\lambda
        \end{equation*}
    The derivative w.\,r.\,t. $\lambda$ is given by
        \begin{equation*}
            \ell' (\lambda) = -n + \frac{1}{\lambda} \sum_{i=1}^{n}x_{i}
        \end{equation*}
    We can thus see that
        \begin{equation*}
            \ell' (\lambda) 
            \begin{cases*}
                > 0, & for $\lambda  < \overline{X}_{n}$\\
                = 0,  & for $\lambda  = \overline{X}_{n}$\\
                < 0, & for $\lambda  > \overline{X}_{n}$
            \end{cases*}
        \end{equation*}
\end{document}

enter image description here

Now, as promised, some notes and tips.

  • First, a few words about modes: although the truth is a bit more complex, TeX (and thus LaTeX) basically has two fundamentally different modes, text mode and math mode. Math mode further comes in two flavors, one for inline mathematics and one for "display" math, i.e. for equations etc. that are separate from the running text. Many things will only work in one mode but not the other.

    Inline math is placed between single dollar signs ($ ... $), as in e.g. Euler's famous formula, $e^{i\pi} + 1 = 0$, is widely considered to be the most beautiful formula in mathematics. Display math is introduced using \[ ... \] in LaTeX (the use of double dollar signs, $$ ... $$, reaches down to LaTeX's underlying TeX core and should be be avoided; see enter link description here), or using a named environment such as equation (numbered), equation* (from amsmath, if I recall correctly; unnumbered), align, `align*, etc.

    To temporarily switch from math mode to text mode, use \text{...}. Some math-mode environments, like cases*, also do this automatically.

  • Speaking of environments: these are ubiquitious in LaTeX, and always take the form \begin{<name>} ... \end{<name>}. In fact, your entire document (after the preamble) is an example: it should be enclosed in a \begin{document} ... \end{document}. (And LaTeX will ignore anything and everything that comes after \end{document}, BTW.)

    As you can see, in the above code, I used \begin{equation*} ... \end{equation*} to produce equations that are separate from the running text (a personal choice, but I think it works better here), and $\lambda$ to have lambda appear (in math mode!)

  • For products in LaTeX, you should use the symbol \prod, which automatically places limits above/below the product sign in display math mode (and next to them in inline math mode), the same way that \sum does for sums. Don't use \Pi there, just like you wouldn't use \Sigma for sums.

  • Fractions are created using \frac{num}{dec}; I've used these for the likelihood function and the derivative of the log-likelihood in your example. Again, this is a matter of taste. (Fractions, like sums and products, will automatically appear somewhat smaller in inline vs. display math mode; to explicitly use either version, use \tfrac and \dfrac.)

  • "Named" functions like log should be typeset using an upright font; in fact LaTeX predefines quite a few, including \log, \exp \sin, \cos, \min, \max, \arg, \det etc. You'll also find \arg, \lim, \sup, \inf etc. useful.

    In fact, when you simply string letters together in math mode, LaTeX will typeset them in a manner appropriate for a product; so it's fine writing, say, the volume of a cuboid is given by $abc$, but if you have a variable with a name consisting of several letters, it's better to use \mathit{...}, e.g. \frac{ d\mathit{hours} }{ d\mathit{lwage} } or so.

    "it" stands for "italic" there, BTW, and this is a math mode-specific command; the text mode equivalent is \textit. You may find commands such as \mathbf and \textbf (bold-face) useful as well.

  • A minor note re: beautiful typesetting: there's many small things that will make a document more beautiful and more readable, and while I remain blissfully unaware of most of them, one little trick I have picked up is the use of a small horizontal space for abbreviations, such as "w.,r.,t." in the above example. \, is such a space: \: and \; are slightly larger. (The mnemonic is that a comma is smaller than a colon is smaller than a semicolon.)

That's all I have for you right now; I hope this'll help get you started. I second the suggestion made in the comments to read up on LaTeX and how to use it, but I also believe that the best thing you can do to learn it is to jump in, start writing, and find out how to solve the challenges you'll no doubt encounter (Google is your friend there, as is this site; and of course LaTeX comes with extensive documentation that you can access using the texdoc command).

3
  • Thank you so much for all the helpful tips. I will definitely use them as I progress. This is actually my first time writing my notes in Latex and it has already amazed me with how beautiful the formulas come out :D
    – PandaNinja
    Commented Apr 22, 2021 at 19:00
  • You're welcome --- best of luck and enjoy your journey! I'm no master myself, but having used LaTeX for a few years now I can definitely say it's worth the effort, even if the learning curve is steep at first.
    – chsk
    Commented Apr 22, 2021 at 19:42
  • 1
    @PandaNinja BTW, if this answer helped you, it'd be nice if you could accept it by clicking on the checkmark symbol.
    – chsk
    Commented May 3, 2021 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .