LyXDifficulty in maths exercises

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

Difficulty in maths exercises

Post by fsolana87 »

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.

Code: Select all

\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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10359
Joined: Mon Mar 10, 2008 9:44 pm

Difficulty in maths exercises

Post by Stefan Kottwitz »

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:

Code: Select all

\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
LaTeX.org admin
Post Reply