有没有办法覆盖 LaTeX 关于双下标和上标的错误?
关于 LaTeX 的一个让我困扰的小问题。当一个人在写作
a^b^c, a_b_c
或
a'^b
数学模式下时,LaTeX 会给出一条错误消息,抱怨有多个上标/下标。在替换包含上标/下标的字符串或使用撇号 '
时,这尤其令人烦恼。
有没有办法覆盖错误并让 LaTeX 简单地输出
a^{bc} a_{bc} {a'}^b
等等?
Minor point about LaTeX that bothers me. When one writes
a^b^c, a_b_c
or
a'^b
in math mode, LaTeX gives an error message complaining about multiple super/subscripts. This is particularly annoying after replacing a string containing a super/subscript or when using the apostrophe, '
.
Is there a way to override the error and have LaTeX simply output
a^{bc} a_{bc} {a'}^b
and so on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是你所希望的
The following is what you wish
这是您真正应该被警告的情况之一,并且必须按照您想要的方式放置大括号 - 或者编写没有双下标/上标的内容,如果这就是您的意思。一般来说,当您使用上标表示求幂而不是索引时,
a^b^c = a^{b^c}
,因此您描述的输出在某些情况下肯定是不正确的。当然,如果它们是上标索引,您可能指的是a^{bc}
,但是 LaTeX 如何知道呢?对于下标,如果您确实指的是a_{n_k}
,而不是a_{nk}
,该怎么办? (即双索引与索引序列)(当然,如果这作为替换的一部分出现,您可能可以找到一种方法来修复它作为替换的一部分。)
This is one of those cases where you really should be warned, and have to place the braces the way you want them - or write something without a double sub/superscript, if that's what you mean. Generally, when you're using superscript to indicate exponentiation, not indexing,
a^b^c = a^{b^c}
, so the output you describe is definitely incorrect in some cases. Sure, if they're superscript indices, you might meana^{bc}
, but how's LaTeX to know? And for subscripts, what if you really do meana_{n_k}
, nota_{nk}
? (that is, double-indexing vs. a sequence of indices)(And of course, if this crops up as part of a substitution, you can probably figure out a way to fix it as part of the substitution.)
虽然Alexeys的答案应该是被接受的——它完全符合作者想要的——让我注意到还有Latex可用的软件包正是这样做的,最值得注意的是 Tensor 软件包 可以做到这一点:
您为第一个示例编写
\Gamma\indices{^\mu_{\nu\rho}}
。相反,使用 Alexeys 答案,您只需编写\Gamma^\mu_{\nu\rho} 显然更短。但是,catcode 对
^
和_
字符的重新定义将破坏这些字符在常规文本中的出现,这很烦人,尤其是在数学模式之外。While Alexeys answer should be the acceppted one -- it does exactly what the author wants -- let me note there are also Latex packages available doing exactly this, most notably the Tensor package can do this:
You write
\Gamma\indices{^\mu_{\nu\rho}}
for the first example. In contrast, with Alexeys answer you just can write\Gamma^\mu_{\nu\rho}
which is obviously shorter. However, the catcode redefinition of the^
and_
characters will break any occurence of these characters in regular text which is annoying especially outside of math mode.