LaTeX 如何渲染 \div?

LaTeX 如何渲染 \div?

這是此問題的後續問題:如何使用 \usepackage{physicals} 來獲得「除以」符號?在引用的問題中,OP詢問如何\undef重新定義\div.我想重新發明輪子,看看精確的\div「原始碼」首先用於渲染什麼。但我可以在哪裡找到它?

這是一個 MNWE:

\documentclass{article}
\begin{document}
What is the \emph{exact} ``source code'' of
\ttfamily\textbackslash div\normalfont, and
where do I find it? Whatever it is, it renders
this: $\div$. I want to use it as a 
starting-point to \ttfamily\textbackslash
def \normalfont my own variant 
\ttfamily\textbackslash mydiv\normalfont.
\end{document}

額外問題:我該怎麼寫\ttfamily \textbackslash(上面的 MNWE 給了我一個關於「字體形狀不可用」的警告)。

答案1

假設 TeX Live 在 Unix 系統上bash,開啟一個終端機視窗並輸入

texdef -t latex div

並返回。您將得到以下資訊:

> texdef -t latex div

\div:
\mathchar"2204


\the\div:
8708

也許,對於非認知者。透過\show\div在互動式會話中執行操作或鍵入,可以發出相同的訊息

\texttt{\meaning\div}

在文件中並對其進行排版。

然而,作為\div核心數學符號,真正的定義可以在 中找到fontmath.ltx;類型

grep '\\div\b' $(kpsewhich fontmath.ltx)

終端將列印

\DeclareMathSymbol{\div}{\mathbin}{symbols}{"04}

這確實是 LaTeX 核心所做的定義\div

您可以透過執行以下操作找到所有核心數學符號定義

less $(kpsewhich fontmath.ltx)

答案2

OP 指出“我想重新發明輪子......”

我要指出的是,要製作您自己的個人版本\div,您不一定需要知道原始版本的確切表述。特別是,程式碼

\let\svdiv\div
\def\div{...\svdiv...}

\div將允許根據原始定義新的。此外,在 的情況下\div,正如約瑟夫在評論中指出的那樣,\show\div揭示了定義,\mathchar"2204表明沒有“代碼”本身對於除號,而是它僅指向字體 intself 的字形槽(數學符號字體的槽 4)。

\documentclass{article}
\usepackage{stackengine}
\begin{document}
Here is the new \textbackslash div:
\let\svdiv\div
\def\div{\mathbin{\ensurestackMath{\stackinset{c}{.002ex}{c}{-.06ex}{\circ}{\svdiv}}}}
$A \div B$
\end{document}

在此輸入影像描述

如果不想重新定義原來的內容,只想\mydiv根據原來的內容來定義,那麼:

\documentclass{article}
\usepackage{stackengine}
\begin{document}
Here is \textbackslash mydiv:
\def\mydiv{\mathbin{\ensurestackMath{\stackinset{c}{.002ex}{c}{-.06ex}{\circ}{\div}}}}
$A \mydiv B$
\end{document}

相關內容