Enumerate with enumitem and \newcommand macro

1,051

enumitem expects a key-value sequence and therefore doesn't expand the optional argument that is supplied. If you're sold on using this interface, you need to make sure that enumitem receives an expanded version of what you supply.

Below I've redefined enumerate to expands its optional argument. I've also opted to use a different way of printing \APLbox using an \fbox with invisible horizontal and vertical struts (zero-width \rules):

enter image description here

\documentclass{article}

\usepackage[inline, shortlabels]{enumitem}

\renewcommand{\labelenumi}{(\textrm{\arabic{enumi}})}
\renewcommand{\labelenumii}{\alph{enumii})}

\usepackage{wasysym,letltxmacro}

\newcommand{\mybigbox}{\APLbox}
\newcommand{\mybox}{\APLbox}

\setlength{\fboxsep}{0pt}
\newcommand{\BoxArabicEnum}{(1) \protect\fbox{\protect\rule{.55em}{0pt}\protect\rule{0pt}{.7em}}}
%\renewcommand{\BoxArabicEnum}{(1) \protect\APLbox}

\LetLtxMacro\oldenumerate\enumerate
\let\endoldenumerate\endenumerate
\makeatletter
\renewenvironment{enumerate}[1][]
  {\begingroup\protected@edef\x{\endgroup\noexpand\begin{oldenumerate}[#1]}\x}
  {\end{oldenumerate}}
\makeatother

\begin{document}

First enumerate:
\begin{enumerate}[ \BoxArabicEnum ]
  \item a
  \item b
  \item c
\end{enumerate}

Second enumerate:
\begin{enumerate}[ (1) \APLbox ]
  \item a
  \item b
  \item c
\end{enumerate}

\end{document}
Share:
1,051

Related videos on Youtube

Rustam
Author by

Rustam

Updated on August 01, 2022

Comments

  • Rustam
    Rustam over 1 year
    % !TeX spellcheck = he_IL
    \documentclass[titlepage=false,12pt,titlepage]{scrreprt}
    
    %\pagenumbering{roman}
    
    \usepackage{ucs}   %  unicode support
    \usepackage[utf8x]{inputenc}
    \usepackage[T1]{fontenc}
    %-----
    \usepackage{anyfontsize}
    \usepackage{t1enc}
    
    \usepackage[english,russian,hebrew]{babel}
    
    \usepackage{helvet}
    \renewcommand{\familydefault}{\rmdefault}
    
    
    
    \usepackage[inline, shortlabels]{enumitem}
    
    \renewcommand{\labelenumi}{)\textrm{\arabic{enumi}}(}
    \renewcommand{\labelenumii}{\alph{enumii}(}
    
    
    \setlist{topsep = 2 pt, partopsep = 1 pt, parsep = 0 pt, itemsep = 2 pt}
    
    
    
    \usepackage{graphicx}
    \usepackage{wasysym}
    
    
    
    
    \newcommand{\mybigbox}{\APLbox}
    \newcommand{\mybox}{\APLbox}
    %------------------------------------------------------
    
    \newcommand{\BoxArabicEnum}{)1( \APLbox}
    
    
    \usepackage[left= 1cm, right= 1.5 cm, top=1cm,bottom=1 cm, footskip=0.5cm]{geometry}
    
    
    \begin{document}
    
    \L{First enumerate:}
    \begin{enumerate}[ \BoxArabicEnum ]
    
    \item  
    a
    \item
    b
    \item
    c
    \end{enumerate}
    
    \L{Second enumerate:}
    
    \begin{enumerate}[ )1( \APLbox ]
    
    \item  
    a
    \item
    b
    \item
    c
    \end{enumerate}
    
    \end{document}
    

    %----------------------------------

    And here is the result:

    Result of compilation

    Questions: Why "First enumerate:" is different from "Second enumerate:" and how to cause user-defined command \BoxArabicEnum to produce the same result as direct substitution )1( \APLbox ?

    • Admin
      Admin almost 8 years
      I can't compile your example due to hebrew, but the main culprit is that )1( isn't recognized as a format inside of an macro when using shortlabels as an enumitem. Since that package is sophisticated, it's not necessary to screw up the labelenumi etc. macros with \renewcommand statements, just use label=...
    • Rustam
      Rustam almost 8 years
      Thank you, but this is not an answer, because I want to reproduce "\begin{enumerate}[ )1( \APLbox ]" with help of command \BoxArabicEnum only in certain places.
    • Admin
      Admin almost 8 years
      It is an answer, but providing another solution ;-)
    • Admin
      Admin almost 8 years
      You can use the label= each time you want to have or define a special enumerate list using newlist
    • Rustam
      Rustam almost 8 years
      Sorry, but this is a bad solution, because in this case I should define several new enumerate lists.
    • Admin
      Admin almost 8 years
      Ok, your decision then -- You're using 1% of the features of enumitem only and complain about a 'bad solution' -- I leave it to others and we won't meet again.