diff options
Diffstat (limited to 'macros/latex/contrib/medmath/medmath.sty')
-rw-r--r-- | macros/latex/contrib/medmath/medmath.sty | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/macros/latex/contrib/medmath/medmath.sty b/macros/latex/contrib/medmath/medmath.sty new file mode 100644 index 0000000000..af6f93165a --- /dev/null +++ b/macros/latex/contrib/medmath/medmath.sty @@ -0,0 +1,110 @@ +% -*- coding: utf-8 -*- +% ---------------------------------------------------------------------------- +% Author: Jianrui Lyu <tolvjr@163.com> +% License: The LaTeX Project Public License 1.3c +% ---------------------------------------------------------------------------- + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{medmath}[2024-01-11 v2024B Fix mediummath option in nccmath package] + +\RequirePackage{array} +\RequirePackage{etoolbox} + +\newif\ifmdm@enabled \mdm@enabledtrue % enable medmath fixes +\newif\ifmdm@amsfonts \mdm@amsfontsfalse % use ams symbol fonts + +\DeclareKeys{ + mdm@enabled .if = mdm@enabled, + mdm@amsfonts .if = mdm@amsfonts +} + +\ProcessKeyOptions + +\RequirePackage[mediummath]{nccmath} + +\newcommand{\my@do@medmath}{% + %% Adjust \oiint operator + \ifdef{\oiint}{% + \let\NCC@op@oiint=\oiint + \DeclareRobustCommand{\oiintop}{\mathop{\medmath{\NCC@op@oiint}}}% + \def\oiint{\DOTSI\NCC@op@prepare{\oiintop}}% + }{}% + %% Setting \medintcorr parameter + %% We have used relative dimensions later, so no need to set it anymore + %\ifmdm@amsfonts + % \medintcorr{0.5em} + %\else + % \medintcorr{0.3em} + %\fi + %% The definite integrals in cases environment may cause infinite loops + %% Our redefinition moves \quad to the beginning of the second columns + %% Therefore removing extra spaces when there is only one column in it + \renewenvironment{cases}{% + \left\{\linespread{1.0}\selectfont\def\arraystretch{1.2}% + \begin{array}{@{}l@{}>{\quad}l@{}}% + }{% + \end{array}\right.% + }% + %% Right skip is missing when minipage or \parbox has only a displayed formula + %% Other problems could be found here: http://tex.stackexchange.com/q/22170 + \let\start@gather=\NCC@startgather + \let\start@align=\NCC@startalign + \let\start@multline=\NCC@startmultline + \let\mathdisplay=\NCC@startdisplay +} + +\newcommand{\my@do@medmath@fix}{% + %% Fix sizes of non integral operators in superscripts/subscripts + %% We use the method in scalerel package for saving math styles + % big operator in normal text is 80% of the size of \displaystyle + % big operator in script is 80% of the size of \textstyle + % big operator in script script is 80% of the size of \scriptstyle + \def\@my@style@D{\displaystyle}% + \def\@my@style@T{\displaystyle}% + \def\@my@style@S{\textstyle}% + \def\@my@style@s{\scriptstyle}% + \def\my@style@saved{\csname @my@style@\@my@style@switch\endcsname}% + \newcommand{\my@style@this}[1]{% + \mathchoice{\def\@my@style@switch{D}##1}{\def\@my@style@switch{T}##1} + {\def\@my@style@switch{S}##1}{\def\@my@style@switch{s}##1}% + }% + \DeclareRobustCommand*\medmath[1]{\NCC@select@msize + \mathord{\my@style@this{\raise\@tempdima\hbox{\NCC@prepare@msize$\my@style@saved ##1$}}}% + } + %% Fix sizes of integral operators in superscripts/subscripts + \newlength{\@my@em}% + \setlength{\@my@em}{1em}% + \ifmdm@amsfonts + \medintcorr{0.5\@my@em}% + \else + \medintcorr{0.3\@my@em}% + \fi + \newcommand{\my@style@unit}[1]{% + \mathchoice{\setlength{\@my@em}{1em}##1}{\setlength{\@my@em}{1em}##1} + {\setlength{\@my@em}{0.5em}##1}{\setlength{\@my@em}{0.3em}##1}% + }% + \let\my@saved@op@printm=\NCC@op@printm + \def\NCC@op@printm{\my@style@unit{\my@saved@op@printm}}% + %% Fix fractions and subfractions in superscripts/subscripts + %% Always use current style size to typeset the fractions + \newcommand{\my@larger@frac}[2]{% + \mathchoice{\genfrac{}{}{}{0}{##1}{##2}}{\genfrac{}{}{}{0}{##1}{##2}}% + {\genfrac{}{}{}{1}{##1}{##2}}{\genfrac{}{}{}{2}{##1}{##2}}% + }% + \DeclareRobustCommand{\frac}[2]{% + \mathchoice{\mfrac{##1}{##2}}{\mfrac{##1}{##2}}% + {\my@larger@frac{##1}{##2}}{\my@larger@frac{##1}{##2}}% + }% + \patchcmd{\NCC@prepare@msize}{% + \def\frac{\protect\NCC@innerfrac{}}% + }{% + \let\frac=\my@larger@frac + }{}{}% +} + +\AtBeginDocument{% + \ifmdm@enabled + \my@do@medmath \my@do@medmath@fix + \fi +} + |