2

I want to make up a style(named myset/.code) of tcolorbox with three arguments. In this style, a macro will be re-defined. Please look at the following MWE. Yet it can not be compiled. I think someting is wrong with the defination of the style. Anyone could tell me how to modify my defination?

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\newcounter{mycounter}
\stepcounter{mycounter}

\newcommand{\mycontent}{\alph{mycounter}}

\tcbset{myset/.code n args={%
  \renewcommand{\mycontent}{%
     #1\#2{mycounter}#3%
   }}}

\begin{tcbitemize}
  \tcbitem \mycontent
  \tcbitem [myset={(}{alph}{)}] \mycontent % I want get a typeout of "(a)"
\end{tcbitemize}

\end{document}
lyl
  • 2,727

1 Answers1

1

If you say code n args, the first thing after = has to be the number of args, which is 3 in this case. And then, in order to "prepend a backslash" you need to use \csname.

\documentclass{article}
\usepackage[most]{tcolorbox}
\begin{document}

\newcounter{mycounter}
\stepcounter{mycounter}

\newcommand{\mycontent}{\alph{mycounter}}

\tcbset{myset/.code n args={3}{%
  \renewcommand{\mycontent}{%
     #1\csname #2\endcsname{mycounter}#3%
   }}}

\begin{tcbitemize}
  \tcbitem \mycontent
  \tcbitem [myset={(}{alph}{)}] \mycontent % I want get a typeout of "(a)"
\end{tcbitemize}

\end{document}

enter image description here

  • Many thanks for your so quick response!! Another question, if \mycontent also have its own arguments, how to distinguish them frome arguments of myset/.code? – lyl Nov 06 '18 at 04:50
  • @lyl You'd need to add another #, i.e ##1 for the first argument and so on. –  Nov 06 '18 at 04:52
  • The another # is for arguments of myset/.code or of \mycontent? – lyl Nov 06 '18 at 04:57
  • @lyl What I meant to say is nicely explained in this answer. –  Nov 06 '18 at 05:02