## LaTeX forum ⇒ LyX ⇒ Difficulty in maths exercises

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
fsolana87
Posts: 1
Joined: Thu Jul 15, 2021 11:26 pm

### Difficulty in maths exercises

I'm trying to write a math book and I'd like to be able to graduate the difficulty of the maths problems and exercises. Writing this code I've found on the web on the preamble I can do it by writing latex code on the LyX text.
\let\svitem\item
\newcommand\difbox[1]{\stackengine{0pt}{\color{gray!30}\rule{5ex}{1.15ex}}{%
\color{cyan!60!black}$\mkern1mu\makeballs{#1}$}{O}{c}{F}{F}{L}}
\def\makeballs#1{\ifnum#1>0\relax{\bullet}%
\expandafter\makeballs\the\numexpr#1-1\relax\fi}
\newenvironment{benumerate}
{\renewcommand\item[1][1]{\def\difficulty{##1}\svitem}%
\def\labelenumi{\smash{\stackunder[1pt]{\color{cyan!60!black}%
\bfseries\sffamily\theenumi}{\difbox{\difficulty}}}}%
\enumerate}{\endenumerate}

I'd like to know if it's possible to create a local layout for selecting the new style and not using the latex commands. I've tried, but I'm in troubles withe the parameter that receives the benumerate environment created on the code above. Could anyone help me?
Thanks.

Stefan Kottwitz
Posts: 9733
Joined: Mon Mar 10, 2008 9:44 pm
Hi,

welcome to the forum!

You could adjust the original enumerate environment, so you can use it in the normal LyX way. Here in a LaTeX document, so we can directly run the code in the forum:

\documentclass{article}
\usepackage{stackengine}
\usepackage{xcolor}
\usepackage{etoolbox}
\let\svitem\item
\newcommand\difbox[1]{\stackengine{0pt}{\color{gray!30}\rule{5ex}{1.15ex}}{%
\color{cyan!60!black}$\mkern1mu\makeballs{#1}$}{O}{c}{F}{F}{L}}
\def\makeballs#1{\ifnum#1>0\relax{\bullet}%
\expandafter\makeballs\the\numexpr#1-1\relax\fi}

\AtBeginEnvironment{enumerate}
{\renewcommand\item[1][1]{\def\difficulty{#1}\svitem}%
\def\labelenumi{\smash{\stackunder[1pt]{\color{cyan!60!black}%
\bfseries\sffamily\theenumi}{\difbox{\difficulty}}}}}

\begin{document}
\begin{enumerate}
\item[1] Easy
\item[2] Medium
\item[3] Hard
\end{enumerate}
\end{document}

Stefan