在环境中包装 LaTeX 命令 [英] wrap LaTeX command in environment

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

问题描述

如何在环境中包装 LaTeX 命令?本质上,我怎样才能把 somecommand{contents} 变成 egin{somecommand} 内容 end{somecommand}?我已经尝试了明显的方法来创建这样的新环境:

How can I wrap a LaTeX command in an environment? In essence, how can I turn somecommand{contents} into egin{somecommand} contents end{somecommand}? I have tried the obvious in creating a new environment as such:


ewenvironment{somecommand}[0]{
  somecommand{
}
{
  }
}

但这会导致大括号出现问题.让我举一个更具体的例子.假设您想创建非常重要的环境,并且您想使用命令 emph 来完成此操作.一个简单(但不正确)的解决方案是将一些东西写成

but this causes problems with the curly brackets. Let me give a more concrete example. Say that you want to create the environment very-important and you want to use the command emph to accomplish this. An straightforward (but incorrect) solution would be to write something as


ewenvironment{very-important}[0]{
  emph{
}
{
  }
}

这里的问题是该命令与在环境中找到的信息一起工作,因此它不是环境的打开命令之一,也不是环境的关闭命令.那么问题来了:你怎么能做到这一点?

The problem here is that the command works with the information that is found inside the environment, so it is not one of the opening commands of the environment, nor is it a closing command of the environment. The question is then: how can you do this?

推荐答案

现在好像能猜到是什么问题了.

It seems that now I can guess what is the question.


ewenvironment{very-important}{startimportant}{}
defstartimportant#1end{emph{#1}end}

egin{very-important}
Something
end{very-important}

此解决方案效果很好.但是恕我直言,将所有文本包装在环境中是个坏主意.为什么?有两种方法可以处理文本.例如,您想更改字体并使用斜体.

This solution works well. But IMHO it is bad idea to wrap all text in the environment. Why? There are two ways to do something with the text. For example, you want to change the font and use italic.

  • 第一种方法. extit{斜体字}
  • 第二种方法.{it 用斜体写的句子/}

有什么区别?问题是第一种方法使用第二种方法.it 宏更改字体,大括号 } 将其更改回来. extit 宏读取完整的参数,更改字体并再次插入参数: extit 大致定义如下(不完全).

What is the difference? The thing is that first method use the second one. it macro changes the font and the brace } changes it back. extit macro reads the full argument, changes the font and inserts the argument again: extit is defined roughly as follows (not exactly).

def	exit#1{{it#1/}}

第一种方法总是做额外的工作.它读取参数两次.几乎总是,您可以进行更改,然后您可以恢复一切.

The first method is always doing extra work. It reads the argument twice. Almost always, you can make changes and then you can everything back.

最终你为什么要使用环境?使用宏.

Eventually why do you use the environment? Use macros.

veryimportant{
   Any thought
}

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

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