0

After @JPi answer on How to use \scalebox around my environment? and comment pointing to the question Verbatim in environ’s \BODY I tried:

  1. Writing the contents to a file
  2. Print it on verbatim mode, wrapping scalebox around it with \input

However looking over this logic, seems impossible to wrap the verbatim contents around the way I am trying to. Perhaps I missed something on the explanation at the question Verbatim in environ’s \BODY?

Thinking better, mixing the verbatim and listings packages looks pretty redundant. So we could just remove the verbatim usage from this and use solely the listings as it already does verbatim output.

Now the question would became, does listings can be put inside scalebox?

\documentclass[10pt,a5paper,twoside]{memoir}

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

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}

\usepackage{graphicx}

\makeatletter
    % Verbatim in environ’s \BODY
    % https://tex.stackexchange.com/questions/51239/verbatim-in-environ-s-body
    \RequirePackage{listings}
    \lst@RequireAspects{writefile}

    \lstnewenvironment{myenvironment}
    {
        % Write file to given filename
        \lst@BeginWriteFile{\jobname.mul}
    }
    {
        % closes output file
        \lst@EndWriteFile
        \scalebox{.2}
        {
            % Uncommenting this, throws the errors
            % \begin{verbatim}
            \input{\jobname.mul}
            % \end{verbatim}
        }
    }
\makeatother

\begin{document}
    This is normal text.

    \begin{myenvironment}
         How to make this environment be {\bfseries verbatim}?
    \end{myenvironment}

    \scalebox{.2}{This is a scale box example.}

    \begin{verbatim}
         This is a verbatim example.
    \end{verbatim}

\end{document}

enter image description here

But if I uncomment the verbatim environment arount \input{\jobname.mul} all kinds of errors are throw.

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.213     \end{myenvironment}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.213     \end{myenvironment}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.


! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.213     \end{myenvironment}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.213     \end{myenvironment}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing \endgroup inserted.
<inserted text> 
                \endgroup 
l.213     \end{myenvironment}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.213     \end{myenvironment}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.213     \end{myenvironment}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

LaTeX Font Info:    Try loading font information for T1+cmtt on input line 213.

(D:\User\Documents\latex\texmfs\install\tex\latex\base\t1cmtt.fd
File: t1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions
)
! Argument of \verbatim@ has an extra }.
<inserted text> 
                \par 
l.213     \end{myenvironment}

I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.

Runaway argument?
\input {\jobname .mul} \end {verbatim} 
! Paragraph ended before \verbatim@ was complete.
<to be read again> 
                   \par 
l.213     \end{myenvironment}

I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.

! Extra }, or forgotten \endgroup.
<recently read> }

l.213     \end{myenvironment}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten \endgroup.
\Gscale@box ...cale@y {#2}\setbox \z@ \hbox {{#3}}
                                                  \setbox \tw@ \hbox {\Gscal...
l.213     \end{myenvironment}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

Related:

  1. Using a Verbatim inside bclogo in a new environment definition
  2. How to make a new environment behave like an existing environment? (Part 2: endnotes and comments)
  3. Defining a new environment extending a verbatim environment
2

If you want to store verbatim material you need an lrbox:

\documentclass{article}

\usepackage{listings,graphicx}

\newsavebox{\mylistingbox}

\begin{document}

\begin{lrbox}{\mylistingbox}
\begin{lstlisting}
\section \textbf & %
\end{lstlisting}
\end{lrbox}

Some text \scalebox{0.5}{\usebox{\mylistingbox}}

\end{document}

enter image description here

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.