编写方程式并使用新命令时,LaTeX 中出现未定义的控制序列错误

编写方程式并使用新命令时,LaTeX 中出现未定义的控制序列错误

我已经使用 定义了参数\newcommand,然后在 Latex 文档中写了一些方程式。但是我收到一个错误undefined control sequence

\begin{document}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{verbatim}
\newcommand{\LC}{{\Gamma}_{\text{L}}}
\newcommand{\interest}{I}
\newcommand{\myr}{r} % the same for the time
\newcommand{\myy}{y}
\newcommand{\cost}{C}
 %\newcommand{\Pev}{{P}_{\text{EV},c,t}}
\newcommand{\rp}[1]{\cost_{\text{p},#1}} %rest to be payed
\newcommand{\ci}[1]{\cost_{\text{I},#1}}     %cost yearly interest
\newcommand{\rb}{\myr_{\text{B}}} %repayment for the bank
\newcommand{\ct}{\cost_{\text{T}}} 
\begin{equation}
\LC = \sum_{\myy=0}^{\lifetime}{\NPC-\rp{\myy}}+\ct
\label{A1}
\end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{equation}
\rb= \frac{\ct}{\lifetime} 
\label{A2}
\end{equation}
\end{document}

这些是更多具有相同误差的方程。

\begin{equation}
\rp{\myy}= 
    \begin{cases}
        \rp{\myy-1} - \rb & , \myy\in\myofbrace{0,\dots,\lifetime} \\
         \ct - \rb & , \myy=0
    \end{cases}
\label{A3} 
 \end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%it is illustrated by this equation:
\begin{equation}
 \ci{\myy}= 
    \begin{cases}
       \rp{\myy-1} \interest & , \myy\in\myofbrace{0,\dots,\lifetime} \\
       \ct \interest & , \myy=0
    \end{cases} 
\label{A4}
\end{equation}
% t = rest to be payed t-1 * interest rate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Where,
\begin{itemize}
\item $\LC$: Total net present cost.
\item $\myy$: The year index.
\item $\lifetime$: The lifetime of the project.
\item $\NPC$: The operating cost of year 0.
\item $\rp{\myy}$: The rest to be payed for the bank for year $\myy$.
\item $\rp{\myy-1}$: The rest to be payed for the bank for year $\myy-1$.
\item $\ct$:  The capital cost.
\item $\rb$: The repayment for the bank every year.
\item $\ci{\myy}$: The yearly cost interest.
\item $\interest$: The interest rate of the bank. 
\end{itemize}

答案1

日志中的错误消息确实显示了哪个命令未定义(\lifetime\NPC)在我修复了不相关的错误(例如丢失\documentclass和放错位置)之后\begin{document},日志文件清楚地显示了该问题

! Undefined control sequence.
l.19 \LC = \sum_{\myy=0}^{\lifetime
                                   }{\NPC-\rp{\myy}}+\ct
?

我在这里定义了\lifetime\NPC因此它运行时没有错误,但我不知道你想要什么定义。

\documentclass{article}
\newcommand\lifetime{\mathrm{lifetime}}
\newcommand\NPC{\mathrm{NPC}}


\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{verbatim}
\newcommand{\LC}{{\Gamma}_{\text{L}}}
\newcommand{\interest}{I}
\newcommand{\myr}{r} % the same for the time
\newcommand{\myy}{y}
\newcommand{\cost}{C}
 %\newcommand{\Pev}{{P}_{\text{EV},c,t}}
\newcommand{\rp}[1]{\cost_{\text{p},#1}} %rest to be payed
\newcommand{\ci}[1]{\cost_{\text{I},#1}}     %cost yearly interest
\newcommand{\rb}{\myr_{\text{B}}} %repayment for the bank
\newcommand{\ct}{\cost_{\text{T}}} 
\begin{document}
\begin{equation}
\LC = \sum_{\myy=0}^{\lifetime}{\NPC-\rp{\myy}}+\ct
\label{A1}
\end{equation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{equation}
\rb= \frac{\ct}{\lifetime} 
\label{A2}
\end{equation}
\end{document}

相关内容