1

Tried to found solution by myself but didn't find nothing certain, I'm still not very good in LaTeX. I have code which works well.

\documentclass[14pt]{extreport}
\usepackage[normalem]{ulem}

\newcommand\s{\nobreak \hskip\fill \allowbreak \space \hskip-\fill \relax}

\begin{document}
\hfill\begin{minipage}[t]{0.7\textwidth}
\begin{flushleft}
\obeyspaces\let =\s
Lorem:~\uline{ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\hfill}
\end{flushleft}
\end{minipage}
\end{document}

But after I try to move \obeyspaces\let =\s command to environment header

\documentclass[14pt]{extreport}
\usepackage[normalem]{ulem}

\newcommand\s{\nobreak \hskip\fill \allowbreak \space \hskip-\fill \relax}

\newenvironment{under}
{\obeyspaces\let =\s}
{}

\begin{document}
\hfill\begin{minipage}[t]{0.7\textwidth}
\begin{flushleft}
\begin{under}
Lorem:~\uline{ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\hfill}
\end{under}
\end{flushleft}
\end{minipage}
\end{document} 

I'm getting an error

! Missing control sequence inserted. <inserted text> \inaccessible l.13 \begin{under}

How can I fix it?

3

You have to use an active space in the instruction

\let =\s

which can be done with the \lowercase trick, see The \lowercase trick. The problem is that in

\newenvironment{under}
  {\obeyspace\let =\s}
  {}

the space is not active which it is in the “expanded” code because there \obeyspaces is executed prior to \let. In the \newenvironment, \obeyspaces is only stored and doesn't act until the environment is called.

\documentclass[14pt]{extreport}
\usepackage[normalem]{ulem}

\newcommand\spaceinunder{\nobreak \hskip\fill \allowbreak \space \hskip-\fill \relax}

\begingroup\lccode`~=` \lowercase{\endgroup
  \newenvironment{under}
  {\obeyspaces\let~=\spaceinunder}
  {}
}

\begin{document}
\hfill\begin{minipage}[t]{0.7\textwidth}
\begin{flushleft}
\begin{under}
Lorem:~\uline{ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\hfill}
\end{under}
\end{flushleft}
\end{minipage}
\end{document} 

enter image description here

A perhaps better definition:

\documentclass[14pt]{extreport}
\usepackage[normalem]{ulem}

\newcommand\spaceinunder{%
  \nobreak\hspace{\fill}\allowbreak\space\hspace{-\fill}\relax
}

\begingroup\lccode`~=` \lowercase{\endgroup
  \newenvironment{under}[1]
  {%
   \begin{flushright}
   \begin{minipage}[t]{#1}\raggedright
   \obeyspaces\let~=\spaceinunder
  }
  {\end{minipage}\end{flushright}}
}

\begin{document}
\begin{under}{0.7\textwidth}
Lorem:~\uline{ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.\hfill}
\end{under}
\end{document} 
  • It's works well as it is. But how can I do the same when I will write Lorem:~\uline{\ftext \stext labore et dolore magna aliquyam erat, sed diam voluptua.\hfill} where \newcommand\ftext{ipsum dolor sit amet,} \newcommand\stext{consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut} – Konstantin Jan 15 '18 at 3:50

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.