在命令中增加计数器时缺少插入 \endcsname

在命令中增加计数器时缺少插入 \endcsname

鉴于以下情况WE

\documentclass[12pt]{article}

\usepackage{unicode-math}

\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\newtcolorbox{mybox}{
    sharp corners
}

\newcounter{mycounter}
\setcounter{mycounter}{0}

\newcommand{\myentry}[1]{%
    \addcontentsline{toc}{subsection}{%
        \textbf{\thesection.\themycounter}~\texorpdfstring{\boldmath #1}{a}%
    }%
}

\newcommand{\mysample}[1]{\begin{mybox}
        \textbf{Sample \themycounter:} \begin{equation*}
        #1
        \end{equation*}
\end{mybox}}

\usepackage{hyperref}

\begin{document}
    
    \tableofcontents

    \section{Samples}
    \myentry{$\symbf{a+b=c}$}
    \mysample{a+b = c}
    
    \myentry{$\symbf{x+y =z}$}
    \mysample{x + y = z}
\end{document}

我打算mycounter在读完计数器后增加。但当我这样做时

\newcommand{\myentry}[1]{%
    \addcontentsline{toc}{subsection}{%
        \textbf{\thesection.\refstepcounter{mycounter}\themycounter}~\texorpdfstring{\boldmath #1}{a}%
    }%
}

\protect并在每次调用之前添加一个\myentry{...},我收到以下错误

Missing \endcsname inserted. \protect\myentry{$\symbf{a+b = c}$}

我怎样才能解决这个问题?

相关内容