ulem with hspace error

The following code

\documentclass{minimal}
\usepackage{ulem}
\begin{document}
\emph{\hspace*{2in}}
\end{document}


used to work without error, to produce an underlined blank space of width 2 inches. Now with a brand new MikTeX installation, I get the following error

! Extra }, or forgotten \endgroup.
\UL@stop ...alty \ifnum \lastkern =\thr@@ \egroup
\egroup \ifdim \wd \UL@box...
l.4 \emph{\hspace*{2in}}


Here are the file dates, etc.

This is pdfTeX, Version 3.14159265-2.6-1.40.21 (MiKTeX 21.1) (preloaded format=pdflatex 2021.2.7)  7 FEB 2021 13:50
entering extended mode
**./untitled-2.tex
(untitled-2.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-01-09> xparse <2020-03-03>
("C:\Program Files\MiKTeX\tex/latex/base\minimal.cls"
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
) ("C:\Program Files\MiKTeX\tex/latex/ulem\ulem.sty"
\UL@box=\box47
\UL@hyphenbox=\box48
\UL@skip=\skip47
\UL@hook=\toks15
\UL@height=\dimen138
\UL@pe=\count177
\UL@pixel=\dimen139
\ULC@box=\box49
Package: ulem 2019/11/18
\ULdepth=\dimen140
)
("C:\Program Files\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def"
File: l3backend-pdftex.def 2021-01-09 L3 backend support: PDF output (pdfTeX)
\l__kernel_color_stack_int=\count178
\l__pdf_internal_box=\box50
)

• For TeXLive users, this works in 2020, but is broken in 2021
– Alec
Jun 17, 2021 at 16:47

Update

With a current LaTeX (LaTeX2e <2021-06-01> patch level 1) the patch is no longer needed.

The \hspace command has been extended to allow calculations if the calc package is loaded. ulem hasn't updated its code yet to this change (but the maintainer has been informed). The needed patch would be something like this:

\documentclass{article}
\usepackage{calc}
\usepackage{ulem}
\makeatletter
\def\@hspace#1{\begingroup\setlength\skip@{#1}%
\edef\x{\endgroup\hskip\the\skip@\relax}\x}%
\makeatother %return @ to normal meaning
\begin{document}

\emph{\hspace*{2in+1cm}}
\end{document}


• What does this patch actually do, and do I need to worry about \hspace usage elsewhere?
– Alec
Jun 17, 2021 at 16:46
• @Alec with a current latex you no longer need the patch. And normally it should work, unless some package does (like ulem) something special. Jun 17, 2021 at 16:50
• I built TeXLive 2021 today, and this is still happening with ulem
– Alec
Jun 17, 2021 at 16:51
• The fix is very new, so you need to check for updates, most importantly of the firstaid package. Jun 17, 2021 at 16:53

The \emph{} command is for italicizing, You use \underline{} for underlining. The following MWE generates the blank space you're after on my machine. You must have redefined \emph{} in another document or something.

\documentclass{minimal}

\begin{document}

\underline{\hspace{2 in}}

\end{document}

• Thanks but your response isn't exactly on point. I wasn't asking how to create an underlined blank space, though I agree your code does that. I was reporting an error. The code above worked for years and exists in scores of exams, quizzes, etc. of mine (actually my wife's). The ulem package redefines \emph to create underlines, and the above code worked with that package for years. Now it throws an error. Unless there's a reason why it was always "against the rules" so to speak to wrap ulem's redefined emph around an hspace, the code should still work. Feb 7, 2021 at 20:18
• I'm sorry, I didn't fully understand what the ulem package was doing before.
– Will
Feb 7, 2021 at 22:03

I am not sure what changed. However, if you use a \kern rather than the \hspace*, it works.

\documentclass{article}
\usepackage{ulem}
\begin{document}
x\emph{\kern2in}x
\end{document}