答案1
一个独立于引擎的解决方案(尽管我对此仍有一种模糊的感觉......)
\documentclass[12pt]{article}
\let\originalmiddle=\middle
\def\middle#1{\mathrel{}\originalmiddle#1\mathrel{}}
\begin{document}
\[
(A \mid B)
\left(A \middle| B\right)
\left(\frac{A}{B} \middle\Vert C_{(A \mid B) \left( A \middle| B \right)} \right)
\]
\end{document}
答案2
您可以使用一些 Lua 魔法。
以下三个代码片段是一个文件。它们之所以被拆分,是因为 Stack Exchange 不支持混合突出显示。
\documentclass{article}
\usepackage{luacode}
\begin{luacode*}
local noad_id = node.id("noad")
local fence_id = node.id("fence")
local inner_subtype = 9 -- see texnodes.w
local middle_subtype = 2 -- see texnodes.w
local function is_vert(delim)
return delim.small_fam == 2
and delim.small_char == 106
and delim.large_fam == 3
and delim.large_char == 12
end
local kern = node.new("kern",99) -- 99 = math kern
kern.kern = 5 * 2^16 -- 5 pt (TODO: load this value from the font)
local function adjust_mid_spacing(head)
for n in node.traverse(head) do
if n and n.nucleus and n.nucleus.head then
adjust_mid_spacing(n.nucleus.head)
elseif n.id == fence_id and n.subtype == middle_subtype then
if is_vert(n.delim) then
node.insert_before(head,n,node.copy(kern))
node.insert_after(head,n,node.copy(kern))
end
end
end
return head
end
luatexbase.add_to_callback("mlist_to_hlist",
function(head, display_type, need_penalties)
head = adjust_mid_spacing(head)
return node.mlist_to_hlist(head, display_type, need_penalties)
end,
"adjust spacing around mid")
\end{luacode*}
\begin{document}
$\left( A \middle| B \right)_{\left( A \middle| B \right)_{\left( A \middle| B \right)}}$
$(A \mid B)_{(A \mid B)_{(A \mid B)}}$
\end{document}