How to do calculations with a LaTeX counter in a newtcolorbox environment?
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2]{%
%setcounter{annee}{#1}
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{#1 hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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
tcolorbox counters calculations
add a comment |
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2]{%
%setcounter{annee}{#1}
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{#1 hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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
tcolorbox counters calculations
add a comment |
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2]{%
%setcounter{annee}{#1}
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{#1 hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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
tcolorbox counters calculations
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2]{%
%setcounter{annee}{#1}
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{#1 hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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
tcolorbox counters calculations
tcolorbox counters calculations
edited 14 mins ago
asked 24 mins ago
AndréC
7,28711340
7,28711340
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Well you can't set the counter in the middle of a key-val-list. But beside this you don't need a counter for this:
documentclass{article}
usepackage{lipsum}
usepackage{xfrac}
usepackage[most]{tcolorbox}
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2][0]{%
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{sfrac{#1}{thenumexpr#1+1} hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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}[2018]{chapitre 1}
tcbsubtitle{Définition}
lipsum[1]
end{resume}
newpage
begin{resume}[2018]{chapitre 1}
tcbsubtitle{Propriétés}
lipsum[2]
end{resume}
end{document}

What isthenumexpr? A TeX register? Or something else?
– AndréC
7 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467192%2fhow-to-do-calculations-with-a-latex-counter-in-a-newtcolorbox-environment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Well you can't set the counter in the middle of a key-val-list. But beside this you don't need a counter for this:
documentclass{article}
usepackage{lipsum}
usepackage{xfrac}
usepackage[most]{tcolorbox}
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2][0]{%
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{sfrac{#1}{thenumexpr#1+1} hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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}[2018]{chapitre 1}
tcbsubtitle{Définition}
lipsum[1]
end{resume}
newpage
begin{resume}[2018]{chapitre 1}
tcbsubtitle{Propriétés}
lipsum[2]
end{resume}
end{document}

What isthenumexpr? A TeX register? Or something else?
– AndréC
7 mins ago
add a comment |
Well you can't set the counter in the middle of a key-val-list. But beside this you don't need a counter for this:
documentclass{article}
usepackage{lipsum}
usepackage{xfrac}
usepackage[most]{tcolorbox}
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2][0]{%
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{sfrac{#1}{thenumexpr#1+1} hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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}[2018]{chapitre 1}
tcbsubtitle{Définition}
lipsum[1]
end{resume}
newpage
begin{resume}[2018]{chapitre 1}
tcbsubtitle{Propriétés}
lipsum[2]
end{resume}
end{document}

What isthenumexpr? A TeX register? Or something else?
– AndréC
7 mins ago
add a comment |
Well you can't set the counter in the middle of a key-val-list. But beside this you don't need a counter for this:
documentclass{article}
usepackage{lipsum}
usepackage{xfrac}
usepackage[most]{tcolorbox}
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2][0]{%
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{sfrac{#1}{thenumexpr#1+1} hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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}[2018]{chapitre 1}
tcbsubtitle{Définition}
lipsum[1]
end{resume}
newpage
begin{resume}[2018]{chapitre 1}
tcbsubtitle{Propriétés}
lipsum[2]
end{resume}
end{document}

Well you can't set the counter in the middle of a key-val-list. But beside this you don't need a counter for this:
documentclass{article}
usepackage{lipsum}
usepackage{xfrac}
usepackage[most]{tcolorbox}
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={sffamilybfserieslargeselectfontcolor{black!63}}}}}
newtcolorbox[auto counter]{resume}[2][0]{%
minipage boxed title*=-106mm,
before upper={textcolor{black!63}{sfrac{#1}{thenumexpr#1+1} hfill #2hfillthetcbcounter/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=sffamilybfserieslarge,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}[2018]{chapitre 1}
tcbsubtitle{Définition}
lipsum[1]
end{resume}
newpage
begin{resume}[2018]{chapitre 1}
tcbsubtitle{Propriétés}
lipsum[2]
end{resume}
end{document}

answered 16 mins ago
Ulrike Fischer
185k7289666
185k7289666
What isthenumexpr? A TeX register? Or something else?
– AndréC
7 mins ago
add a comment |
What isthenumexpr? A TeX register? Or something else?
– AndréC
7 mins ago
What is
thenumexpr? A TeX register? Or something else?– AndréC
7 mins ago
What is
thenumexpr? A TeX register? Or something else?– AndréC
7 mins ago
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f467192%2fhow-to-do-calculations-with-a-latex-counter-in-a-newtcolorbox-environment%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown