(The description is kind of long, questions are at bottom)
I'm currently using a lined-paper style, thus need all the contents to be strictly sticking to the line.
I've changed the \baselineskip
, have removed the vertical space of itemized environment using enumitem
package, and have made some other adjustments, so for now pure text and most in-line math look just fine. However, the displayed math always break the correct line spacing. I tried the code below, but this isn't really helping.
\abovedisplayshortskip=0pt%
\belowdisplayshortskip=0pt%
\abovedisplayskip=0pt%
\belowdisplayskip=0pt%
To avoid manually fixing using \vspace{}
every time, I write a "\protectbox
" macro to produce line spacing of integer multiple of \baselineskip
, which looks like this:
\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
Now I can use \protectbox
to surround the math environment, so that texts following it are well positioned on the line.
However, sometimes there're so many equations that I want this to be applied automatically. Thus I redefined the equation
and equation*
environment as follows:
\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
These two environments work just fine. However, use of \[ ... \]
will produce an error (the .log file says it's an "emergency stop", but there's no detail). I find out that \[ ... \]
is defined by
\DeclareRobustCommand{\[}{\begin{equation*}}
\DeclareRobustCommand{\]}{\end{equation*}}
Thus I think it should behave exactly like the equation*
, but it's not.
I also tried to redefine the $$ ... $$
since in markdown we usually use this for displayed math and I'm also using the markdown
package. The code looks like this:
\catcode`$=\active
\makeatletter
\protected\def${\@ifnextchar$\@doubledollar\@singledollar}
\def\@doubledollar$#1$${\[#1\]}
\def\@singledollar#1${\(#1\)}
\makeatother
However the compiler throws an error
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.
Now finally the questions:
1. (The most important) Is there some cleverer way to solve the lined-paper-style alignment problem? I think my solution for alignment is somewhat ugly, but after a lot of searching, I did not find other solutions.
2. Is there some way to integrate the \protectbox
into math environments $$ ... $$
, \[ ... \]
, etc?
3. Why does environment*
work but \[ ... \]
produce errors?