4

error messageHere is my document and the problem:

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{float}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
 \graphicspath{ {./images/} }

\begin{document} \section{The Binomial Distribution}

If $X \sim Bin(n,p)$ where $p = \frac{1}{2}$, hence $q = 1 - \frac{1}{2} = \frac{1}{2}$, then

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1]{2}}^k \frac{1]{2}^{n-k}\ &= {n\choose k}{\frac{1]{2}}^n\ &= \frac{n\choose k}{2^n} \end{align}

Note that $2^n$ is constant for fixed $n$. Therefore, $P(X=k)$ has symmetry matching the symmetry of Pascal's Triangle. If $p < \frac{1}{2}$, the distribution is negatively skewed.

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1]{6}}^k \frac{5]{6}^{n-k}\ &= \frac{n\choose k 5^{n-k}}{6^n} \end{align} \end{document}

So there seems to be problems from \section{The Binomial Distribution} onwards. Before when I typeset, it kept saying there was a "missing $ inserted" and I played around with it, unfortunately messing it up so much that now it only has "Undefined control sequence \document class{amsart}" as the error message. Please help!

Follow up question

Here is my entire code (excluding information which I think isn't contributing to an error):

\documentclass{amsart}

\usepackage{amsmath} \usepackage{booktabs} \usepackage{float} \usepackage{graphicx} \usepackage[utf8]{inputenc} \usepackage{amssymb} \graphicspath{ {./images/} }

\begin{document}

  1. $\frac{(n\times p)!}{p!^n}$

\vspace{5mm}

  1. Want to borrow $1$ to $n$ books:\

There are $38$ numbers and only $26$ differences when maximised, so the ceiling function $\lceil \frac{38}{26} \rceil =2$.\ Therefore by PHP, there exists at least two numbers whose difference is at most $26$

\section{Statistics} \subsection{Averages from grouped data} \hfill\ \textbf{Estimating the mean:} An estimate for the mean can be obtained by assuming hat each of the raw data values takes the midpoint value of the interval in which it has been placed $$\text{Mean estimate} =\frac{\sum{fx}}{\sum{f}}$$

\subsection{Pareto Charts} \hfill\ The following table shows the 6 most common reasons for conditions failing their driving test.\ \hfill\

\begin{center} \begin{tabular}{@{}lll@{}} \toprule Reason & Percentage of conditions & Cumulative frequency \ \midrule Observations at junctions & 11.9 & 31 \ Use of mirrors & 8.2 & 52.4 \ Inappropriate speed & 5.1 & 65.7 \ Steering control & 4.7 & 77.9 \ Reversing around corner & 4.3 & 89.1 \ Incorrect positioning & 4.2 & 100 \ \bottomrule Total &38.4 \ \end{tabular} \end{center} \hfill \

\begin{figure}[H] \centering \includegraphics[scale=0.15]{paretochart1} \caption{Pareto chart} \label{default} \end{figure}

\newpage \textbf{Note:} \begin{itemize} \item The Cumulative frequency graph is concave down and monotone increasing \item Pareto Principle: 80% of consequences come from 20% of the causes \item Deciles: \begin{itemize} \item 0 - 10% 1st decile \item 10 - 20% 2nd decile \item $\vdots$ \item 90 - 100% 10th decile \end{itemize} \end{itemize}

\section{The Binomial Distribution}

If $X \sim Bin(n,p)$ where $p = \frac{1}{2}$, hence $q = 1 - \frac{1}{2} = \frac{1}{2}$, then

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1}{2}}^k \frac{1}{2}^{n-k}\ &= {n\choose k}{\frac{1}{2}}^n\ &= \frac{{n\choose k}}{2^n} \end{align}

Note that $2^n$ is constant for fixed $n$. Therefore, $P(X=k)$ has symmetry matching the symmetry of Pascal's Triangle. If $p < \frac{1}{2}$, the distribution is negatively skewed.

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1}{6}}^k \frac{5}{6}^{n-k}\ &= \frac{{n\choose k 5^{n-k}}}{6^n} \end{align}

Note that $5^{n-k}$ does affect the symmetry. If $k$ is small, probabilities to left of the mode are higher. If $k$ is large, probabilities to the right of the mode are lower.

\end{document}

user71207
  • 545
  • One problem is multiple instances of \frac{1] with mismatched delimiters – Steven B. Segletes Jun 18 '21 at 02:07
  • yikes thats horrifying. Ok I fixed them all. The error message is still "Undefined control sequence \document class{amsart}". I think I moved something and mismatched delimiters is no longer the main problem – user71207 Jun 18 '21 at 02:09
  • 1
    Are you accidentally compiling with pdftex, instead of pdflatex? – Steven B. Segletes Jun 18 '21 at 02:18
  • how can I tell? – user71207 Jun 18 '21 at 02:18
  • 1
    YES indeed the error log says pdftex. How can I change it back to pdflatex? I may have accidentally changed it somehow. – user71207 Jun 18 '21 at 02:19
  • Sorry - all of my other documents are being compiled in pdftex as well and they work fine. I didn't change anything – user71207 Jun 18 '21 at 02:20
  • Well, I don't use TeXLive, but my MikTeX identifies as This is pdfTeX, Version 3.141592653-2.6-1.40.22 (MiKTeX 21.3) (preloaded format=pdflatex 2021.5.31), which is definitely different than format=pdftex. – Steven B. Segletes Jun 18 '21 at 02:21
  • I am so sorry for the confusion - you are indeed correct. See the error message i included? it does say format=pdftex. How do I fix this? – user71207 Jun 18 '21 at 02:25
  • I don't use TeXLive to advise. In the MikTeX editor (Texworks), there is a pull-down menu in the upper left where such things are set, right next to compile button. – Steven B. Segletes Jun 18 '21 at 02:27
  • Thank you, my problem is solved. I changed it back. Why does format= pdftex NOT typeset properly? – user71207 Jun 18 '21 at 03:10
  • 1
    dont use \choose in latex use \binom{n}{m} – David Carlisle Jun 18 '21 at 06:06
  • 1
    Off-topic: The claim that "If p < 0.5, the [Binomial] distribution is negatively skewed" is false. In fact, the exact opposite is true. – Mico Jun 18 '21 at 06:57
  • 2
    pdftex does typeset properly if you process a plain tex document. The syntax of plain tex is different, ( a \choose b is plain syntax that should not be used in laetx for example) so it's like asking why an English spell checker doesn't work properly on a German text. – David Carlisle Jun 18 '21 at 07:04
  • 1
    never use \\ at the end of a paragraph, you do get warnings about badness 10000 (ie as bad as possible) from 2. Want to borrow $1$ to $n$ books:\\ – David Carlisle Jun 18 '21 at 07:29
  • 1
    @Mico yeah sorry a typo - it should be positively skewed – user71207 Jun 18 '21 at 09:33
  • "never use \ at the end of a paragraph, you do get warnings about badness 10000 (ie as bad as possible) from 2. Want to borrow $1$ to $n$ books:\" @DavidCarlisle can you please expand on its point? I'm not sure what you mean. – user71207 Jun 18 '21 at 09:34
  • Ok I didnt know that. Well then why is it just so that \choose works in latex AND tex? Is it actually "bad" , or just a nit picky thing? (to use \binom over \choose) – user71207 Jun 18 '21 at 09:36
  • @user never ignore warnings, see the warning you get from this example (I copied it under Steven's answer) – David Carlisle Jun 18 '21 at 09:37
  • 1
    My earlier comment was about the three warnings that you get from the above Underfull \hbox (badness 10000) in paragraph at lines 33--36 badness is tex's internal check on the quality of the output and 10000 is the maximum value so tex is telling you it is giving up and the output will be bad. see https://tex.stackexchange.com/a/334249/1090 – David Carlisle Jun 18 '21 at 09:40
  • 2
    tex is a macro expansion language so higher level languages like latex can not hide lower level constructs there is no compilation step or internal function definitions as with compiled languages, so every lower level contruct is accessible, it just shouldn't be used. – David Carlisle Jun 18 '21 at 09:41

3 Answers3

4

There were two issues: One problem is multiple instances of \frac{1] with mismatched delimiters, and syntax like \frac{n\choose k}{2^n}. Apparently it needs an extra set of braces to unconfuse it.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{float}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
% \graphicspath{ {./images/} }

\begin{document} \section{The Binomial Distribution}

If $X \sim Bin(n,p)$ where $p = \frac{1}{2}$, hence $q = 1 - \frac{1}{2} = \frac{1}{2}$, then

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1}{2}}^k \frac{1}{2}^{n-k}\ &= {n\choose k}{\frac{1}{2}}^n\ &= \frac{{n\choose k}}{2^n} \end{align}

Note that $2^n$ is constant for fixed $n$. Therefore, $P(X=k)$ has symmetry matching the symmetry of Pascal's Triangle. If $p < \frac{1}{2}$, the distribution is negatively skewed.

\begin{align} P(X=k) &= {n\choose k}p^k q^{n-k}\ &= {n\choose k}{\frac{1}{6}}^k \frac{5}{6}^{n-k}\ &= \frac{{n\choose k 5^{n-k}}}{6^n} \end{align} \end{document}

enter image description here

  • Thanks for this, but the error message is still "Undefined control sequence \document class{amsart}". I think I moved something and mismatched delimiters is no longer the main problem – user71207 Jun 18 '21 at 02:09
  • Ill add a photo in my post – user71207 Jun 18 '21 at 02:10
  • I confirm it works on a fresh document. Therefore there is something else in my document that is wrong. What should I do know? Do I include my entire code? – user71207 Jun 18 '21 at 02:12
  • If I misunderstood the question, then clarifying the question can be helpful on your part. However, if you misunderstood the problem and I properly answered the misunderstood question, then it is generally poor form to revise the question in such a way that makes existing answers obsolete. Best to ask a new question in such a case. – Steven B. Segletes Jun 18 '21 at 02:16
  • I will update my question, marking a clear follow up question – user71207 Jun 18 '21 at 02:22
  • 1
    Package amsmath Warning: Foreign command \atopwithdelims; (amsmath) \frac or \genfrac should be used instead (amsmath) on input line 21. ie use \binom{a}{b} not {{a \choose b}} – David Carlisle Jun 18 '21 at 07:06
3

(This answer addresses the OP's follow-up question, not the question that was posted initially.)

Some general observations about your code:

  • In LaTeX documents, one should not use {n \choose k} or {1 \over 2} infix-style notation. Period. Instead, use \binom{n}{k} and \frac{1}{2}, respectively. For more on this subject, see What is the difference between \over and \frac?

  • In LaTeX documents, don't use $$ to initiate and terminate display-math mode. Instead, use \[ and \]. For a detailed discussion, please see Why is \[ ... \] preferable to $$ ... $$?

  • There's an overabundance of visual formatting directives in your code. For the most part, they don't cause errors, but they're often redundant and create a lot of code clutter. E.g., most of the \hfill\\ directives could be replaced with simple blank lines. Likewise, most of the \\ line terminators in running text can and should be dropped.

  • Notation such as {\frac{1}{2}}^k is not conducive to good typography. For one, the curly braces around \frac{1}{2} are redundant. Second, and more importantly, there's very little visual difference between \frac{1}{2}^k and \frac{1^k}{2}. Since the latter impression should obviously be avoided at nearly all cost, please start to write (in a display-math context) \biggl(\frac{1}{2}\biggr)^{\!k}. Your readers will very much appreciate it.

  • Don't create paragraph breaks right before display-math material.

  • Do please give your readers a (visual) break by replacing diminutive-looking constructs such as \frac{{n\choose k}}{2^n} and \frac{\binom{n}{k 5^{n-k}}}{6^n} with much more reader-friendly alternatives such as \binom{n}{k}2^{-n} and \frac{\binom{n}{k 5^{n-k}}}{6^n}. Try it!


Addendum to address the OP's follow-up question, about why I called \frac{{n\choose k}}{2^n} "diminutive looking" and why I suggested using \binom{n}{k}2^{-n} instead. After all, aren't they the same mathematically? Of course they are the same mathematically; however, they're they're not at all the same typographically. TeX and LaTeX are typographic tools, so use them well to maximize the readability of what you're writing.

enter image description here

\documentclass{article}
\usepackage{amsmath} % for \binom macro
\begin{document}
\[
\frac{{n\choose k}}{2^n} \quad\text{vs.}\quad  \binom{n}{k}2^{-n}
\]
\end{document}
Mico
  • 506,678
  • Thank you so much! This information is very valuable to me. I'm the only person in my class who uses LaTeX so I don't get any support except from the few "tutorial LaTeX" booklets that I read – user71207 Jun 18 '21 at 09:37
  • One question: what does " diminutive-looking constructs" mean? They are the same mathematical expression – user71207 Jun 18 '21 at 09:40
  • @user71207 - Please see the addendum I posted to further explain why I called one of the terms in your code "diminutive looking". Just because two typographic expressions have the same mathematical meaning doesn't mean that their readability and legibility is the same as well. – Mico Jun 18 '21 at 10:04
  • Thank you for the insight. Not going to lie, but I find both equally readable. What makes the second more preferable? Actually I think I prefer this over both: $$\frac{1}{2^n}\binom{n}{k}$$ – user71207 Jun 21 '21 at 13:03
1

If you are using format=pdftex then don't use LaTeX's constructions in your document, i.e. don't use any macros like \documentclass, \usepackage, \begin{document} etc. Use simply plain TeX. It is much more simple than usage of LaTeX.

wipet
  • 74,238
  • I didnn't even know TeX was a thing. Should I be using that instead of LaTeX? Where can I find a tutorial for TeX? I'm just interested in seeing how that commands may differ from LaTx – user71207 Jun 18 '21 at 09:38
  • 1
    A short summary about TeX is in http://mirrors.ctan.org/info/tex-nutshell/tex-nutshell.pdf for example. – wipet Jun 18 '21 at 11:35