2

To write the handouts I use a command called \exo which displays in bold and automatically increments the exercise numbers. It has an optional parameter which is the grade obtained for the exercise during an evaluation. I improved it thanks to @egreg's answer here so that there is always a little bit of white space to write the grade next to the scale and it works very well.

But now the next line is fully justified instead of left aligned (which is what I want to achieve). For example the sentence "Compléter le tableau suivant et indiquez vos calculs:" is not left justified.

What is my mistake?

Translated with www.DeepL.com/Translator (free version)

my exercice

\documentclass[a5paper,12pt,french]{article}  % Présentation générale et mise en page

%  Marges de la page
\usepackage[left=0.3cm, right=0.3cm, top=1cm, bottom=0cm]{geometry}

% pas de retrait de paragraphe
\setlength{\parindent}{0mm}         
\usepackage{array}
\usepackage[output-decimal-marker={,}]{siunitx}
\sisetup{locale=FR}
                            
% --------------------------------------
% Nouvelle commande \exo pour numéroter les exercices
% --------------------------------------
\usepackage{ifthen}
\newcounter {EX} \setcounter{EX}{0}%compteur pour numéroter avant le \newcommand {\exo} ce sont des entiers (et non des décimaux)

\newcommand {\exo}[2][]{ %barème optionnel 
\stepcounter{EX} %
\par \vspace{1em} %\
\underline{\textbf{Exercice\,\theEX\,:}}\textbf{ #2}%
\ifthenelse{\equal{#1}{}} %
{\par} %
{\newdimen \p%
\p=#1cm % 
\ifdim \p<2cm
% egreg solution https://tex.stackexchange.com/a/91564/138900
\nobreak\hfill\penalty50\hskip1em\null\nobreak
     \hfill\makebox[5mm]{}/\num{#1}~point \parfillskip=0pt \finalhyphendemerits=0 \par
\else
\nobreak\hfill\penalty50\hskip1em\null\nobreak
     \hfill\makebox[5mm]{}/\num{#1}~points \parfillskip=0pt \finalhyphendemerits=0 \par
\fi} % 
}

\begin{document}
\thispagestyle{empty}



\pagestyle{empty}


\exo[3]{On agrandit une pièce triangulaire d'un puzzle tel que le côté qui mesure \SI{4}{cm} mesure \SI{4.8}{cm} sur le triangle agrandi}

Compléter le tableau suivant et indiquez vos calculs:


\exo[2,5]{Lors de sa construction en 1889, la tour Eiffel mesurait \SI{300}{m} de haut.}
Un modèle réduit en bois de la tour Eiffel mesure \SI{0,12}{m} de haut.

La largeur de ce modèle réduit est de \SI{0,05}{m}. Quelle est la largeur de la tour Eiffel?

\exo[2.5]{Lors de sa construction en 1889, la tour Eiffel  }


\end{document}
6
  • 2
    not related but do \newdimen \p outside the definition, you are allocating a new register each time. – David Carlisle Apr 16 at 16:22
  • 2
    also % at end of line doesn't suppress space if you leave space before it. \stepcounter{EX} % should be \stepcounter{EX}% (and all similar lines) – David Carlisle Apr 16 at 16:26
  • Andrééééééééé...re-welcome :-) – Sebastiano Apr 16 at 20:16
  • 1
    @Sebastiano Good evening, Sebastiano, how are you? – AndréC Apr 16 at 20:24
  • 1
    @Sebastiano I am very sorry to hear that things are not going well for you. I want you to know that I am thinking of you even if I don't know what to say or do for you. – AndréC Apr 16 at 20:38
5

You need to localize the change to \parfillskip. The braces are in the quoted answer.

I also simplified the code for adding the plural.

\documentclass[a5paper,12pt,french]{article}  % Présentation générale et mise en page

%  Marges de la page
\usepackage[left=0.3cm, right=0.3cm, top=1cm, bottom=0cm]{geometry}

% pas de retrait de paragraphe
\setlength{\parindent}{0mm}         
\usepackage{array}
\usepackage[output-decimal-marker={,}]{siunitx}
\sisetup{locale=FR}
                            
% --------------------------------------
% Nouvelle commande \exo pour numéroter les exercices
% --------------------------------------
%compteur pour numéroter avant le \newcommand {\exo} 
% ce sont des entiers (et non des décimaux)
\newcounter{EX}
%\setcounter{EX}{0}

\newcommand {\exo}[2][]{ %barème optionnel 
  \stepcounter{EX} %
  \par \vspace{1em} %\
  \underline{\textbf{Exercice\,\theEX\,:}}\textbf{ #2}%
  \if\relax\detokenize{#1}\relax
    \par
  \else
    % egreg solution https://tex.stackexchange.com/a/91564/138900
    \nobreak\hfill\penalty50\hskip1em\null\nobreak
    \hfill\makebox[5mm]{}/\num{#1}~point\ifdim#1cm<2cm \else s\fi
    {\parfillskip=0pt \finalhyphendemerits=0 \par}% <--- braces!
  \fi
}

\begin{document}
\thispagestyle{empty}

\pagestyle{empty}


\exo[3]{On agrandit une pièce triangulaire d'un puzzle tel que le 
côté qui mesure \SI{4}{cm} mesure \SI{4.8}{cm} sur le triangle agrandi}

Compléter le tableau suivant et indiquez vos calculs:


\exo[2,5]{Lors de sa construction en 1889, la tour Eiffel mesurait \SI{300}{m} de haut.}
Un modèle réduit en bois de la tour Eiffel mesure \SI{0,12}{m} de haut.

La largeur de ce modèle réduit est de \SI{0,05}{m}. Quelle est la largeur de la tour Eiffel?

\exo[2.5]{Lors de sa construction en 1889, la tour Eiffel  }

\end{document}

enter image description here

4
  • Thank you for your answer, I see that you have replaced the conditional test \ifthenelse{\equal{#1}{}} by \if\relax\detokenize{#1}\relax what is the reason ? – AndréC Apr 16 at 20:29
  • @AndréC Much neater, isn't it? And fully expandable, also. Not that in this case it matters a lot, but… Actually, I've never liked \ifthenelse. ;-) – egreg Apr 16 at 20:53
  • In Italian and English I don't know, but in French, the plural starts at 2 as recalled here projet-voltaire.fr/regles-orthographe/… so the test must be ifdim#1cm<2cm – AndréC Apr 17 at 5:47
  • @AndréC Fixed, thanks. – egreg Apr 17 at 7:58
4

Add an extra group so the settings are local.

Also some corrections to avoid adding space tokens, and toi use \refstepcounter so you can \label.

enter image description here

\documentclass[a5paper,12pt,french]{article}  % Présentation générale et mise en page

%  Marges de la page
\usepackage[left=0.3cm, right=0.3cm, top=1cm, bottom=0cm]{geometry}

% pas de retrait de paragraphe
\setlength{\parindent}{0mm}         
\usepackage{array}
\usepackage[output-decimal-marker={,}]{siunitx}
\sisetup{locale=FR}
                            
% --------------------------------------
% Nouvelle commande \exo pour numéroter les exercices
% --------------------------------------
\usepackage{ifthen}
\newcounter {EX} \setcounter{EX}{0}%compteur pour numéroter avant le \newcommand {\exo} ce sont des entiers (et non des décimaux)

\newcommand {\exo}[2][]{{%barème optionnel 
\refstepcounter{EX}%
\par \vspace{1em}%\
\underline{\textbf{Exercice\,\theEX\,:}}\textbf{ #2}%
\ifthenelse{\equal{#1}{}}%
{\par}%
{%
\ifdim#1cm<2cm
% egreg solution https://tex.stackexchange.com/a/91564/138900
\nobreak\hfill\penalty50\hskip1em\null\nobreak
     \hfill\makebox[5mm]{}/\num{#1}~point \parfillskip=0pt \finalhyphendemerits=0 \par
\else
\nobreak\hfill\penalty50\hskip1em\null\nobreak
     \hfill\makebox[5mm]{}/\num{#1}~points \parfillskip=0pt \finalhyphendemerits=0 \par
\fi}% 
}}

\begin{document}
\thispagestyle{empty}



\pagestyle{empty}


\exo[3]{On agrandit une pièce triangulaire d'un puzzle tel que le côté qui mesure \SI{4}{cm} mesure \SI{4.8}{cm} sur le triangle agrandi}

Compléter le tableau suivant et indiquez vos calculs:


\exo[2,5]{Lors de sa construction en 1889, la tour Eiffel mesurait \SI{300}{m} de haut.}
Un modèle réduit en bois de la tour Eiffel mesure \SI{0,12}{m} de haut.

La largeur de ce modèle réduit est de \SI{0,05}{m}. Quelle est la largeur de la tour Eiffel?

\exo[2.5]{Lors de sa construction en 1889, la tour Eiffel  }


\end{document}
4
  • Thank you for your answer and corrections. I thought that the simple fact of creating a group between braces {} was enough for the parameters to be local. And that therefore in a macro, the definitions were local. Why is this not the case and it is necessary to double the braces? – AndréC Apr 16 at 19:06
  • @AndréC no, braces in a macro definition or for surrounding a macro argument do not form a group otherwise a macro like \bfseries which is definded by \def\bfseries{.... change the font ...} would have no effect after the commnd. – David Carlisle Apr 16 at 19:11
  • If I understood well \refstepcounter, it will allow me to calculate automatically the scale of the evaluation and to display it at the top of the page on the evaluation, is this what this command is for ? Is that what this command is for? – AndréC Apr 17 at 5:22
  • no the behavior is exactly the same as stepcounter it just adds one, but it makes it the current reference so \label may be used and referenced later with \ref like a section counter or table counter @AndréC – David Carlisle Apr 17 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.