I created a course summary box. In order to distinguish the summaries by school year, I have put an optional argument that displays the latter in the upper left corner (highlighted in yellow on the screenshot).
To display this school year, I write a fraction in the optional argument, like this:
\begin{resume}[$\sfrac{2018}{2019}$]{chapitre 1}
\tcbsubtitle{Définition}
\lipsum[1]
\end{resume}
In order to simplify the code and also to progress in LaTeX, I want to modify this argument to transmit only the year 2018, then automatically calculate the next school year and display the fraction 2018/2019.
To do this, I created a counter called annee,
%\setcounter{annee}{#1}
but when I try to use it in a tcolorbox, I have this error:
! Missing \endcsname inserted.
\documentclass{article}
\usepackage{lipsum}
\usepackage{xfrac}
\usepackage[most]{tcolorbox}
\newcounter{annee}
\tcbset{titreresume/.style={boxed title style={colframe=black!15,colbacktitle=gray!75,
leftrule=1.5mm,rightrule=1.5mm,toprule=1.5pt,bottom=0pt,boxsep=1pt}}}
\tcbset{soustitre/.style={subtitle style={colback=black!7,colframe=black!25,
boxsep=1mm,fontupper={\sffamily\bfseries\large\selectfont\color{black!63}}}}}
\newtcolorbox[auto counter]{resume}[2][]{%
%\setcounter{annee}{#1}
minipage boxed title*=-106mm,
before upper={\textcolor{black!63}{#1 \hfill #2\hfill\thetcbcounter/\pageref{nombre-de-page}}},
titreresume,soustitre,colframe=black!25,colback=white,leftrule=3mm,rightrule=3mm,toprule=2pt,bottomrule=2pt,left=3pt,right=0pt,top=3mm,
fonttitle=\sffamily\bfseries\large,label={nombre-de-page},
enhanced,nobeforeafter,lower separated=false,attach boxed title to top center={yshift=-3mm,xshift=-\linewidth/5},
title={\normalsize Résumé}}
\begin{document}
\begin{resume}[$\sfrac{2018}{2019}$]{chapitre 1}
\tcbsubtitle{Définition}
\lipsum[1]
\end{resume}
\newpage
\begin{resume}[$\sfrac{2018}{2019}$]{chapitre 1}
\tcbsubtitle{Propriétés}
\lipsum[2]
\end{resume}
\end{document}
How do I do calculations with a LaTeX counter in a tcolorbox?
Translated with www.DeepL.com/Translator



\the\numexpr? A TeX register? Or something else? – AndréC Dec 24 '18 at 15:35\numexprwhich is an e-TeX registry and not a LaTeX\newcounterwhen both are registries (if I'm not mistaken)? – AndréC Dec 25 '18 at 07:21\newcounter{foo}involves the definition of\c@foo, aTeXcounter register, but macro definition isn't expandable; direct usage of\numexpris expandable... – Dec 25 '18 at 10:33