如何自动删除左上标的撇号引入的额外空格?

如何自动删除左上标的撇号引入的额外空格?

我需要使用左上标。我知道有mathtoolstensor和 这样的包leftidx。但它们都存在相同的排版问题。

如果我排版左上标,并且该上标的右侧附加有撇号、星号或类似符号,则左上标会从其基本符号移开。LaTeX 确实会引入这个间隙,因为 LaTeX 认为它需要这个额外的空间来容纳左上标的右上标,但它并没有这样做,因为实际上这两个符号不会互相干扰。

问题可视化

下面是一个 MWE:

\documentclass{article} 
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}


% Symbol for Turing machine and Oracle
\newcommand{\tmF}{\mathcal{F}}
\newcommand{\oO}{\mathcal{O}}

% Left superscript, copied from "leftidx"-package
% How to improve this command?
\newcommand{\append}[2]{{\protect\vphantom{#1}}^{#2}\!#1}

% Code from: https://www.tug.org/TUGboat/tb22-4/tb72perlS.pdf
\def\mathrlap{\mathpalette\mathrlapinternal}
\def\mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}}

\setlength{\fboxsep}{0pt}
\setlength{\fboxrule}{0.25pt}

\begin{document}

\section{Problem visualization}

\begin{itemize}
  \item This looks OK: $\append{\tmF}{\oO}$
  \item This looks typographically wrong: $\append{\tmF}{\oO'}$
  \item This looks better: $\append{\tmF}{\oO\mathrlap{'}}$
\end{itemize}

\section{Problem visualization with boxes}

\begin{itemize}
  \item This looks OK: $\append{\fbox{$\tmF$}}{\fbox{$\oO$}}$
  \item This looks typographically wrong: $\append{\fbox{$\tmF$}}{\fbox{$\oO$}'}$
  \item This looks better: $\append{\fbox{$\tmF$}}{\fbox{$\oO$}\mathrlap{'}}$
\end{itemize}

\end{document}

append的工作原理如下:首先,基本符号排版为不可见,这样如果基本符号本身的高度不同,则后面的上标会移动到正确的高度。然后引入一个小的负空间来填补数学模式下两个连续名词符号之间的正常空间。最后排版实际的基本符号。

我通过手动告诉 LaTeX 撇号不带空格来生成印刷正确的版本。但我不想使用,\mathrlap而更喜欢一个append可以自动计算出需要多少额外空间的宏。

答案1

当然,“视觉空洞”取决于符号的相对形状。你可以删除\scriptspace左侧上标,这样可以减少间隙。

在产品版本中您当然会在 的定义中将其更改\trylength\z@(即 0pt)\app@@nd

\documentclass{article} 
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}


% Symbol for Turing machine and Oracle
\newcommand{\tmF}{\mathcal{F}}
\newcommand{\oO}{\mathcal{O}}

% Left superscript, copied from "leftidx"-package
% How to improve this command?
\makeatletter
\DeclareRobustCommand{\append}[2]{%
  \mathpalette\app@nd{{#1}{#2}}#1%
}
\newcommand{\app@nd}[2]{\app@@nd#1#2}
\newcommand{\app@@nd}[3]{%
  \mbox{\scriptspace\trylength\m@th$#1{\vphantom{#2}}^{#3}$}%
}
\newdimen\trylength
\makeatother

% Code from: https://www.tug.org/TUGboat/tb22-4/tb72perlS.pdf
\def\mathrlap{\mathpalette\mathrlapinternal}
\def\mathrlapinternal#1#2{\rlap{$\mathsurround=0pt#1{#2}$}}

\setlength{\fboxsep}{-0.25pt}
\setlength{\fboxrule}{0.25pt}

\begin{document}

\section{Normal scriptspace}
\trylength=\scriptspace
\begin{itemize}
  \item $\append{\tmF}{\oO}$ $\append{\mathcal{H}}{\oO}$
  \item $\append{\tmF}{\oO'}$ $\append{\mathcal{H}}{\oO'}$
  \item $\append{\fbox{$\tmF$}}{\fbox{$\scriptstyle\oO$}}$
  \item $\append{\fbox{$\tmF$}}{\fbox{$\scriptstyle\oO'$}}$
\end{itemize}

\section{Zero scriptspace}
\trylength=0pt
\begin{itemize}
  \item $\append{\tmF}{\oO}$ $\append{\mathcal{H}}{\oO}$
  \item $\append{\tmF}{\oO'}$ $\append{\mathcal{H}}{\oO'}$
  \item $\append{\fbox{$\tmF$}}{\fbox{$\scriptstyle\oO$}}$
  \item $\append{\fbox{$\tmF$}}{\fbox{$\scriptstyle\oO'$}}$
\end{itemize}

\end{document}

在此处输入图片描述

相关内容