![独立多环境与 \newlstenvironment](https://linux22.com/image/352728/%E7%8B%AC%E7%AB%8B%E5%A4%9A%E7%8E%AF%E5%A2%83%E4%B8%8E%20%5Cnewlstenvironment.png)
大概是由于处理的副作用verbatim
,该listings
软件包提供了\newlstenvironment
。不幸的是,生成的环境无法与standalone
的多选项配合使用。
可以通过删除\standaloneenv{maxpage}
或替换(失去逐字效果)\newlstenvironment
来运行以下内容。\newenvironment
\documentclass{standalone}
\usepackage{listings}
\lstset{aboveskip=0pt,belowskip=0pt}
\lstnewenvironment{maxpage}{\setbox0=\hbox\bgroup}{\egroup\usebox0}
\standaloneenv{maxpage}% or [multi=maxpage]
\begin{document}
\begin{maxpage}
This is a test.
\textbullet $\sin x^2$
And it has more than one line.
In fact, it goes on and on and on and on and on and on and on until is extends quite far.
\end{maxpage}
\end{document}
有没有办法让两者协同工作?
答案1
人们总是可以使用两个环境,一个用于逐字,一个用于多重。
\documentclass[multi=wrapper]{standalone}
\usepackage{listings}
\lstset{aboveskip=0pt,belowskip=0pt}
\newenvironment{wrapper}{}{}
\lstnewenvironment{maxpage}{\setbox0=\hbox\bgroup}{\egroup\usebox0}
\begin{document}
\begin{wrapper}
\begin{maxpage}
This is a test.
\textbullet $\sin x^2$
And it has more than one line.
In fact, it goes on and on and on and on and on and on and on until is extends quite far.
\end{maxpage}
\end{wrapper}
\end{document}