1

I suddenly got an error in my .tex document in all the equations.

\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}
  • You can copy code directly in here, no need to let people fetch it from other sides! – user31729 Jan 5 '17 at 19:08
  • The macro \ifinenumerate is defined nowhere. – egreg Jan 5 '17 at 19:09
  • 1
    The unknown code is \ifinenumerate, not equation – user31729 Jan 5 '17 at 19:09
1

You seem to have copied code from https://tex.stackexchange.com/a/339515/4427 but you forgot some part of it.

\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}

I moved some parts to better places; don't forget fontenc.

  • not actually, a friend gave me that part of the code. Maybe he did. ;) – Ismael Jan 5 '17 at 19:16
  • @Ismael Then I'm quite certain you don't need it. ;-) – egreg Jan 5 '17 at 19:19
  • Dont know why those lines where missing. Last time I compiled it, it worked perfectly. now is working. Many thanks – Ismael Jan 5 '17 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.