多个编译错误:缺少 $ 插入

多个编译错误:缺少 $ 插入

我是 Latex 的初学者,所以如果我的格式不好,请原谅。每当我编译时,我都会收到多个编译错误:

Missing $ inserted ans Extra } or forgotten endgroup. 

我仔细研究了代码,删除和替换了$所有}地方,但仍然出现相同的错误。但是,它仍然可以编译并转换为格式正确的 PDF。有人能解释一下吗?

\documentclass[11pt]{article}

\usepackage{fullpage} 
\usepackage{amsmath}  
\usepackage{amssymb}  
\usepackage{amsthm}   
\usepackage{comment}  
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{lipsum}

\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref} 

\usepackage{lipsum}

\makeatletter
\renewcommand{\maketitle}{\bgroup\setlength{\parindent}{0pt}
\begin{flushleft}
  \@title

  \@author
\end{flushleft}\egroup
}
\makeatother

\title{}
\date{}
\author{%
Name \\
Due \\
ID\\
}

\pagestyle{empty} % disables page numbers

\begin{document}

\maketitle

\centerline{\sc \large Homework 1 in \LaTeX\ }

\vspace{2pc}

\thispagestyle{empty}

\begin{flushleft}
\textbf{Exercise 1} 

\vspace{1pc}

\par \textit{A ball and a bat cost \$1.10 (total). The bat costs \$1.0 more than the ball. How much does the ball cost?}\par
    \setlength{\parindent}{10ex} 
    Let the price of the bat = $x$ \hfill $x$ + $y$ = 1.10

    Let the price of the ball = $y$ \hfill $x$ = $y$ + 1.0

                                    \hfill ($y$ + 1) + $y$ = 1.10

                                    \hfill 2$y$ = .10

                                    \hfill $y$ = .05

                                    \hfill $x$ + .05 = 1.10

                                    \hfill $x$ = \$1.05

    Therefore the ball cost \$0.05 and the the bat cost \$1.0 

\vspace{1pc}    

\noindent\textbf{Exercise 2} 

\vspace{1pc}

\noindent\textit{Prove the following statements:}\par
    \indent\textit{a)   The sum of any three consecutive even numbers is always a multiple of 6}\par

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
    $N1$ = $2q$ 

    $N2$ = $2q$ + 2 

    $N3$ = $2q$ + 4

    $S$ = $N1$+$N2$+$N3$

    By hypothesis $S$ = $2q+(2q+2)+(2q+4$) = $6q+6$

    $S$ = $N1$+$N2$+$N3$ = $6(q+1)$

    \indent\textit{b)   The product of any three consecutive even numbers is always a multiple of 8}\par

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
    $N1$ = $2q$ 

    $N2$ = $2q$ + 2 

    $N3$ = $2q$ + 4

    $S$ = $N1$\times$N2$\times$N3$
                    = $2q(4q^{2}+16q+8)$

                    = $8q^{3}+32q^{2}+16q$

                    = $8q(q^{2}+4q+2)$ 

\indent\textit{c)   Prove that if you add the squares of three consecutive integer numbers and then subtract two, you always get a multiple of 3.}\par

    \vspace{4pc}

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
    $N1$ = ($2q$)^{2} 

    $N2$ = ($2q + 2$)^{2} 

    $N3$ = ($2q + 4$)^{2} 

    $S = N1 + N2 + N3$

By hypothesis $S = ((2q)^{2} + (2q+2)^{2} + (2q+4)^{2})-2 

                    = (4q^{2}+(4q^{2}+8q+4)+(4q^{2}+16q+16))-2

                    = (12q^{2}+24q+20)-2

                    = 12q^{2}+24q+18

                    = 3(4q^{2}+8q+6)$

    \noindent If N1= 2, N2=4, N3=6

    $S$ = ((2)^{2}+(4)^{2}+(6)^2)-2 = (56)-2 = 54 = 3\times 18\par
    \noindent If N1 = 4, N2 = 6, N3 = 8

    $S$ = ((4)^{2}+(6)^{2}+(8)^2)-2 = (116)-2 = 114 = 3\times 38

\vspace{1pc}    

\noindent\textbf{Exercise 3} 

\vspace{1pc}

\noindent\textit{Based on the final number obtained, Roger can then “guess” the initial number. Show that there is no magic in this. Justify your answer.} \par
    \setlength{\parindent}{10ex} 
    Let $x$ be the random integer: \hfill $2x$

                                   \hfill $2x$ + 5

                                   \hfill (2$x$ + 5)^{2}

                                   \hfill (4$x$^{2}+20$x$+25)-25

                                   \hfill (4$x$^{2}+20$x$) \div 4

    Roger can simply asubtract 5 from the final number and\hfill ($x^{2}$+5$x$) \div x

    he will be able to guess the integer.  \hfill $x$ + 5

\vspace{1pc}    

\noindent\textbf{Exercise 4} 

\vspace{1pc}

\noindent\textit{Prove the following identities, where $p, q, x, m,$ and $n$ are real numbers:} \par
    \noindent\textit{a) $8(p-q)+3(p+q)=2(p+2q)+9(p-q)$}\par
    \noindent Let the LHS = $8(p-q)+3(p+q)$

    \setlength{\parindent}{13ex}  = $8p-8q+3p+3q = 11p - 5q$ 

    \noindent Let the RHS = $2(p+2q)+9(p-q)$

    \setlength{\parindent}{13ex}  = $2p+4q+9p-9q = 11p - 5q$ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{b) $ x(m+n)+y(n-m)=m(x-y)+n(x+y)$}\par

    \noindent Let the LHS = $x(m+n)+y(n-m)$

    \setlength{\parindent}{13ex}  = $ xm + xn +yn -ym $ 

    \noindent Let the RHS = $m(x-y)+n(x+y)$

    \setlength{\parindent}{13ex}  = $xm - ym + xn + yn = xm +xn + yn - ym $ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{c) $(x+2)(x+10)-(x-5)(x-4)=21x$}\par

    \noindent Let the LHS = $(x+2)(x+10) - (x-5)(x-4)$

    \setlength{\parindent}{13ex}  = $ (x^{2}+12x+20) - (x^{2}-9x+20)$ 

                                  = $21x $ 

    \noindent Let the RHS = $21x$ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{d) $m^{4}-1=(m^{2+}1)(m^{2}-1)$}\par

    \noindent Let the LHS = $m^{4}-1$

    \noindent Let the RHS = $(m^{2}+1)(m^{2}-1)$ 
                          = $m^{4} -1 $\hfill Therefore $LHS = RHS$

\vspace{2pc}    

\noindent\textbf{Extra Credit} 

\vspace{1pc}

\par If the 1 minute person goes across with the two minute person that would be 2 min gone. The one minute person then goes back to the ten \& five minute persons while the two minute person is already on the other side, 3 minutes will have elapsed.Once back on the starting side, the one minute person gives the ten minute person and the five minute person the flashlight, they cross to the other side with 13 minutes goneby. If the ten \& five minute person give the two minute person the flashlight, the two minute person can go back across the bridge to retrieve the one minute person and this will cost another 2 minutes so 15 minutes will have elapsed. The two minute person then crosses to the other side with the one minute person, they will both take another 2 minutes and all will have crossed in 17 minutes.


\end{flushleft}     

\end{document}

答案1

我已编译了您的文档,主要问题在于您似乎认为在数学公式中,只有变量必须括在一对 $ 之间$ … $。例如:(2$x$ + 5)^{2}而不是$(2x+5)^2$

虽然某些符号可以在文本模式下被理解,例如+(间距不好),但大多数符号只有在数学模式下才能被编译器理解。

此外,整个文档中的大部分格式设置都是手动完成的,这是非常糟糕的做法:LaTeX 是markup一种语言,所有格式设置都应该通过序言、包和类文件完成。你应该阅读一些初学者文档。

您可能会对该包裹exsheets感兴趣。

这是可编译的代码:

\documentclass[11pt]{article}

\usepackage{fullpage}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{comment}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{lipsum}

\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref}

\usepackage{lipsum}

\makeatletter
\renewcommand{\maketitle}{\bgroup\setlength{\parindent}{0pt}
\begin{flushleft}
  \@title

  \@author
\end{flushleft}\egroup
}
\makeatother

\title{}
\date{}
\author{%
Name \\
Due \\
ID\\
}

\pagestyle{empty} % disables page numbers

\begin{document}

\maketitle

\centerline{\sc \large Homework 1 in \LaTeX\ }

\vspace{2pc}

\thispagestyle{empty}

\begin{flushleft}
\textbf{Exercise 1}

\vspace{1pc}

\par \textit{A ball and a bat cost \$\,1.10 (total). The bat costs \$\,1.0 more than the ball. How much does the ball cost?}\par
    \setlength{\parindent}{10ex}
    Let the price of the bat = $x$ \hfill $x$ + $y$ = 1.10

    Let the price of the ball = $y$ \hfill $x$ = $y$ + 1.0

                                    \hfill ($y$ + 1) + $y$ = 1.10

                                    \hfill 2$y$ = .10

                                    \hfill $y = .05$

                                    \hfill $x$ + .05 = 1.10

                                    \hfill $x$ = \$\,1.05

    Therefore the ball cost \$\,0.05 and the the bat cost \$\,1.0

\vspace{1pc}

\noindent\textbf{Exercise 2}

\vspace{1pc}

\noindent\textit{Prove the following statements:}\par
    \indent\textit{a) The sum of any three consecutive even numbers is always a multiple of 6}\par

 \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
 $N1$ = $2q$

 $N2$ = $2q$ + 2

 $N3$ = $2q$ + 4

 $S$ = $N1$+$N2$+$N3$

 By hypothesis $S$ = $2q+(2q+2)+(2q+4$) = $6q+6$

 $S$ = $N1$+$N2$+$N3$ = $6(q+1)$

 \indent\textit{b) The product of any three consecutive even numbers is always a multiple of 8}\par

 \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
 $N1$ = $2q$

 $N2$ = $2q$ + 2

 $N3$ = $2q$ + 4

 $S$ = $N1\times N2\times N3$
 = $2q(4q^{2}+16q+8)$

 = $8q^{3}+32q^{2}+16q$

 = $8q(q^{2}+4q+2)$

\indent\textit{c) Prove that if you add the squares of three consecutive integer numbers and then subtract two, you always get a multiple of 3.}\par

 \vspace{4pc}

 \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
 $N1 = (2q)^{2}$

 $N2 = (2q + 2)^{2}$

 $N3 = (2q + 4)^{2}$

 $S = N1 + N2 + N3$

By hypothesis $S = ((2q)^{2} + (2q+2)^{2} + (2q+4)^{2})-2 $
$ = (4q^{2}+(4q^{2}+8q+4)+(4q^{2}+16q+16))-2 $

$ = (12q^{2}+24q+20)-2 $

$ = 12q^{2}+24q+18 $

 $ = 3(4q^{2}+8q+6)$

 \noindent If $ N1= 2, N2=4, N3=6 $

 $S = ((2)^{2}+(4)^{2}+(6)^2)-2 = (56)-2 = 54 = 3\times 18$\par
 \noindent If $ N1 = 4, N2 = 6, N3 = 8 $

 $S = ((4)^{2}+(6)^{2}+(8)^2)-2 = (116)-2 = 114 = 3\times 38$

\vspace{1pc}

\noindent\textbf{Exercise 3}

\vspace{1pc}

\noindent\textit{Based on the final number obtained, Roger can then “guess” the initial number. Show that there is no magic in this. Justify your answer.} \par
 \setlength{\parindent}{10ex}
 Let $x$ be the random integer: \hfill $2x$

 \hfill $2x + 5$

 \hfill $ (2x + 5)^{2} $

 \hfill $(4x^{2}+20x+25)-25 $

 \hfill $ (4x^{2}+20x) \div 4 $

%% Roger can simply asubtract 5 from the final number and\hfill $ ( x^{2} +5x) \div x $
%%
%% he will be able to guess the integer. \hfill $x + 5$

\vspace{1pc}

\noindent\textbf{Exercise 4}

\vspace{1pc}

\noindent\textit{Prove the following identities, where $p, q, x, m,$ and $n$ are real numbers:} \par
 \noindent\textit{a) $8(p-q)+3(p+q)=2(p+2q)+9(p-q)$}\par
 \noindent Let the LHS = $8(p-q)+3(p+q)$

 \setlength{\parindent}{13ex} = $8p-8q+3p+3q = 11p - 5q$

 \noindent Let the RHS = $2(p+2q)+9(p-q)$

 \setlength{\parindent}{13ex} = $2p+4q+9p-9q = 11p - 5q$ \hfill Therefore $LHS = RHS$

 \noindent\textit{b) $ x(m+n)+y(n-m)=m(x-y)+n(x+y)$}\par

 \noindent Let the LHS = $x(m+n)+y(n-m)$

 \setlength{\parindent}{13ex} = $ xm + xn +yn -ym $

 \noindent Let the RHS = $m(x-y)+n(x+y)$

 \setlength{\parindent}{13ex} = $xm - ym + xn + yn = xm +xn + yn - ym $ \hfill Therefore $LHS = RHS$

 \noindent\textit{c) $(x+2)(x+10)-(x-5)(x-4)=21x$}\par

 \noindent Let the LHS = $(x+2)(x+10) - (x-5)(x-4)$

 \setlength{\parindent}{13ex} = $ (x^{2}+12x+20) - (x^{2}-9x+20)$

 = $21x $

 \noindent Let the RHS = $21x$ \hfill Therefore $LHS = RHS$

 \noindent\textit{d) $m^{4}-1=(m^{2+}1)(m^{2}-1)$}\par

 \noindent Let the LHS = $m^{4}-1$

 \noindent Let the RHS = $(m^{2}+1)(m^{2}-1)$
 = $m^{4} -1 $\hfill Therefore $LHS = RHS$

\vspace{2pc}

\noindent\textbf{Extra Credit}

\vspace{1pc}

\par If the 1 minute person goes across with the two minute person that would be 2 min gone. The one minute person then goes back to the ten \& five minute persons while the two minute person is already on the other side, 3 minutes will have elapsed.Once back on the starting side, the one minute person gives the ten minute person and the five minute person the flashlight, they cross to the other side with 13 minutes goneby. If the ten \& five minute person give the two minute person the flashlight, the two minute person can go back across the bridge to retrieve the one minute person and this will cost another 2 minutes so 15 minutes will have elapsed. The two minute person then crosses to the other side with the one minute person, they will both take another 2 minutes and all will have crossed in 17 minutes.

\end{flushleft}

\end{document} 

结果第一页如下:

在此处输入图片描述

答案2

我已经注释掉了完全错误的代码,以便 LaTeX 能够编译它。目前,此代码编译,但输出结果不佳。

正如问题评论中提到的,你犯了很多典型的新手错误(我们都犯过),你一定要读一些基本的 LaTeX 入门材料。一个好的起点可以是LaTeX2e 的简短介绍

简单解释一下,在学习了一些基本文档之后,你应该能够自己理解这一点:你对数学环境有一个常见的误解,代码中的许多错误都是由于使用数学字符和宏而发生的,例如上标^{}\times 外部数学。这是正确的代码:$ax^2 + bx + c = 0$,这不是:$ax$^2 + $bx$ + $c$ = 0

\documentclass[11pt]{article}

\usepackage{fullpage} 
\usepackage{amsmath}  
\usepackage{amssymb}  
\usepackage{amsthm}   
\usepackage{comment}  
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{lipsum}

\usepackage[colorlinks=true,citecolor=blue,linkcolor=blue]{hyperref} 

\usepackage{lipsum}

\makeatletter
\renewcommand{\maketitle}{\bgroup\setlength{\parindent}{0pt}
\begin{flushleft}
  \@title

  \@author
\end{flushleft}\egroup
}
\makeatother

\title{}
\date{}
\author{%
Name \\
Due \\
ID\\
}

\pagestyle{empty} % disables page numbers

\begin{document}

\maketitle

\centerline{\sc \large Homework 1 in \LaTeX\ }

\vspace{2pc}

\thispagestyle{empty}

\begin{flushleft}
\textbf{Exercise 1} 

\vspace{1pc}

\par \textit{A ball and a bat cost \$1.10 (total). The bat costs \$1.0 more than the ball. How much does the ball cost?}\par
    \setlength{\parindent}{10ex} 
    Let the price of the bat = $x$ \hfill $x$ + $y$ = 1.10

    Let the price of the ball = $y$ \hfill $x$ = $y$ + 1.0

                                    \hfill ($y$ + 1) + $y$ = 1.10

                                    \hfill 2$y$ = .10

                                    \hfill $y$ = .05

                                    \hfill $x$ + .05 = 1.10

                                    \hfill $x$ = \$1.05

    Therefore the ball cost \$0.05 and the the bat cost \$1.0 

\vspace{1pc}    

\noindent\textbf{Exercise 2} 

\vspace{1pc}

\noindent\textit{Prove the following statements:}\par
    \indent\textit{a)   The sum of any three consecutive even numbers is always a multiple of 6}\par

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
    $N1$ = $2q$ 

    $N2$ = $2q$ + 2 

    $N3$ = $2q$ + 4

    $S$ = $N1$+$N2$+$N3$

    By hypothesis $S$ = $2q+(2q+2)+(2q+4$) = $6q+6$

    $S$ = $N1$+$N2$+$N3$ = $6(q+1)$

    \indent\textit{b)   The product of any three consecutive even numbers is always a multiple of 8}\par

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
    $N1$ = $2q$ 

    $N2$ = $2q$ + 2 

    $N3$ = $2q$ + 4

    % $S$ = $N1$\times$N2$\times$N3$
%                     = $2q(4q^{2}+16q+8)$

%                     = $8q^{3}+32q^{2}+16q$

%                     = $8q(q^{2}+4q+2)$ 

\indent\textit{c)   Prove that if you add the squares of three consecutive integer numbers and then subtract two, you always get a multiple of 3.}\par

    \vspace{4pc}

    \noindent Let $N1$ be the first even integer where $N2$ and $N3$ are consecutive even integers.\par
%     $N1$ = ($2q$)^{2} 

%     $N2$ = ($2q + 2$)^{2} 

%     $N3$ = ($2q + 4$)^{2} 

    $S = N1 + N2 + N3$

% By hypothesis $S = ((2q)^{2} + (2q+2)^{2} + (2q+4)^{2})-2 

%                     = (4q^{2}+(4q^{2}+8q+4)+(4q^{2}+16q+16))-2

%                     = (12q^{2}+24q+20)-2

%                     = 12q^{2}+24q+18

%                     = 3(4q^{2}+8q+6)$

    \noindent If N1= 2, N2=4, N3=6

%     $S$ = ((2)^{2}+(4)^{2}+(6)^2)-2 = (56)-2 = 54 = 3\times 18\par
    \noindent If N1 = 4, N2 = 6, N3 = 8

%     $S$ = ((4)^{2}+(6)^{2}+(8)^2)-2 = (116)-2 = 114 = 3\times 38

\vspace{1pc}    

\noindent\textbf{Exercise 3} 

\vspace{1pc}

\noindent\textit{Based on the final number obtained, Roger can then “guess” the initial number. Show that there is no magic in this. Justify your answer.} \par
    \setlength{\parindent}{10ex} 
    Let $x$ be the random integer: \hfill $2x$

                                   \hfill $2x$ + 5

%                                    \hfill (2$x$ + 5)^{2}

%                                    \hfill (4$x$^{2}+20$x$+25)-25

%                                    \hfill (4$x$^{2}+20$x$) \div 4

%     Roger can simply asubtract 5 from the final number and\hfill ($x^{2}$+5$x$) \div x

    he will be able to guess the integer.  \hfill $x$ + 5

\vspace{1pc}    

\noindent\textbf{Exercise 4} 

\vspace{1pc}

\noindent\textit{Prove the following identities, where $p, q, x, m,$ and $n$ are real numbers:} \par
    \noindent\textit{a) $8(p-q)+3(p+q)=2(p+2q)+9(p-q)$}\par
    \noindent Let the LHS = $8(p-q)+3(p+q)$

    \setlength{\parindent}{13ex}  = $8p-8q+3p+3q = 11p - 5q$ 

    \noindent Let the RHS = $2(p+2q)+9(p-q)$

    \setlength{\parindent}{13ex}  = $2p+4q+9p-9q = 11p - 5q$ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{b) $ x(m+n)+y(n-m)=m(x-y)+n(x+y)$}\par

    \noindent Let the LHS = $x(m+n)+y(n-m)$

    \setlength{\parindent}{13ex}  = $ xm + xn +yn -ym $ 

    \noindent Let the RHS = $m(x-y)+n(x+y)$

    \setlength{\parindent}{13ex}  = $xm - ym + xn + yn = xm +xn + yn - ym $ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{c) $(x+2)(x+10)-(x-5)(x-4)=21x$}\par

    \noindent Let the LHS = $(x+2)(x+10) - (x-5)(x-4)$

    \setlength{\parindent}{13ex}  = $ (x^{2}+12x+20) - (x^{2}-9x+20)$ 

                                  = $21x $ 

    \noindent Let the RHS = $21x$ \hfill Therefore $LHS = RHS$ 

    \noindent\textit{d) $m^{4}-1=(m^{2+}1)(m^{2}-1)$}\par

    \noindent Let the LHS = $m^{4}-1$

    \noindent Let the RHS = $(m^{2}+1)(m^{2}-1)$ 
                          = $m^{4} -1 $\hfill Therefore $LHS = RHS$

\vspace{2pc}    

\noindent\textbf{Extra Credit} 

\vspace{1pc}

\par If the 1 minute person goes across with the two minute person that would be 2 min gone. The one minute person then goes back to the ten \& five minute persons while the two minute person is already on the other side, 3 minutes will have elapsed.Once back on the starting side, the one minute person gives the ten minute person and the five minute person the flashlight, they cross to the other side with 13 minutes goneby. If the ten \& five minute person give the two minute person the flashlight, the two minute person can go back across the bridge to retrieve the one minute person and this will cost another 2 minutes so 15 minutes will have elapsed. The two minute person then crosses to the other side with the one minute person, they will both take another 2 minutes and all will have crossed in 17 minutes.


\end{flushleft}     

\end{document}

相关内容