1

I learnt from resizebox doesn't respect linebreaks? that \resizebox contents had to be wrapped in a minipage to get newlines; indeed, it works:

\resizebox{20em}{!}
  {\begin{minipage}{10em}
     lorem\\
     ipsum\\
     tex.stackexchange
   \end{minipage}}  

And it works with \par, as well:

\resizebox{20em}{!}
  {\begin{minipage}{10em}
     lorem\par
     ipsum\par
     tex.stackexchange
   \end{minipage}}

But not with \obeylines? What gives?

\resizebox{20em}{!}
  {\begin{minipage}{10em}
     \obeylines{}
     lorem
     ipsum
     tex.stackexchange
   \end{minipage}}

How can I use \obeylines in a \resizebox?

Clément
  • 4,004
  • 3
    \obeylines is similar to \verb and doesn't work in any command argument. Just put it before the \resizebox – David Carlisle Aug 10 '16 at 08:11
  • Isn't \obeylines just a catcode change? Why doesn't that work in a command with arguments? I ran into this problem because an environment that I use calls \obeylines, and I can't really move that outside of the environment :/ In any case, please make this an answer, and I'll be happy to accept it :) – Clément Aug 10 '16 at 08:41
  • @it's because they are a catcode change that obeylines and verb do not work in command arguments – David Carlisle Aug 10 '16 at 08:45
  • Got it. Thanks for explaining :) I wonder how listings, fancyvrb, and the like do it, then. Don't they use catcode changes to preserve spaces, lines, etc? – Clément Aug 10 '16 at 09:02
  • yes and listings has the same restrictions as verb, it can't be used in the argument of another command. – David Carlisle Aug 10 '16 at 10:25

1 Answers1

2

You need to change the setup before the argument is scanned:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

{\obeylines\resizebox{20em}{!}%
  {\begin{minipage}{10em}%
     lorem
     ipsum
     tex.stackexchange
   \end{minipage}}}
\end{document}}
David Carlisle
  • 757,742