未定义控制序列。\begin{equation}

未定义控制序列。\begin{equation}

.tex我的文档中的所有方程式突然出现错误。

\documentclass[a4paper,openright,12pt]{article}
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amssymb, amsmath, amsbsy} % simbolitos
\usepackage{upgreek} % para poner letras griegas sin cursiva
\usepackage{cancel} % para tachar
\usepackage{mathdots} % para el comando \iddots
\usepackage{mathrsfs} % para formato de letra
\usepackage{stackrel} % para el comando \stackbin
\usepackage{graphicx}
\usepackage{caption}
\usepackage{chngcntr}
\usepackage{hyperref}
\usepackage[a4paper,hmargin=2cm,vmargin={2cm,2.5cm}]{geometry}




\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{subsubsection}
\counterwithin*{figure}{section}
\counterwithin*{figure}{subsection}
\counterwithin*{figure}{subsubsection}


\makeatletter
\renewcommand\theequation{%
    \ifnum\value{subsection}>0 \thesubsection.\else
    \ifnum\value{section}>0 \thesection.\fi\fi
    \ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi%
    \arabic{equation}%
}
\AtBeginDocument{%
    \renewcommand\theHequation{%
        \ifnum\value{subsection}>0 \theHsubsection.\else
        \ifnum\value{section}>0 \theHsection.\fi\fi
        \ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname\fi%
        \arabic{equation}%
    }%
}

\renewcommand\thefigure{%
    \ifnum\value{subsection}>0 \thesubsection.\else
    \ifnum\value{section}>0 \thesection.\fi\fi
    \ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi%
    \roman{figure}
}
\AtBeginDocument{%
    \renewcommand\theHfigure{%
        \ifnum\value{subsection}>0 \theHsubsection.\else
        \ifnum\value{section}>0 \theHsection.\fi\fi
        \ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname\fi%
        \arabic{figure}%
    }%
}
\makeatother

\begin{document}

\begin{equation}
\label{eq:2.1.1}
\nabla \times \textbf{E} = - \frac{\partial \textbf{B}}{\partial t} 
\end{equation}

\end{document}

答案1

你似乎复制了https://tex.stackexchange.com/a/339515/4427但你忘记了其中的一部分。

\documentclass[a4paper,openright,12pt]{article}
\usepackage[a4paper,hmargin=2cm,vmargin={2cm,2.5cm}]{geometry} % better early
\usepackage[T1]{fontenc} % needed for Spanish
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amssymb, amsmath, amsbsy} % simbolitos
\usepackage{upgreek} % para poner letras griegas sin cursiva
\usepackage{cancel} % para tachar
\usepackage{mathdots} % para el comando \iddots
\usepackage{mathrsfs} % para formato de letra
\usepackage{stackrel} % para el comando \stackbin
\usepackage{graphicx}
\usepackage{caption}
\usepackage{chngcntr}
\usepackage{etoolbox} % needed for the code below
\usepackage{hyperref}




\counterwithin*{equation}{section}
\counterwithin*{equation}{subsection}
\counterwithin*{equation}{subsubsection}
\counterwithin*{figure}{section}
\counterwithin*{figure}{subsection}
\counterwithin*{figure}{subsubsection}

% these two lines were missing
\newif\ifinenumerate
\AtBeginEnvironment{enumerate}{\inenumeratetrue}

\makeatletter
\renewcommand\theequation{%
    \ifnum\value{subsection}>0 \thesubsection.\else
    \ifnum\value{section}>0 \thesection.\fi\fi
    \ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi%
    \arabic{equation}%
}
\AtBeginDocument{%
    \renewcommand\theHequation{%
        \ifnum\value{subsection}>0 \theHsubsection.\else
        \ifnum\value{section}>0 \theHsection.\fi\fi
        \ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname\fi%
        \arabic{equation}%
    }%
}

\renewcommand\thefigure{%
    \ifnum\value{subsection}>0 \thesubsection.\else
    \ifnum\value{section}>0 \thesection.\fi\fi
    \ifinenumerate \csname theenum\romannumeral\the\@enumdepth\endcsname\fi%
    \roman{figure}
}
\AtBeginDocument{%
    \renewcommand\theHfigure{%
        \ifnum\value{subsection}>0 \theHsubsection.\else
        \ifnum\value{section}>0 \theHsection.\fi\fi
        \ifinenumerate \csname theHenum\romannumeral\the\@enumdepth\endcsname\fi%
        \arabic{figure}%
    }%
}
\makeatother

\begin{document}

\begin{equation}
\label{eq:2.1.1}
\nabla \times \textbf{E} = - \frac{\partial \textbf{B}}{\partial t} 
\end{equation}

\end{document}

我把一些部分移到了更好的地方;别忘了fontenc

相关内容