浮動機制的錯誤或功能

浮動機制的錯誤或功能

如果我輸入$\section{Second section}$

\begin{enumerate}
\item first bla bla 
\item second bla bla
$\item last bla bla$
\end{enumerate}

我收到錯誤訊息! Missing $ inserted...! LaTeX Error: Command \item invalid in math mode.

但是,如果我編譯以下程式碼,我會得到(正確的)輸出,但可以說是字串輸出。

\documentclass{article}
\usepackage{lipsum}

\begin{document}
\section{First section}
\lipsum[1]
\begin{table}
\section{Second section}
\caption{Just a table}
\end{table}
\begin{enumerate}
\item first bla bla
\item second bla bla
\begin{table}
\item last bla bla
\caption{Just a table}
\end{table}
\end{enumerate}
\section{Last section}
\lipsum[1]

\end{document}

在此輸入影像描述

這是一個錯誤嗎?浮動物件可以去(任何地方),例如 an\item位於前面的物品之前,或更糟的是在 another 的專案內enumerate

這是一個功能嗎?編號仍然正確,人們可能需要這個。

主要問題:為什麼乳膠不能阻止\section, \item, ... 命令進入浮動環境,我們知道,相反,這\caption在浮動環境之外不起作用。就是為什麼沒有

\gdef\@infloaterr#1{%
   \relax
   \ifx\@captype\@undefined
   \else
 \@latex@error{Command \protect#1  inside float}
   \fi}

如同\@inmatherr

答案1

有許多不正確的輸入不會產生錯誤訊息。 (\section[z]{\section{aa}}例如)。

\section浮點數內部是一個錯誤,它只是不被系統捕獲(在乳膠設計時,這樣做會花費不合理的內存量。)

數學/非數學的區別是內建在 tex 中的,測試它比每個命令測試每個沒有意義的地方要容易得多。

同樣,\caption需要知道要製作什麼類型的標題(內部儲存在 中\@captype),因此那裡的測試要容易得多,因為預設定義是它會產生錯誤,\caption僅在啟用標題的上下文中本地工作。

相關內容