1

I'm getting the error Package enumitem: Undefined label with the following code:

\documentclass{article}

\usepackage[french,english]{babel}

\usepackage{enumitem}
\setlistdepth{10}
\renewlist{itemize}{itemize}{10}

\setlist[itemize]{label=$\cdot$}

\setlist[itemize,1]{label=\textbullet}
\setlist[itemize,2]{label=--}
\setlist[itemize,3]{label=*}

\begin{document}

\selectlanguage{french}

\begin{itemize}
    \item {\selectlanguage{english} Test}
    \item Text
\end{itemize}

\end{document}

Is there any way to fix this?

6
  • You're misusing \selectlanguage. Use otherlanguage* or \foreignlanguage.
    – egreg
    Commented Apr 17, 2022 at 21:01
  • @egreg What is the difference here? I thought that putting \selectlanguage in a group is the same as using \foreignlanguage.
    – Jinwen
    Commented Apr 17, 2022 at 21:03
  • No, it's not the same. In the particular case, it's babel-french kicking in, but that's secondary.
    – egreg
    Commented Apr 17, 2022 at 21:05
  • @egreg Sorry, I don't quite understand, could you please explain in more detail? Actually I've always been using \selectlanguage in group for locally changing the language, and this is the first time I encountered an error. And it only happens when I'm trying to extend the number of levels of itemize.
    – Jinwen
    Commented Apr 17, 2022 at 21:17
  • Don't use \selectlanguage for locally change language. Never. It's just that simple.
    – egreg
    Commented Apr 17, 2022 at 21:22

1 Answer 1

2

A language switch can set and reset lots of things. french for example stores and then restore the itemize labels

\documentclass{article}

\usepackage[french,english]{babel}

\begin{document}


\selectlanguage{french}

\renewcommand\labelitemi{--}
\begin{itemize} 
    \item Text
    \item Text
\end{itemize}

\selectlanguage{english} 

\begin{itemize}
    \item Text
    \item Text
\end{itemize}


\end{document}

enter image description here

Such changes are often (as here) not local but global changes. This means that if you change the language with \selectlanguage in the middle of a list you are confusing LaTeX quite heavily. Use \selectlanguage with care.

3
  • I fully agree with @Ulrike. Nevertheless, in that precise example, English being the main language, babel-french does not alter the list layout at all, so there is no need to store/restore lists' settings when switching languages… I'll try to fix this asap. Commented Apr 18, 2022 at 14:25
  • @DanielFlipo yes I wondered about that, but even if you fix it: selectlanguage is not a local command. Commented Apr 18, 2022 at 14:44
  • @UlrikeFisher of course \selectlanguage is not local, but its misuse here reveals something wrong in babel-french which needs to be fixed. Commented Apr 18, 2022 at 17:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .