13

I lost quite some time due to some weird error (which might possibly stem from a ragged2e bug, but I'm note sure so I won't put the blame on anyone), so I thought it would be nice to share this.

The ragged2e package defines commands such as \Centering that can replace the usual alignment commands and work in interesting contexts such as in a \pbox. However, after using \Centering dozens of times, I stumbled upon a very particular case that resulted in an error.

This works fine:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}

\begin{document}

\Centering%
Some random words.

\end{document}

However, if the text right after the \Centering command starts with “Plus” (non case-sensitive), I get a “Missing number” error:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}

\begin{document}

\Centering%
Plus some random words.

\end{document}

The problem seems to occur with other commands, such as \RaggedRight.

According to what I get with texdoc, I'm using v2.1 of ragged2e.

14

Interesting bug. The \Centering macro ends with \@raggedtwoe@everyselectfont whose definition is

% ragged2e.sty, line 191:
\newcommand{\@raggedtwoe@everyselectfont}{%
  \if@raggedtwoe@spaceskip
    \ifdim\fontdimen\thr@@\font=\z@\relax
      \spaceskip\z@
    \else
      \spaceskip\fontdimen\tw@\font
    \fi
  \else
    \spaceskip\z@
  \fi
  }

Since \spaceskip is a glue parameter, it will look forward for possible plus or minus specifications.

Fix:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{etoolbox}

\makeatletter
\appto\@raggedtwoe@everyselectfont{\relax}
\makeatother

\begin{document}

\Centering
Plus some random words.

\end{document}

The appended \relax will stop the search for glue specifications.

  • you will report the bug, won't you? – barbara beeton Dec 7 '17 at 16:50
  • @barbarabeeton Done. – egreg Dec 7 '17 at 16:56
  • 1
    Arg. Confirmed; I'll fix this. – Martin Schröder Dec 7 '17 at 22:00
11

It seems that these commands interpret the “plus” as the beginning of a “plus ⟨length⟩ minus ⟨length⟩” structure to give stretch values to a length. Adding a \relax appears to solve the problem, here.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}

\begin{document}

\Centering \relax%
Plus some random words.

\end{document}

Leaving an empty line between the command and the text might also work, but it's less compact in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.