有没有办法覆盖 LaTeX 关于双下标和上标的错误?

发布于 2024-09-02 19:59:32 字数 300 浏览 8 评论 0原文

关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

几味少女 2024-09-09 19:59:32

以下是你所希望的

\catcode`\^ = 13 \def^#1{\sp{#1}{}}
\catcode`\_ = 13 \def_#1{\sb{#1}{}}

The following is what you wish

\catcode`\^ = 13 \def^#1{\sp{#1}{}}
\catcode`\_ = 13 \def_#1{\sb{#1}{}}
北恋 2024-09-09 19:59:32

这是您真正应该被警告的情况之一,并且必须按照您想要的方式放置大括号 - 或者编写没有双下标/上标的内容,如果这就是您的意思。一般来说,当您使用上标表示求幂而不是索引时,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 mean a^{bc}, but how's LaTeX to know? And for subscripts, what if you really do mean a_{n_k}, not a_{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.)

左岸枫 2024-09-09 19:59:32

虽然Alexeys的答案应该是被接受的——它完全符合作者想要的——让我注意到还有Latex可用的软件包正是这样做的,最值得注意的是 Tensor 软件包 可以做到这一点:

张量包的屏幕截图Documentation

您为第一个示例编写 \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:

Screenshot from the tensor package documentation

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文