\leq、\le、\leqslant 和 LuaLaTeX

\leq、\le、\leqslant 和 LuaLaTeX

\leq我在使用 LuaLaTeX替换时遇到了问题\leqslant(使用 PdfLaTeX 时没有遇到这个问题)。

以下是 MWE:

\documentclass[10pt,a4paper,french]{article}

\usepackage{mathtools}
\usepackage{babel}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},math-style=french]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage[scale={0.75,0.8},footskip=1.5cm,heightrounded]{geometry}


\RenewDocumentCommand{\leq}{}{\leqslant}%modification du <=


\begin{document}
    \[x\leq 3\]
\end{document}

以下是我得到的结果:

在此处输入图片描述

<= 符号没有改变。

但是,如果我输入:

\documentclass[10pt,a4paper,french]{article}

\usepackage{mathtools}
\usepackage{babel}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},math-style=french]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage[scale={0.75,0.8},footskip=1.5cm,heightrounded]{geometry}


\RenewDocumentCommand{\le}{}{\leqslant}%modification du <=


\begin{document}
    \[x\le 3\]
\end{document}

以下是我得到的结果:

在此处输入图片描述

我不明白,因为我认为\le\leq完全一样。而且在我的所有文档(有很多)中,我都使用了\leq

答案1

您可能希望所有不等式都使用倾斜变体,逐个重新定义它们可能很繁琐。许多 Unicode 数学字体都有一次性完成所有操作的选项(这些选项称为“样式集”)。不幸的是,NewComputerModern您使用的默认字体没有此功能。您可以建议维护者添加它或切换到其他字体。

字体示例Erewhon

\documentclass[10pt,a4paper,french]{article}
\usepackage{mathtools}
\usepackage{babel}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},
            math-style=french]{unicode-math}
\usepackage[StylisticSet=4]{fourier-otf}
%\usepackage[Style=leqslant]{fourier-otf}% Same output
\usepackage[scale={0.75,0.8},footskip=1.5cm,heightrounded]{geometry}
\begin{document}
  \[x\leq 3, y\leqq 4, z\ngeq 5, t\eqless 6\]
\begin{document}

将打印

在此处输入图片描述

答案2

Unicode 对 ≤ 和 ⩽ 有不同的代码点

≤ U+2264 小于或等于
⩽ U+2A7D 小于或倾斜等于

其他相关符号也类似。

如果你这样做\ShowCommand{\le}\begin{document}你会看到

> \le=\protected macro:
->\leq .

\ShowCommand{\leq}你一起得到

> \leq=the character ≤.

\ShowCommand{\leqslant}得到

> \leq=the character ⩽.

你应该这样做

\documentclass[10pt,a4paper,french]{article}

\usepackage{mathtools}
\usepackage{babel}
\usepackage[
  warnings-off={mathtools-colon,mathtools-overbracket},
  math-style=french
]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage[scale={0.75,0.8},footskip=1.5cm,heightrounded]{geometry}

\AtBeginDocument{%
  \RenewCommandCopy{\leq}{\leqslant}%
  \RenewCommandCopy{\le}{\leq}%
}


\begin{document}

\[x\leq 3 \qquad x \le 3\]

\end{document}

\geq您还需要对和\ge以及需要倾斜的其他不等式符号执行类似操作。

从 开始unicode-math-table,但并非所有带有斜线的符号都有不带斜线的对应符号。

\UnicodeMathSymbol{"02A7D}{\leqslant                 }{\mathrel}{less-than or slanted equal to}%
\UnicodeMathSymbol{"02A7E}{\geqslant                 }{\mathrel}{greater-than or slanted equal to}%
\UnicodeMathSymbol{"02A7F}{\lesdot                   }{\mathrel}{less-than or slanted equal to with dot inside}%
\UnicodeMathSymbol{"02A80}{\gesdot                   }{\mathrel}{greater-than or slanted equal to with dot inside}%
\UnicodeMathSymbol{"02A81}{\lesdoto                  }{\mathrel}{less-than or slanted equal to with dot above}%
\UnicodeMathSymbol{"02A82}{\gesdoto                  }{\mathrel}{greater-than or slanted equal to with dot above}%
\UnicodeMathSymbol{"02A83}{\lesdotor                 }{\mathrel}{less-than or slanted equal to with dot above right}%
\UnicodeMathSymbol{"02A84}{\gesdotol                 }{\mathrel}{greater-than or slanted equal to with dot above left}%
\UnicodeMathSymbol{"02A93}{\lesges                   }{\mathrel}{less-than above slanted equal abov
e greater-than above slanted equal}%
\UnicodeMathSymbol{"02A94}{\gesles                   }{\mathrel}{greater-than above slanted equal a
bove less-than above slanted equal}%
\UnicodeMathSymbol{"02A95}{\eqslantless              }{\mathrel}{slanted equal to or less-than}%
\UnicodeMathSymbol{"02A96}{\eqslantgtr               }{\mathrel}{slanted equal to or greater-than}%
\UnicodeMathSymbol{"02A97}{\elsdot                   }{\mathrel}{slanted equal to or less-than with
 dot inside}%
\UnicodeMathSymbol{"02A98}{\egsdot                   }{\mathrel}{slanted equal to or greater-than w
ith dot inside}%
\UnicodeMathSymbol{"02A9B}{\eqqslantless             }{\mathrel}{double-line slanted equal to or le
ss-than}%
\UnicodeMathSymbol{"02A9C}{\eqqslantgtr              }{\mathrel}{double-line slanted equal to or gr
eater-than}%
\UnicodeMathSymbol{"02AA8}{\lescc                    }{\mathrel}{less-than closed by curve above slanted equal}%
\UnicodeMathSymbol{"02AA9}{\gescc                    }{\mathrel}{greater-than closed by curve above slanted equal}%
\UnicodeMathSymbol{"02AF9}{\leqqslant                }{\mathrel}{double-line slanted less-than or equal to}%
\UnicodeMathSymbol{"02AFA}{\geqqslant                }{\mathrel}{double-line slanted greater-than or equal to}%

答案3

Lua 代码可以在字体级别工作:定义您自己的自定义字体功能,包括字形替换。

負責

平均能量损失

\documentclass{article}
\directlua{
fonts.handlers.otf.addfeature {
name = "leqs",
type = "substitution",
data = {
["≤"] = "uni2A7D",
}
}
}

\usepackage{unicode-math}
\setmathfont{texgyretermes-math.otf}[RawFeature=+leqs]

\begin{document}
 
  \[ x \leq 3 \]
\end{document}

编辑

为了在 Lua 中实现更完整的查找表,定义自定义替代样式字体功能。

请注意,字体 TeX Gyre Termes - Math 缺少一些字形。

字体功能

平均能量损失

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{unicode-math}


\directlua{
fonts.handlers.otf.addfeature{
    name = "saltineq",
    type = "alternate",
    data =
    {
      ["≤"] = "⩽", %-- \leqslant
                ["≥"] = "⩾", %-- \geqslant
            ["⋜"] = "⪕", %-- \eqslantless
            ["⋝"] = "⪖", %-- \eqslantgtr
                ["⪙"] = "⪛", %-- \eqqslantless
                ["⪚"] = "⪜", %-- \eqqslantgtr
                ["≦"] = "⫹", %-- \leqqslant
            ["≧"] = "⫺", %-- \geqqslant
    },
  }
}  

    \setmainfont[
        RawFeature={+saltineq},
    ]{XITS-Regular.otf}

    \setmathfont{texgyretermes-math.otf}[
%        RawFeature={+saltineq},
    ]
    

\ExplSyntaxOn

% Adapted from:
%https://tex.stackexchange.com/questions/654839/how-to-detect-if-a-unicode-character-has-been-defined
\NewDocumentCommand{\cg} { m }
 {
  \wb_checkunicode:nnn { #1 } { #1 } { 
                    {\color{red}
                        \textrm{
                        #1
                        }
                    }}
 }
 
\cs_new_protected:Nn \wb_checkunicode:nnn
 {
  \cs_if_exist:cTF { u8:\tl_to_str:n { #1 } } { #2 } { #3 }
 }
\ExplSyntaxOff
 
 
   
\begin{document}


\addfontfeature{RawFeature={-saltineq}}


\begin{longtblr}[caption={Without feature},
remark{Note}={Text = XITS; Math = TeX Gyre Termes - Math.},
]{
colspec={Q[r]Q[c]Q[c]Q[c]Q[c]Q[l]},
cell{2-Z}{1,6}={font=\ttfamily,cmd={\textbackslash}},
column{3,4}={mode=imath},
column{3}={fg=blue},
row{odd}={bg={blue!12}},
}
&T&M&M&T&\\
 leq
& \leq
& \leq
& \leqslant
& \leqslant
&  leqslant
\\
 geq
& \geq
& \geq
& \geqslant
& \geqslant
&  geqslant
\\
 eqless
& \eqless
& \eqless
& \eqslantless
& \eqslantless
&  eqslantless
\\
 eqgtr
& \eqgtr
& \eqgtr
& \eqslantgtr
& \eqslantgtr
&  eqslantgtr
\\
 leqq
& \leqq
& \leqq
& \leqqslant
& \leqqslant
&  leqqslant
\\
 geqq
& \geqq
& \geqq
& \geqqslant
& \geqqslant
&  geqqslant
\\
 eqqless
& \eqqless
& \eqqless
& \eqqslantless
& \eqqslantless
&  eqqslantless
\\
 eqqgtr
& \eqqgtr
& \eqqgtr
& \eqqslantgtr
& \eqqslantgtr
&  eqqslantgtr
\\
\end{longtblr}





\addfontfeature{RawFeature={+saltineq}}

    \setmathfont{texgyretermes-math.otf}[
        RawFeature={+saltineq},
    ]


\begin{longtblr}[caption={With feature},
note{a}={Red is \texttt{\textbackslash textrm} in math mode.},
remark{Note}={Text = XITS; Math = TeX Gyre Termes - Math.},
]{colspec={Q[r]Q[c]Q[c]Q[c]Q[c]Q[l]},
cell{2-Z}{1,6}={font=\ttfamily,cmd={\textbackslash}},
column{3,4}={mode=imath},
column{3}={fg=blue},
row{odd}={bg={blue!12}},
%cell{6-9}{3-4}={bg={red!5}},
}
&T&M&M&T&\\
 leq
& \leq
& \leq
& \leqslant
& \leqslant
&  leqslant
\\
 geq
& \geq
& \geq
& \geqslant
& \geqslant
&  geqslant
\\
 eqless
& \eqless
& \eqless
& \eqslantless
& \eqslantless
&  eqslantless
\\
 eqgtr
& \eqgtr
& \eqgtr
& \eqslantgtr
& \eqslantgtr
&  eqslantgtr
\\
 leqq
& \leqq
& \cg{\leqq}
& \cg{\leqqslant}
& \leqqslant
&  leqqslant
\\
 geqq
& \geqq
& \cg{\geqq}
& \cg{\geqqslant}
& \geqqslant
&  geqqslant
\\
 eqqless
& \eqqless
& \cg{\eqqless}
& \cg{\eqqslantless}
& \eqqslantless
&  eqqslantless
\\
 eqqgtr
& \eqqgtr
& \cg{\eqqgtr}
& \cg{\eqqslantgtr}
& \eqqslantgtr
&  eqqslantgtr
\\
\end{longtblr}


\end{document}

编辑

一个更实际的例子

数学模式中的字体特征必须可见unicode-math,以便在符号刷新时拾取它。

数学模式

平均能量损失

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{unicode-math}


\directlua{
fonts.handlers.otf.addfeature{
    name = "saltineq",
    type = "alternate",
    data =
    {
      ["≤"] = "⩽", %-- \leqslant
                ["≥"] = "⩾", %-- \geqslant
            ["⋜"] = "⪕", %-- \eqslantless
            ["⋝"] = "⪖", %-- \eqslantgtr
                ["⪙"] = "⪛", %-- \eqqslantless
                ["⪚"] = "⪜", %-- \eqqslantgtr
                ["≦"] = "⫹", %-- \leqqslant
            ["≧"] = "⫺", %-- \geqqslant
    },
  }
}  

\newcommand\fontmimname{Asana Math}


    \setmathfont{texgyretermes-math.otf}[
%        RawFeature={+saltineq},
    ]
    
    \setmathfont[
                Colour=red,
                range={\eqqslantgtr,
                \eqqgtr,
                \leqqslant,
                \geqqslant,
                \eqqslantless,
                \eqqless,
                }
    ]{\fontmimname}




\begin{document}


\addfontfeature{RawFeature={-saltineq}}


\begin{longtblr}[caption={Without feature},
note{a}={Red is imported from \fontmimname{}, without the feature activated.},
remark{Note}={Text = Default; Math = TeX Gyre Termes - Math.},
]{
colspec={Q[r]Q[c]Q[c]Q[c]Q[c]Q[l]},
cell{2-Z}{1,6}={font=\ttfamily,cmd={\textbackslash}},
column{3,4}={mode=imath},
column{3}={fg=blue},
row{odd}={bg={blue!12}},
}
&T&M&M&T&\\
 leq
& \leq
& \leq
& \leqslant
& \leqslant
&  leqslant
\\
 geq
& \geq
& \geq
& \geqslant
& \geqslant
&  geqslant
\\
 eqless
& \eqless
& \eqless
& \eqslantless
& \eqslantless
&  eqslantless
\\
 eqgtr
& \eqgtr
& \eqgtr
& \eqslantgtr
& \eqslantgtr
&  eqslantgtr
\\
 leqq
& \leqq
& \leqq
& \leqqslant
& \leqqslant
&  leqqslant
\\
 geqq
& \geqq
& \geqq
& \geqqslant
& \geqqslant
&  geqqslant
\\
 eqqless
& \eqqless
& \eqqless
& \eqqslantless
& \eqqslantless
&  eqqslantless
\\
 eqqgtr
& \eqqgtr
& \eqqgtr
& \eqqslantgtr
& \eqqslantgtr
&  eqqslantgtr
\\
\end{longtblr}





\addfontfeature{RawFeature={+saltineq}}


    \setmathfont{texgyretermes-math.otf}[
        RawFeature={+saltineq},
    ]


    \setmathfont[
                RawFeature={+saltineq},
                Colour=brown,
                range={\eqqslantgtr,
                \eqqgtr,
                \leqqslant,
                \geqqslant,
                \eqqslantless,
                \eqqless,
                \leqq,
                \geqq,
                }
    ]{\fontmimname}
    
\begin{longtblr}[caption={With feature},
note{a}={Brown is imported from \fontmimname{}, with the feature activated.},
remark{Note}={Text = Default; Math = TeX Gyre Termes - Math.},
]{colspec={Q[r]Q[c]Q[c]Q[c]Q[c]Q[l]},
cell{2-Z}{1,6}={font=\ttfamily,cmd={\textbackslash}},
column{3,4}={mode=imath},
column{3}={fg=blue},
row{odd}={bg={blue!12}},
%cell{6-9}{3-4}={bg={red!5}},
}
&T&M&M&T&\\
 leq
& \leq
& \leq
& \leqslant
& \leqslant
&  leqslant
\\
 geq
& \geq
& \geq
& \geqslant
& \geqslant
&  geqslant
\\
 eqless
& \eqless
& \eqless
& \eqslantless
& \eqslantless
&  eqslantless
\\
 eqgtr
& \eqgtr
& \eqgtr
& \eqslantgtr
& \eqslantgtr
&  eqslantgtr
\\
 leqq
& \leqq
& \leqq
& \leqqslant
& \leqqslant
&  leqqslant
\\
 geqq
& \geqq
& \geqq
& \geqqslant
& \geqqslant
&  geqqslant
\\
 eqqless
& \eqqless
& \eqqless
& \eqqslantless
& \eqqslantless
&  eqqslantless
\\
 eqqgtr
& \eqqgtr
& \eqqgtr
& \eqqslantgtr
& \eqqslantgtr
&  eqqslantgtr
\\
\end{longtblr}


\end{document}

答案4

这不是答案,而且不如 AtBeginDocument 优雅,但您可以在文档内部重新定义。如果需要,可以将其限制为一个组。

重新定义

平均能量损失

\documentclass[10pt,a4paper,french]{article}

\usepackage{mathtools}
\usepackage{babel}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket},math-style=french]{unicode-math}
\usepackage[default]{fontsetup}
\usepackage[scale={0.75,0.8},footskip=1.5cm,heightrounded]{geometry}

\NewDocumentCommand{\oldleqslant}{}{\leqslant}%modification du <=

%%\RenewDocumentCommand{\leq}{}{\leqslant}%modification du <=


\begin{document}

    \[x\leq 3\]

\RenewDocumentCommand{\leq}{}{\oldleqslant}%modification du <=

    \[x\leq 3\]


\end{document}

相关内容