Hello (and sorry for the englishmarmelade),
I try to define a environment exercise. I would like to define the label automatically.
Why ? First and unique goal is to see in my structure faster where is my exercice and how many exercice of this type i have.
My code :
\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
%--hyperref
\usepackage[pdfborder={0 0 0}]{hyperref} %pour que les références soient des liens hypertextes
%\usepackage{charter} %Modif des polices : charter, newcent, mathptmx, mathpple...
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
%------Operation math et latex
\usepackage{etoolbox}
\newcounter{exo}
\makeatletter
\newenvironment{exo}[1]%
{\refstepcounter{exo}%
\protected@edef@currentlabelname{#1}% addition here
\vspace{0.5cm}\noindent
\fbox{
{\large\bfseries{Exercice \theexo~: #1} \par}\label{#1}
{\par\vspace{0.5cm}}}}
\makeatother
\begin{document}
\begin{exo}{type}
Derivate this function $f(x)=x$
\end{exo}
\end{document}
First problem : It works (i can use \ref) but i don't see it on my structure view (i use texmaker) and that was my goal.
Comment : The editor can't see the label inside an environment So that's not the way.
Second problem : If type is empty i have an error because \label wait an information
Idea : How to solve this with an ifempty
'''
\ifx&%
% #1 is empty
\label{theexo}
\else
% #1 is nonempty
\label{#1}
\fi
'''
Another try : Changing \subsection to use it as exercise but not sur it's a good solution.
Thank you for all the help.
Ange

\documentclass ...etc.? Thank you – MS-SPO Jan 17 '24 at 16:33\labeldo? – Teepeemm Jan 17 '24 at 17:16hyperrefshould be loaded last unless you know a package must be loaded later (and there are very few such packages). – cfr Jan 17 '24 at 18:35\typeout{Exercise on page \thepage.}at the start of each environment. You can also define a counter, and add to the counter each time the environment is used, then typeout the value at end document. – rallg Jan 17 '24 at 19:03