5

I use XeTeX, Version 3.1415926-2.4-0.9998 (TeX Live 2012/W32TeX).

I want to create a nested list without hyphenation. I am using the sloppypar environment with hyphenation command to turn off hyphenation. This creates issues when used with a nested numbered list created using enumerate. In the MWE below, the second item in the outer list is not numbered, while the first item in the second inner list has the combined number 2(a). The nested list works fine without sloppypar as the second section below shows.

\documentclass{article}
\usepackage{ragged2e}
\usepackage{polyglossia}
\begin{document}
\section{Nested list with sloppypar}
\begin{enumerate}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}
\end{enumerate}

\section{Nested list without sloppypar}
\begin{enumerate}
\item Blah blah blah.
\begin{enumerate}
    \item Blah blah blah.
    \item Blah blah blah.
\end{enumerate}
\item Blah blah blah.
\begin{enumerate}
    \item Blah blah blah.
    \item Blah blah blah.
\end{enumerate}
\end{enumerate}
\end{document}
1
  • Somewhat off-topic: You may want to look into updating your TeX distribution from TeXLive2012 to TeXLive2015. XeTeX and the polyglossia package, in particular, have evolved quite a bit over the past three years.
    – Mico
    Commented Jul 10, 2015 at 0:04

3 Answers 3

3

Just add a \par or blank line leaving the nested enumerate environment.

\documentclass{article}
\usepackage{ragged2e}
\usepackage{polyglossia}
\begin{document}
\section{Nested list with sloppypar}
\begin{enumerate}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}\par % <----- ADDED PAR IS HERE
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}
\end{enumerate}

\section{Nested list without sloppypar}
\begin{enumerate}
\item Blah blah blah.
\begin{enumerate}
    \item Blah blah blah.
    \item Blah blah blah.
\end{enumerate}
\item Blah blah blah.
\begin{enumerate}
    \item Blah blah blah.
    \item Blah blah blah.
\end{enumerate}
\end{enumerate}
\end{document}

enter image description here

As I tell the OP in the comments below, I cannot give a definitive answer as to why the \par is needed. But the symptom of the original MWE gave the appearance of a misinterpreted paragraph/group issue. So it was a natural first guess, and in this case, it proved sufficient.

Alternately, the nested enumerate could be enclosed in its own group, as follows:

\documentclass{article}
\usepackage{ragged2e}
\usepackage{polyglossia}
\begin{document}
\section{Nested list with sloppypar}
\begin{enumerate}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
{\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\begin{enumerate}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
    \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah blah.\end{sloppypar}
\end{enumerate}
\end{enumerate}
\end{document}
2
  • Works, could you also please explain why a par is needed?
    – user22209
    Commented Jul 9, 2015 at 18:18
  • @user22209 I cannot give a definitive answer as to why the \par is needed. But the symptom of your original MWE gave the appearance of a misinterpreted paragraph issue. So it was a natural first guess, and in this case, it proved sufficient. Alternately, one could have enclosed the nested enumerate in its own group { } and that too would have worked. Commented Jul 9, 2015 at 18:24
2

In a list environment, the action of \item is deferred when a paragraph is started. And \begin{sloppypar} starts with \par, which confuses this mechanism.

Here's a minimal example that emulates what sloppypar does: \par at the beginning, some other actions that don't concern the issue, and \par at the end.

\documentclass{article}

\newenvironment{foo}{\par}{\par}

\begin{document}

\begin{enumerate}
  \item \begin{foo}x\end{foo}
  \begin{enumerate}
    \item \begin{foo}x\end{foo}
  \end{enumerate}
  \item \begin{foo}x\end{foo}
  \begin{enumerate}
    \item \begin{foo}x\end{foo}
  \end{enumerate}
\end{enumerate}

\end{document}

enter image description here

As you see, the problem is exactly the same.

I'm not sure about the need of \justifying in your document, but in my opinion you should define a wrapper environment:

\documentclass{article}

\usepackage{polyglossia}

\usepackage{kantlipsum} % for mock text

\newenvironment{sloppyenumerate}
 {\begin{enumerate}\sloppy\hyphenrules{nohyphenation}}
 {\end{enumerate}}

\begin{document}

\begin{sloppyenumerate}
\item \kant[2]
\begin{enumerate}
    \item \kant[3]
\end{enumerate}
\item \kant[4]
\begin{enumerate}
    \item \kant[5]
\end{enumerate}
\end{sloppyenumerate}

\end{document}

If you need to selectively use \sloppy for some of the items, don't use sloppypar:

\newenvironment{sloppyitem}
 {\sloppy\hyphenrules{nohyphenation}}
 {\par}% <--- the \par here is fundamental

and use

\item \begin{sloppyitem}text\end{sloppyitem}
1

While Steven's answer certainly solves your problem, the way you are marking up your document is not ideal. You can simplify everything a lot with the following:

\usepackage{etoolbox}
\AtBeginEnvironment{enumerate}{\sloppy\hyphenrules{nohyphenation}}

Compare (and comment out the \AtBeginEnvironment line to see the difference):

\documentclass{article}
\usepackage[vmargin=1cm]{geometry}
\usepackage{ragged2e}
\usepackage{polyglossia}
\def\bb{I want to create a nested list withouthyphenation. Iamusingthesloppyparenvironmentwithhyphenationcommandtoturnoffhyphenation. This creates issues when used with a nested numbered list created using enumerate. In the MWE below, the second item in the outer list is not numbered, while the first item in the second inner list has the combined number 2(a). The nested list works fine without sloppypar as the second section below shows.}

\usepackage{etoolbox}


\begin{document}

\bb

\section{Nested list with sloppypar}
\begin{enumerate}
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}\bb \end{sloppypar}
  \begin{enumerate}
  \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}\bb
      blah blah.\end{sloppypar}
  \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah
      blah blah.\end{sloppypar}
  \end{enumerate}\par
\item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah blah
    blah.\end{sloppypar}
  \begin{enumerate}
  \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}Blah
      blah blah.\end{sloppypar}
  \item \begin{sloppypar}\justifying\hyphenrules{nohyphenation}\bb \end{sloppypar}
  \end{enumerate}
\end{enumerate}

\section{Nested list without sloppypar}

\AtBeginEnvironment{enumerate}{\sloppy\hyphenrules{nohyphenation}}
\begin{enumerate}
\item \bb
  \begin{enumerate}
  \item \bb
  \item Blah blah blah.
  \end{enumerate}
\item Blah blah blah.
  \begin{enumerate}
  \item Blah blah blah.
  \item \bb
  \end{enumerate}
\end{enumerate}

\bb

\end{document}

The .tex file is much easier to read in the second case.

image of no hyphenation

2
  • not tested with this example, but many times in tugboat i have put \begin{sloppypar} just once before \begin{enumerate} (or even, in a similar situation, before \section), and a single \end{sloppypar} after the matching \end{enumerate}. or around several \items. just because the command name has par in it doesn't mean it must be limited to a single paragraph. just make sure all environments and brace groups are balanced. Commented Jul 9, 2015 at 21:14
  • @barbarabeeton -- Well, I suspect your use of \sloppy and equivalent was quite judicious. My answer was really only meant to point out that the amount of "manual" markup in the question was pretty extreme (and therefore both error-prone and more difficult to maintain). Ideally, the OP just wants to do it for one or two \items, and not for whole environments at a time....
    – jon
    Commented Jul 9, 2015 at 23:48

You must log in to answer this question.

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