为什么`\texttt`会重复并缩小我的方程式?

为什么`\texttt`会重复并缩小我的方程式?

当我\texttt在方程环境中使用插入符号时amsmath,我得到了一个非常奇怪的结果。具体来说,文本在缩小时重复了四次。

梅威瑟:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
    \texttt{y^o}
\end{equation*}

\end{document}

使用编译此文档将pdflatex产生以下结果:

重复收缩

即使我删除该o字符,也会出现相同的结果。为了修复它,我可以将有问题的行修改为\texttt{y$^o$},但为什么首先会出现这种重复的情况呢?

答案1

标记应该是,\mathtt{y^{o}}因为参数的内容是数学而不是文本。

然而要解释输出。

您的文件产生

! Missing $ inserted.
<inserted text> 
                $
l.7     \texttt{y^o}

? 

您可以/应该在那里停止输入x并修复错误,但是 TeX 的界面是为处理大型文档可能要花几个小时的时代而设计的,因此最好尝试在一次运行中收集所有错误。

因此,如果您通过键入内容滚动浏览该错误s,或​​者通过命令行选项在滚动模式下运行 tex,它将尝试$通过在之前插入一个^然后继续来恢复丢失的内容。但是它的恢复(从任何错误中)只是插入需要插入的任何内容以让它继续并检查文档的语法。如果您在发生错误后获得任何 pdf 输出,它最多可用于调试,但它本质上是错误恢复的任意意外输出,

所以...s在这里输入我们得到

! Missing $ inserted.
<inserted text> 
                $
l.7     \texttt{y^o}

? s
OK, entering \scrollmode...
! Extra }, or forgotten $.
\textdef@ ...th {#1}\let \f@size #2\selectfont #3}
                                                  }
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\textdef@ ...h {#1}\let \f@size #2\selectfont #3}}

l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\text@ ...e {\textdef@ \displaystyle \f@size {#1}}
                                                  {\textdef@ \textstyle \f@s...
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.7     \texttt{y^o}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Extra }, or forgotten $.
\textdef@ ...th {#1}\let \f@size #2\selectfont #3}
                                                  }
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\textdef@ ...h {#1}\let \f@size #2\selectfont #3}}

l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\text@ ...xtstyle \f@size {\firstchoice@false #1}}
                                                  {\textdef@ \textstyle \sf@...
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.7     \texttt{y^o}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Extra }, or forgotten $.
\textdef@ ...th {#1}\let \f@size #2\selectfont #3}
                                                  }
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\textdef@ ...h {#1}\let \f@size #2\selectfont #3}}

l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\text@ ...tstyle \sf@size {\firstchoice@false #1}}
                                                  {\textdef@ \textstyle \ssf...
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.7     \texttt{y^o}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.

! Extra }, or forgotten $.
\textdef@ ...th {#1}\let \f@size #2\selectfont #3}
                                                  }
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\textdef@ ...h {#1}\let \f@size #2\selectfont #3}}

l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\text@ ...style \ssf@size {\firstchoice@false #1}}
                                                  \check@mathfonts }
l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Extra }, or forgotten $.
\text@ ...firstchoice@false #1}}\check@mathfonts }

l.7     \texttt{y^o}

I've deleted a group-closing symbol because it seems to be
spurious, as in `$x}$'. But perhaps the } is legitimate and
you forgot something else, as in `\hbox{$x}'. In such cases
the way to recover is to insert both the forgotten and the
deleted material, e.g., by typing `I$}'.

! Missing $ inserted.
<inserted text> 
                $
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing $ inserted.
<inserted text> 
                $
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing $ inserted.
<inserted text> 
                $
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing $ inserted.
<inserted text> 
                $
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing { inserted.
<to be read again> 
                   \endgroup 
l.8 \end{equation*}

A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing { inserted.
<to be read again> 
                   \endgroup 
l.8 \end{equation*}

A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing { inserted.
<to be read again> 
                   \endgroup 
l.8 \end{equation*}

A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing } inserted.
<inserted text> 
                }
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Missing $ inserted.
<inserted text> 
                $
l.8 \end{equation*}

I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.

! Display math should end with $$.
<to be read again> 
                   \endgroup 
l.8 \end{equation*}

The `$' that I just saw supposedly matches a previous `$$'.
So I shall assume that you typed `$$' both times.

因此报告了 42 个单独的错误。所有这些错误本质上都是虚假的,因为 TeX 试图通过插入来$“恢复”最初的错误,从而摆脱它所造成的困境。

\texttt(如果amsmath已加载)旨在使用\text并生成非数学文本,但下标大小正确。它\mathchoice为此使用了一个原语,但效果本质上\text{zzz}

\ifdisplaystyle
   \mbox{zzz}
\else \iftextstyle
     \mbox{zzz}
\else \ifscriptstyle
   \mbox{\scriptsize zzz}
\else
    \mbox{\scriptscriptsize zzz}
\fi\fi\fi

(使用想象\ifdisplaystyle tests

\mbox因此,在文本模式下,您在四个版本中都遇到了错误^,因此 tex 插入了错误,然后$遇到了另一个错误,因为数学运算尚未关闭。因此,您会遇到多个错误,并且当您在错误的时间退出数学运算模式时,所有四个版本都会输出。}\mbox{y$^o}

答案2

\texttt在数学模式下使用是合法的:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\makeatletter
\def\foo{\texttt{\ifx\f@size\sf@size scriptsize\else
                 \ifx\f@size\ssf@size subscriptsize\else
                 normal\fi\fi}}
\makeatother

\[
\foo_{\foo^{\foo}}
\]

% \[\mathchoice{\hbox{a^b}}{X}{Y}{Z}\]

\end{document}

在此处输入图片描述

如果你注释掉包的加载,amsmath你会得到:

在此处输入图片描述

但当然不合法的是在论证中使用数学模式而不明确再次进入数学模式。

你可以重现类似的“重复”模式,就像你观察到的那样

\[\mathchoice{\mbox{a^b}}{X}{Y}{Z}\]

在此处输入图片描述

其中所有四个参数都已排版,第一个参数由于缺少$'s 而存在错误。

没有错误\[\mathchoice{\mbox{$a^b$}}{X}{Y}{Z}\]

并最终在数学模式中amsmath加载使用。\texttt\mathchoice

相关内容