I am using Miktex 2.9 with Texstudio 2.12.6. My document is in KOMA-class. As I was trying to load the optidef package, I got an error which seems related to \addcontentsline{toc}.
I assumed some outdated packages to be the cause, so I have updated all packages using Miktex Updater. The problem remains.
Here is a MWE:
\documentclass[12pt, twoside, openright, numbers=noenddot]{scrreprt}
%%%%%%%%%%%%%%%%% BEGIN PACKAGES
%%% Page header
\usepackage[automark,headsepline=off]{scrlayer-scrpage}
%%% Mathematic equations
%\usepackage{optidef}
%%% links in pdf
\usepackage{hyperref}
\usepackage[all]{hypcap}
\usepackage[numbered]{bookmark}
%%%%%%%%%%%%%%%%% END PACKAGES
\begin{document}
%%% ToC
\pagenumbering{roman}
\phantomsection
\pdfbookmark{Inhaltsverzeichnis}{toc}
\setcounter{tocdepth}{4}
\tableofcontents
%%%% from here on: add elements to ToC
\addtocontents{toc}{\setcounter{tocdepth}{0}}
%%%% chapters
\addtocontents{toc}{\setcounter{tocdepth}{4}}
\chapter{Test}
test
%%%% Optidef Example
%\begin{mini}[2]
% {w}{f(w)+ R(w+6x)}
% {\label{eq:Example1}}
% {}
% \addConstraint{g(w)}{=0}
% \addConstraint{n(w)}{= 6}
% \addConstraint{L(w)+r(x)}{=Kw+p}
% \addConstraint{h(x)}{=0.}
%\end{mini}
\end{document}
Without optidef package, the document compiles flawlessly. As soon as I load the package optidef, I will get the following error message for all corresponding lines of code:
Undefined control sequence. \addtocontents{toc}{\setcounter{tocdepth}{0}}
Does anyone have a solution? Thank you very much in advance.
Best regards, Dan.
\protectshould also be used without loadingoptidef. – egreg Oct 07 '18 at 14:31