LaTeX 代码中的错误

LaTeX 代码中的错误

有人能发现我的 LaTeX 代码中的错误吗?这是我第一次使用 LaTeX,所以我对它的工作原理不太熟悉。我的代码在第 38 行出现错误,描述如下:“LaTeX 错误:Unicode 字符 - (U+2212)”。

我的代码如下:

\documentclass[a4paper, 12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{tgtermes}
\usepackage{fouriernc}
\usepackage[T1]{fontenc}
\usepackage[margin=3cm]{geometry}


\usepackage{amssymb}
\usepackage{amsmath}

\usepackage{enumerate}
\usepackage{verbatim}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=red,   
    urlcolor=red,
}
\usepackage{listings}
\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}

\title{1. Handin\\{\large \textsc{Algoritmer og datastrukturer}}}
\author{Gustav Næsborg Eskesen og Casper Kejser}
\date{September 11th, 2023}

\begin{document}

\maketitle

\section{Problem 1.8: Searching an infinite sorted list *}
\underline{\textbf{\emph{Problem description:}}}
\\
\emph{Assume we have an infinite long increasing sequence of real values $x_1<x_2<x_3<\cdot\cdot\cdot$ and we want to find the position of a real value $y>x_1$ in this list. More specifically, we want to find the index $d$ where $x_d-1<y\le x_d$, i.e. $x_d=y$ if $y$ is in the list, and otherwise $x_d$ is the successor of $y$ in the list. E.g. for the sequence $3 5 7 9 11 17 19 23 31 33 37 . . .$ and $y = 11$ we have $d = 5$, since $y = x_5 = 11$, whereas for $y = 24$ we have $d = 9$, since $23 = x_8 < y \le x_9 = 31$. We assume the sequence to be divergent, i.e. there always exists such a $d$. Describe an algorithm to find the index $d$, where the number of comparisons performed between $y$ and the $x_i$s is a function of the final value of $d$. What is the most efficient algorithm (fewest number of comparisons performed) you can find? Argue that your algorithm finds the correct index $d$, such that either $y = x_d or x_d−1 < y < x_d$. Analyze your algorithm — how many comparisons does your algorithm perform as a function of $d$?}
\\
\\
We will try solving this problem using binary search. As we know binary search needs a list of numbers, which has an end, because it is not possible for us to go to the  middle of an infinte number list. So we will start from the start of the list, and take a sequence of numbers from the list. We will then check the highest number of the list and if it is under y we will double the list size, and then continue to do this until we have a list where y is in it. 
So if we take a set of numbers from the start of the list that goes from $x_1 + x_2 ..... x_b$. We then check that $x_b \geq y$. If not then we double our search  amount. Such that $x_{2b}$. And we continue doing this $x_{((2b)2)2.....n}$ until $x_n \geq y$. We can rewrite this to $x_{b2^n}$.  And if we want to make it even more digestible we can set b as 1, such that we can say $2^n$.
\\
\\
We extend our list of numbers by $2^n$. Until this $x_{2^n} \geq y$ is true. When this is true we can take the list of numbers we have and start performing binary search, unless $x_{2^n} = y$, then we have found y and can end the search.
We will from now call y for its index d, because that is what we are suppose to find in the assignment description. We now know that d exist in this list $2^{n-1} < d \leq 2^n$. This means that the list length is $2^n - 2^{n-1}$. We can reduce this to $2^{n-1}$. 
\\
\\
Using the function from thereom 6 from literature [6]. We know now that  our algorithm will in the worst case scenario make $\lceil log_2 ({2^{n-1}} - 1) \rceil$ comparisons before it finds index d. 


\end{document}

答案1

这是第 38 行段落末尾的公式$y = x_d or x_d-1 < y < x_d$。符号-不常见。您的文件是用 utf8 编码的吗?

答案2

让我重申一下上面已经提到的一些内容,无论是作为评论还是答案:

有问题的字符是 utf-8 代码2212,即数学减号。它可能看起来像连字符(取决于字体),但执行方式不同。字符 utf-8002D是标准连字符,可以兼作减号。显然,LaTeX 数学处理需要那里有一个普通连字符,它会将其解释为减号。它与实际的 utf-8 减号混淆了。这让我很惊讶。

可以通过将纯文本加载到十六进制编辑器中来检测。您将看到,在需要十六进制代码(连字符)的地方,却出现了字符的2D三个 utf-8 代码(数学减号)。E2 88 922212

现在,一般来说你应该使用 utf-8,除非有充分的理由不这样做,例如你正在使用较旧的 LaTeX 代码。但这不是这里的问题。

另一个可能出现的混淆(不在本代码中)是,在纯文本文件中插入不间断空格字符A0而不是普通空格。它们看起来都像空格,但 LaTeX 可能会以不同的方式处理它们。

至于使用\\换行符:当然,你可以这样做。但是当你使用\\它时,意味着行将不会对齐,并且下面的文本是同一个连续段落的一部分(那里没有缩进)。这可能不是你想要做的。因此,你可以在段落之间使用一行空白的纯文本,或者使用\par代码明确结束一个段落。

相关内容