在 LaTeX 中创建新环境的问题 [英] Problem with creating a newenvironment in LaTeX

查看:17
本文介绍了在 LaTeX 中创建新环境的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 LaTeX 中实现这个新环境:

I am trying to implement this new environment in LaTeX:


ewenvironment{javacode}[2]
{egin{lstlisting}[language=java, label=#1, caption=#2]}
{end{lstlisting}}

然后像这样使用它:

egin{javacode}{c}{some code}
int x = 5;
end{javacode}

但我收到以下错误:

Overfull hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1] [2]) [3])
*

谁能帮忙解决这个问题?

Can anyone help as regards fixing this problem?

[更新]

我试过这样做 红鼻子独角兽 指示,并且它工作正常.

I tried it doing it like Red-nosed unicorn instructed, and it worked correctly.

但现在我尝试像这样添加 egin{singlespace}:

But now I tried adding a egin{singlespace} like such:

lstnewenvironment{javacode}[2]
{
egin{singlespace}
lstset{language=java, label=#1, caption=#2}}
{
end{singlespace}
}

我得到了同样的错误:

Overfull hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1]) [2] [3])
*

推荐答案

经过进一步研究,我发现了这个http://www.tug.org/pipermail/texhax/2009-June/012699.html

Upon further research, I found this http://www.tug.org/pipermail/texhax/2009-June/012699.html

要解决我的解决方案,我需要使用 singlespace 而不是 singlespace 环境.

To workaround my solution, I need to use singlespacing instead of the singlespace environment.

以下是我的工作代码:

lstnewenvironment{javacode}[2]
{singlespacinglstset{language=java, label=#1, caption=#2}}
{}

这篇关于在 LaTeX 中创建新环境的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆