(描述有点长,问题在底部)
我目前使用的是横线纸样式,因此需要所有内容都严格遵守横线。
我已经改变了\baselineskip
,已经删除了使用包的 itemized 环境的垂直空间enumitem
,并做了一些其他调整,所以现在纯文本和最多内联数学看起来不错。但是,显示的数学总是破坏正确的行距。我尝试了下面的代码,但这并没有真正帮助。
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
为了避免\vspace{}
每次都手动修复使用,我编写了一个“ \protectbox
”宏来产生 整数倍的行距\baselineskip
,如下所示:
\RequirePackage{calc}
\makeatletter
\newlength{\@temp@length}
\newlength{\protectboxskip}
\newcommand{\protectbox}[2][0]{% the first parameter is an offset of length, the second is the content
% measure the height of contents
\setbox0=\vbox{%
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
#2}%
\@temp@length=\ht0 \advance\@temp@length by \dp0%
% calculate the number of lines needed to place the content
\setlength{\@temp@length}{\numexpr\@temp@length/1864679\relax cm + #1\baselineskip}%
\setlength{\protectboxskip}{0.5\@temp@length}%
\vspace{\protectboxskip}%
\vspace{-0.3\baselineskip}%
\par\noindent%
\begin{minipage}[c][\baselineskip]{\linewidth}%
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
#2%
\end{minipage}%
\vspace{\protectboxskip}%
\vspace{0.3\baselineskip}%
}
\makeatother
现在我可以用来\protectbox
包围数学环境,以便跟在它后面的文本在线上处于良好的位置。
但是,有时方程式太多,我希望它能够自动应用。因此,我重新定义了equation
andequation*
环境,如下所示:
\RequirePackage{amsmath}
\RequirePackage{environ}
\let\MYequation\equation
\let\endMYequation\endequation
\RenewEnviron{equation}{%
\protectbox[-1]{%
\begin{MYequation}%
\BODY%
\end{MYequation}}%
}
\makeatletter
\RenewEnviron{equation*}{%
\protectbox[-1]{%
\begin{MYequation}%
\st@rredtrue \global\@eqnswfalse% this is copied from amsmath.sty
\BODY%
\end{MYequation}}%
}
\makeatother
这两个环境运行良好。但是,使用\[ ... \]
会产生错误(.log 文件说这是“紧急停止”,但没有详细信息)。我发现定义\[ ... \]
为
\DeclareRobustCommand{\[}{\begin{equation*}}
\DeclareRobustCommand{\]}{\end{equation*}}
因此我认为它的行为应该与完全一样equation*
,但事实并非如此。
我还尝试重新定义,$$ ... $$
因为在 markdown 中我们通常使用它来显示数学,而且我也在使用该markdown
包。代码如下所示:
\catcode`$=\active
\makeatletter
\protected\def${\@ifnextchar$\@doubledollar\@singledollar}
\def\@doubledollar$#1$${\[#1\]}
\def\@singledollar#1${\(#1\)}
\makeatother
然而编译器会抛出一个错误
Package tikz: Sorry, some package has redefined the meaning of the math-mode dollar sign. This is incompatible with tikz and its calc library and might cause unrecoverable errors.
现在终于有疑问了:
1.(最重要的)有没有更巧妙的方法来解决横格纸式对齐问题?我觉得我的对齐解决方案有点丑陋,但经过大量搜索,我没有找到其他解决方案。
2. 有没有办法将其整合\protectbox
到数学环境$$ ... $$
等中\[ ... \]
?
3.为什么可以environment*
工作但是\[ ... \]
会产生错误?
答案1
正如在这里回答的那样:我对另一个问题的回答,可以按如下方式进行:
% \protectbox<optional, space ajust>{optional, height}{content}
\newlength{\protectboxskip}
\NewDocumentCommand\protectbox{D<>{0}om}
{
\IfNoValueTF{#2}%
{% Height not given
% measure the height
\setbox0=\vbox{%
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
#3}%
\@temp@length=\ht0 \advance\@temp@length by \dp0%
% assign the height
\setlength{\@temp@length}{\numexpr\@temp@length/\baselineskip\relax\baselineskip + #1\baselineskip}%
}%
{% Height given
\setlength{\@temp@length}{#2\baselineskip-\baselineskip}%
}
\setlength{\protectboxskip}{0.5\@temp@length}%
% space above
\vspace{\parskip}%
\vspace{\baselineskip}%
\vspace*{\protectboxskip}%
\vspace*{-0.2\baselineskip}%
\vspace{-\parskip}%
\vspace{-\baselineskip}%
\par%
\noindent%
% the content
\begin{minipage}[c][\baselineskip]{\linewidth}%
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
#3%
\end{minipage}%
% space after
\vspace{\protectboxskip}%
\vspace{0.2\baselineskip}%
}
% Redefine equation and equation*
\let\equation\equation
\let\endequation\endequation
\RenewEnviron{equation}{%
\addtocounter{equation}{-1}
\protectbox<0>{%
\begin{equation}%
\BODY%
\end{equation}}%
\par\noindent%
}
\RenewEnviron{equation*}{%
\protectbox<0>{%
\addtocounter{equation}{-1}
\begin{equation}%
\st@rredtrue \global\@eqnswfalse%
\BODY%
\end{equation}}%
\par\noindent%
}
% Redefine \[...\]
\def\[#1\]{\begin{equation*}#1\end{equation*}}