2010-01-08 68 views
4

我想定義一個新的命令這樣乳膠新的命令

\newcommand{\bob}[1]{\excerpt \begin{lstlisting} {#1} \end{lstlisting}} 

,然後使用它像這樣

\bob{abcd} 

,但我得到了以下錯誤乳膠。

text dropped after begin of listing latex 

編輯:

我嘗試以下

\newcommand{\boy}[1] {{% 
\begin{Verbatim} % 
{ #1 } % 
\end{Verbatim} }} 

,當我嘗試使用它我還得到一個錯誤。

\boy{abc} 

回答

4

也許您在尋找\newenvironment macro

在這種情況下,你會使用這樣

\newenvironment{bob}{% 
\excerpt \begin{lstlisting}}{% 
\end{lstlisting}} 

後來

\begin{bob} 
abcd 
\end{bob} 
1

{listing}環境特殊而神奇;它不能在這樣的命令中使用。如dmckee所述,更改爲\newenvironment設置應該可行。如果您無法完成這項工作,請查看fancyvrb包裝。

+0

我試過了fancyvrb,它沒有幫助解決問題:-( – Milhous 2010-01-13 15:51:51

1

嘗試列表包的lstnewenvironment。