如何使用 listing 包使 \scalebox 内的新环境逐字逐句?

如何使用 listing 包使 \scalebox 内的新环境逐字逐句?

@JPi回答如何在我的环境中使用 \scalebox?并评论指出这个问题环境中的 \BODY 中的逐字内容我试过:

  1. 将内容写入文件
  2. 以逐字模式打印,scalebox并用\input

然而,从这个逻辑来看,似乎不可能按照我试图的方式将逐字逐句的内容包裹起来。也许我错过了问题解释中的一些内容环境中的 \BODY 中的逐字内容

仔细想想,混合使用verbatimlistings包看起来是多余的。所以我们可以verbatim从中删除用法,只使用,listings因为它已经可以逐字输出。

现在的问题是,listings可以放进去吗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

但是如果我取消注释周围的逐字环境,就会引发\input{\jobname.mul}各种错误。

! 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$}'.

有关的:

  1. 在新的环境定义中使用 bclogo 中的 Verbatim
  2. 如何使新环境表现得像现有环境?(第 2 部分:尾注和评论)
  3. 定义一个扩展 verbatim 环境的新环境

答案1

如果你想存储逐字材料你需要一个 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

相关内容