我希望有一个命令\catlim
在内联模式和显示模式下的行为有所不同。也就是说,在内联模式下,它应该等同于,\lim
而在显示模式下,它应该等同于\varprojlim
(或它的某个更好的版本)箭头位于限制下方。以下是结果应为的示例:
% arara: lualatex
\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\begin{document}
Inline \(\lim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}\) and display:
\begin{equation*}
\varprojlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}.
\end{equation*}
\end{document}
答案1
由于您使用的是 LuaTeX,因此您可以简单地查询\mathstyle
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\newcommand\catlim{%
\ifcase\mathstyle
% 0 = \displaystyle
\expandafter\varprojlim
\or
% 1 = \crampeddisplaystyle
\expandafter\varprojlim
\else
% all other styles
\expandafter\lim
\fi}
\begin{document}
Inline \(\catlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}\) and display:
\begin{equation*}
\catlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}.
\end{equation*}
\end{document}
答案2
当您明确重置数学样式时,不清楚您想要做什么。以下解决方案需要amsmath
但也适用于“经典”排版引擎,它会根据开关进行区分\if@display
。这会故意忽略数学样式(\displaystyle
与其他样式),并决定使用哪个命令(\varprojlim
与其他样式\lim
),仅考虑公式是否以内联方式显示或排版。
我坚持认为,从你的问题中无法明确看出你认为这是一个错误还是一个功能。另请参阅@daleif 的评论。
代码:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{mathtools} % also loads "amsmath"
\usepackage{amsfonts}
\makeatletter
\newcommand*\catlim{%
\relax\if@display
\expandafter\varprojlim
\else
\expandafter\lim
\fi
}
\makeatother
\newcommand*{\numberset}[1]{\mathbb{#1}}
\newcommand*{\N}{\numberset{N}}
\newcommand*{\Z}{\numberset{Z}}
\begin{document}
In line:
\( \catlim_{i\in\N} \Z/p^{i}\Z \).
In line, but with \verb|\displaystyle|:
\( \displaystyle \catlim_{i\in\N} \frac{\Z}{p^{i}\Z} \).
In display:
\[
\catlim_{i\in\N} \frac{\Z}{p^{i}\Z}
\]
In display, but with \verb|\textstyle|:
\[
\textstyle \catlim_{i\in\N} \Z/p^{i}\Z
\]
An example with \texttt{cases} (starred version requires the
\textsf{mathtools} package):
\[
G =
\begin{cases*}
\catlim_{i\in\N} \frac{\Z}{p^{i}\Z} & first case \\
\catlim_{i\in\N} \frac{\Z}{q^{i}\Z} & second case
\end{cases*}
\]
Note how the fraction is typeset: this too shows that
\verb|\textstyle| is in force.
\end{document}
打印输出: