缺少 $ 插入。额外的},或逐字遗忘的$

Missing $ inserted. Extra }, or forgotten $ in verbatim

我正在逐字环境中渲染内联数学。

代码为

\usepackage{upquote} % Upright quotes for verbatim code
\usepackage{eurosym} % defines \euro
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
\usepackage{fancyvrb} % verbatim replacement that allows latex

\providecommand{\tightlist}{%
   \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\{\}}

\begin{Verbatim}[commandchars=\\{\}, fontsize=\small, xleftmargin=-3.9em]
\displaystyle \cos{\left(x \right)}  - (1)
\end{Verbatim} - (2)

对于第 (1) 行,警告是 - 缺少插入的 $。额外的 },或者忘记了 $ .

对于第 (2) 行,警告是 - 出了点问题 - 可能缺少 \item。缺少 $ 插入。缺少 } 插入。

如果有人想现场观看,请看这里 link(只读):- https://www.overleaf.com/read/dvrbkmkmdcgc

我无法找出此处所需的正确语法。 谢谢

您需要围绕内联数学添加数学模式。在普通文本中,您可能会使用 $...$,但由于您已经启用 \ 作为 latex 命令的开始进行转义,因此您可以使用 \(....\) 作为快速解决方法。如果您需要更大的灵活性,我建议您查看 listings 包而不是 fancyvrb

\documentclass{article}
\usepackage{upquote} % Upright quotes for verbatim code
\usepackage{eurosym} % defines \euro
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
\usepackage{fancyvrb} % verbatim replacement that allows latex
\providecommand{\tightlist}{%
    \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\{\}}

\title{Testing}
\author{aakashguptachoudhury }
\date{October 2019}

\usepackage{natbib}
\usepackage{graphicx}

\begin{document}

\maketitle

\section{Introduction}
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened.

\begin{figure}[h!]
\centering
\includegraphics[scale=1.7]{universe}
\caption{The Universe}
\label{fig:universe}
\end{figure}

\section{Conclusion}
``I always thought something was fundamentally wrong with the universe'' \citep{adams1995hitchhiker}
 \begin{Verbatim}[commandchars=\\{\}, fontsize=\small, xleftmargin=-3.9em]
 \(\displaystyle \displaystyle \cos{\left(x\right)} \)
\end{Verbatim}

\bibliographystyle{plain}
\bibliography{references}
\end{document}