# How to calculate the current school year in a tcolorbox?

I have created a personal package that contains the definition of a summary box.

This box has an optional argument that is the current school year (highlighted in yellow in the screenshot below).

I would like to be able to calculate the current school year automatically.

• Thus, for a compilation between September 1, 2018 and August 31, 2019, the school year displayed is 2018/2019 by default.
• Otherwise, if this option is set to 2017, it will display as it does today 2017/2018.

### How can this be achieved?

The current code is the one of @jbfu's response:

\documentclass{article}
\usepackage{lipsum}
\usepackage{xfrac}
\usepackage[most]{tcolorbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% boite resumé

\def\couleurresume{red}%

% style du titre « résumé du cours »
\tcbset{titreresume/.style={
boxed title style={
colframe=\couleurresume!50,%
colback=\couleurresume!10,%
coltext=blue,%
leftrule=1.5mm,rightrule=1.5mm,toprule=1.5pt,bottom=0pt,boxsep=1pt}}
}

% style des soustitres des résumés
\tcbset{soustitre/.style={
subtitle style={%
colback=\couleurresume!7,%
colframe=\couleurresume!50,%
boxsep=1mm,
fontupper={\sffamily\bfseries\large\selectfont\color{\couleurresume!63!black}}}}
}

% style du titre-boxed des encadrés
minipage boxed title*=-.5\linewidth,
boxed title style={
boxrule=.8pt,boxsep=0pt,toptitle=0pt,
colframe=\couleurresume!55,colback=white},
halign title=left}
}

% boite créant la boite résumé
\newtcolorbox[auto counter]{resume}[2][]{%
minipage boxed title*=-106mm,
attach boxed title to top center={yshift=-3mm,xshift=-\linewidth/5},
enhanced,
nobeforeafter,
lower separated=false,
before upper={
\textcolor{\couleurresume!63!black}{\sfrac{#1}{\the\numexpr#1+1} \hfill{#2}\hfill\thetcbcounter/\ref{nombre-de-resume}}},
colframe=\couleurresume!50,%
colback=white,%
coltitle=\couleurresume!63!black,%
leftrule=3mm,rightrule=3mm,toprule=2pt,bottomrule=2pt,left=3pt,right=0pt,top=3mm,
fonttitle=\sffamily\bfseries\large,
titreresume,soustitre,title={\normalsize Résumé}
}

\usepackage{atveryend}
\makeatletter
\AfterLastShipout{%
\immediate\write\@auxout
{\string\newlabel{nombre-de-resume}{{\thetcb@cnt@resume}{}}}%
}
\makeatother
\begin{document}

\begin{resume}[2018]{chapitre 1}
\tcbsubtitle{Définition}

\lipsum[1]
\end{resume}

\newpage

\begin{resume}[2018]{chapitre 1}

\tcbsubtitle{Propriétés}
\lipsum[2]
\end{resume}

%\show\tcbcounter
\end{document}


Please note that there is a follow-up question here...

Here is a way with \NewDocumentCommand and checking the \year and \month counter registers.

Apparently a school year is pretty much exactly one year in France (so different to Germany, where it usually begins in August/September and ends in June/July -- school's out for summer is not counted here)

\currentschoolyear has one optional argument, tested with \IfValueTF -- without the argument, the month is whether it is smaller than 9 if this is the case, it is the time from January to August, so it is the current school year at that period, if month is 9 or larger, the value advances to the next year, i.e. 2019/09/21 would give 2019/2020, whereas 2019/05/21 will return 2018/2019.

\NewDocumentCommand{\currentschoolyear}{+o}{%
\IfValueTF{#1}{%
\sfrac{#1}{\the\numexpr#1+1}%
}{%
\ifnum\month<9%
\sfrac{\the\numexpr\year-1}{\the\year}%
\else
\sfrac{\the\year}{\the\numexpr\year+1}%
\fi
}%
}


In order to test for empty arguments from the tcolorbox environment either use \ifblank (a etoolbox macro) or switch over to the more sophisticated \NewTColorBox macro that allows checks for xparse - like argument specifiers.

I've provided both \ifblank method in the definition of the oldresume environment and IfValueTF= - method with resume.

\month=9 can be used in order to explicitly set the month, if needed, e.g. for testing etc., the same holds for \year=2019 etc. if needed.

\documentclass{article}
\usepackage{lipsum}
\usepackage{xfrac}
\usepackage[most]{tcolorbox}

\NewDocumentCommand{\currentschoolyear}{+o}{%
\IfValueTF{#1}{%
\sfrac{#1}{\the\numexpr#1+1}
}{%
\ifnum\month<9%
\sfrac{\the\numexpr\year-1}{\the\year}%
\else
\sfrac{\the\year}{\the\numexpr\year+1}%
\fi
}%
}

%\month=7
%\day=31

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% boite resumé

\def\couleurresume{red}%

% style du titre « résumé du cours »
\tcbset{titreresume/.style={
boxed title style={
colframe=\couleurresume!50,%
colback=\couleurresume!10,%
coltext=blue,%
leftrule=1.5mm,rightrule=1.5mm,toprule=1.5pt,bottom=0pt,boxsep=1pt}}
}

% style des soustitres des résumés
\tcbset{soustitre/.style={
subtitle style={%
colback=\couleurresume!7,%
colframe=\couleurresume!50,%
boxsep=1mm,
fontupper={\sffamily\bfseries\large\selectfont\color{\couleurresume!63!black}}}}
}

% style du titre-boxed des encadrés
minipage boxed title*=-.5\linewidth,
boxed title style={
boxrule=.8pt,boxsep=0pt,toptitle=0pt,
colframe=\couleurresume!55,colback=white},
halign title=left}
}

% boite créant la boite résumé
\newtcolorbox[auto counter]{oldresume}[2][]{%
minipage boxed title*=-106mm,
attach boxed title to top center={yshift=-3mm,xshift=-\linewidth/5},
enhanced,
nobeforeafter,
lower separated=false,
before upper={
\textcolor{\couleurresume!63!black}{\ifblank{#1}{\currentschoolyear}{\currentschoolyear[#1]} \hfill{#2}\hfill\thetcbcounter/\ref{nombre-de-resume}}},
%        \textcolor{\couleurresume!63!black}{\sfrac{#1}{\the\numexpr#1+1} \hfill{#2}\hfill\thetcbcounter/\ref{nombre-de-resume}}},
colframe=\couleurresume!50,%
colback=white,%
coltitle=\couleurresume!63!black,%
leftrule=3mm,rightrule=3mm,toprule=2pt,bottomrule=2pt,left=3pt,right=0pt,top=3mm,
fonttitle=\sffamily\bfseries\large,
titreresume,soustitre,title={\normalsize Résumé}
}

\NewTColorBox[auto counter]{resume}{+o+m}{%
minipage boxed title*=-106mm,
attach boxed title to top center={yshift=-3mm,xshift=-\linewidth/5},
enhanced,
nobeforeafter,
lower separated=false,
IfValueTF={#1}{%
before upper={\textcolor{\couleurresume!63!black}{\currentschoolyear[#1] \hfill{#2}\hfill\thetcbcounter/\ref{nombre-de-resume}}},
}{%
before upper={\textcolor{\couleurresume!63!black}{\currentschoolyear \hfill{#2}\hfill\thetcbcounter/\ref{nombre-de-resume}}},
},
colframe=\couleurresume!50,%
colback=white,%
coltitle=\couleurresume!63!black,%
leftrule=3mm,rightrule=3mm,toprule=2pt,bottomrule=2pt,left=3pt,right=0pt,top=3mm,
fonttitle=\sffamily\bfseries\large,
titreresume,soustitre,title={\normalsize Résumé}
}

\usepackage{atveryend}
\makeatletter
\AfterLastShipout{%
\immediate\write\@auxout
{\string\newlabel{nombre-de-resume}{{\thetcb@cnt@resume}{}}}%
}
\makeatother
\begin{document}

\begin{resume}[2017]{chapitre 1}
\tcbsubtitle{Définition}

\lipsum[1]
\end{resume}

\newpage

\begin{resume}{chapitre 1}

\tcbsubtitle{Propriétés}
\lipsum[2]
\end{resume}

%\show\tcbcounter
\end{document}

• To my knowledge, the school year does not have a legal definition in France. The start dates and the summer holiday date are defined. These dates vary each year. Currently, teachers return to school on the last day of August. So, to simplify, I prefer to pretend that a school year lasts a full year. This will allow me to correct the previous year's documents without having to change the default option. – AndréC Jan 19 '19 at 21:03
• @AndréC: In my federal state here in Germany, school always ends at end of July and starts mid of september. I don't bother about the correct dates however. The code I gave above is what I use basically in my LaTeX code suite for my work at school. – user31729 Jan 19 '19 at 21:07
• 50 years ago in France, it was the same as in Germany. It allowed the children of farmers (very many at the time) to help their parents in the fields. From now on, summer holidays are getting shorter and shorter so that the official summer holiday date is July 6, 2019! The Ministry and many unions want this holiday to be even shorter, but the tourism industry is not in favour of it (and neither am I). – AndréC Jan 19 '19 at 21:11
• Where can I find documentation on the registers \year, \month? – AndréC Jan 23 '19 at 6:15
• @AndréC: TeX by Topic or the TeXBook, I would say --- they are TeX registers – user31729 Jan 23 '19 at 15:23