要求 Latex 更努力地不要將內聯數學拆分為多行

要求 Latex 更努力地不要將內聯數學拆分為多行

當我的內聯數學被分解為多行時,我不喜歡它。必要時我會忍受它,但我寧願它沒有發生,即使這意味著有時理由會更糟。我希望將這一點傳達給乳膠。

如果是文字,我會將其設定\hyphenpenalty為更大的值。我不確定這是否適用於數學,但無論如何我不想改變它的文字,只是為了數學。

例子:

\documentclass{article}
\begin{document}
    \begin{minipage}{3.8cm}
    Recall that the meaning of
    $P( w_j \mid w_i)$  is actually  that 
    $P(W_j{=}w_j \mid W_i {=} w_i)$.
    By not using softmax, with its normalising denominator this means that we expect that:
    $\sum_{\forall w_j \in V} P(w_j \mid w_i) \neq 1$ (except by coincidence).
    \end{minipage}
\end{document}

輸出:

輸出不大

這不太好,看看可以放在一行中的數學如何分解為兩行?

如果我手動換行會更好:

更好但仍然不是很好

(更好的是可以稍微改寫,但這超出了 Latex 的能力:-D)

答案1

您可以將不希望被拆散的東西放入盒子中。當然,這是手動幹預,但在這種情況下可能是最好的。

\documentclass{article}
\begin{document}
    \begin{minipage}{3.8cm}
    Recall that the meaning of
    \mbox{$P( w_j \mid w_i)$}  is actually  that 
    \mbox{$P(W_j{=}w_j \mid W_i {=} w_i)$}.
    By not using softmax, with its normalising denominator this means that we expect that:
    \mbox{$\sum_{\forall w_j \in V} P(w_j \mid w_i) \neq 1$} (except by coincidence).
    \end{minipage}
\end{document}

在此輸入影像描述

請注意,框中的內容不會因邊距限製而受到任何擴展或壓縮。因此,如果\mbox從第一個數學物件中刪除它們,則內部數學間距將被調整以符合邊距約束。

夾子:

在此輸入影像描述

或者\nobreak也可用於手動防止數學中斷。在這裡,在第二個數學元素\nobreak之後添加一個\mid即可解決所有問題......暫時。但在這裡或那裡添加另一個詞,你將不得不重新幹預。

\documentclass{article}
\begin{document}
    \begin{minipage}{3.8cm}
    Recall that the meaning of
    $P( w_j \mid w_i)$  is actually  that 
    $P(W_j{=}w_j \mid\nobreak W_i {=} w_i)$.
    By not using softmax, with its normalising denominator this means that we expect that:
    $\sum_{\forall w_j \in V} P(w_j \mid w_i) \neq 1$ (except by coincidence).
    \end{minipage}
\end{document}

在此輸入影像描述

答案2

數學模式下的自動換行由參數\relpenalty和控制\binoppenalty。僅在關係符號或二元運算符號之後或在使用者插入的明確懲罰處才可以中斷。

您可以透過設定(可能是本機群組)來完全禁止自動換行

\relpenalty=10000
\binoppenalty=10000

然後您可以使用\linebreak\nolinebreak連同適當的可選參數一起指定可行的換行符。

如果您設定的值小於 10000,則換行不太理想。預設值分別為 500 和 700。

答案3

在此輸入影像描述

\documentclass{article}

\begin{document}
    \begin{minipage}{3.8cm}%\RaggedRight
    Recall that the meaning of
    $P( w_j{\mid}w_i)$ is actually that
    \mbox{$P(W_j{=}w_j{\mid}W_i{=}w_i)$}.
    By not using softmax, with its normalising denominator this means that we expect that:
    \mbox{$\sum_{\forall w_j \in V} P(w_j{\mid}w_i) \neq 1$} (except by coincidence).
    \end{minipage}
\end{document}

在狹窄的環境中使用合理的環境會導致解決方案不美觀。看看使用RaggedRightfromraged2e包是否可以接受:

\documentclass{article}
\usepackage{ragged2e}
\begin{document}
    \begin{minipage}{3.8cm}\RaggedRight
    Recall that the meaning of
    $P( w_j{\mid}w_i)$ is actually that
    \mbox{$P(W_j{=}w_j{\mid}W_i{=}w_i)$}.
    By not using softmax, with its normalising denominator this means that we expect that:
    \mbox{$\sum_{\forall w_j \in V} P(w_j{\mid}w_i) \neq 1$} (except by coincidence).
    \end{minipage}
\end{document}

在此輸入影像描述

答案4

我能想到的最簡單的解決方案是將指令插入\raggedrightminipage.在狹窄的專欄中,試圖充分證明材料的合​​理可能會產生相當大且沒有吸引力的詞間間隙。最好透過呼叫放棄理由\raggedright,這也會抑制連字符以及內聯數學​​材料內的換行。

在此輸入影像描述

\documentclass{article}
\begin{document}
\begin{minipage}{3.8cm}
    \raggedright
    Recall that the meaning of
    $P(w_j \mid w_i)$  is actually  that 
    $P(W_j=w_j \mid W_i = w_i)$.
    By not using softmax, with its normalising denominator 
    this means that we expect that:
    $\sum_{\forall w_j \in V} P(w_j \mid w_i) \neq 1$ 
    (except by coincidence).
\end{minipage}
\end{document}

相關內容