\caption 中的 \iffalse 不完整,但在常规文本中正确。\if 在哪里?

\caption 中的 \iffalse 不完整,但在常规文本中正确。\if 在哪里?

我正在尝试创建一个新的字符作为$\bot$和的叠加=,如下所示:

在常规环境中使用命令 <code>\disjointcompl</code>

由于某种原因,与常规环境不同,它在 \caption 环境中不起作用。哪里出了问题;冲突的 \if 语句在哪里?

\documentclass[a4paper,11pt,oneside,oldfontcommands]{memoir}
\usepackage{amsmath}    

% Disjoint & complete (\disjointcompl) character, as a superimpose of \bot and = .
\newcommand{\disjointcompl}{%
  \mathrel{
    \vphantom{=}\text{
      \mathsurround=0pt\ooalign{
        $\bot$\cr\raisebox{-0.89ex}{$=$}\cr
      }
    }
  }
}

\begin{document}
The disjoint \& complete context is denoted as $\disjointcompl$  

\begin{figure}
  \caption{A correspondence over a \emph{disjoint class context}. The current  context is defined as \( \disjointcompl  \)}
\end{figure}

\end{document}

此代码会产生以下错误:

! Incomplete \iffalse; all text was ignored after line 19.
<inserted text> 
                \fi 

而删除标题中的 则\disjointcompl可使代码运行并生成上面的图片。

答案1

问题在于,您的定义使其成为一个脆弱的命令,如果在移动参数(标题或章节标题)中使用,则\disjointcompl必须加上前缀。\protect

您可以使用\DeclareRobustCommand以避免该问题。

这是对您的命令的修改定义,它适用于标题,并且将等号的顶部栏精确叠加到的栏上\bot

\documentclass[a4paper,11pt,oneside,oldfontcommands]{memoir}
\usepackage{amsmath}    

% Disjoint & complete (\disjointcompl) character, as a superimpose of \bot and = .
\DeclareRobustCommand{\disjointcompl}{%
  \mathrel{\text{%
    \mathsurround=0pt
    \vtop{\offinterlineskip
      \ialign{##\cr
        $\bot$\cr
        \noalign{\kern-0.1ex}
        $=$\cr
      }
    }%
  }}%
}

\begin{document}
The disjoint \& complete context is denoted as
$\disjointcompl_{\disjointcompl_{\disjointcompl}}$

\begin{figure}[htp]
  \caption{A correspondence over a \emph{disjoint class context}. The current  context is defined as \( \disjointcompl  \)}
\end{figure}

\end{document}

在此处输入图片描述

放大版

在此处输入图片描述

相关内容