CTeX-org / forum

A temporarily alternate forum of `bbs.ctex.org`
https://t.me/chinesetex
Apache License 2.0
210 stars 16 forks source link

我想把公式编号连带编号两边的括号 的字体 都设置为Times New Roman,但 左边那个括号的字体就是改不了 #325

Open fuysgit opened 1 week ago

fuysgit commented 1 week ago

检查清单

操作系统

win11

TeX 发行版

TexLive2024 CTeX3.0.215.2

描述问题

我想把公式右边编号和编号两边的括号的字体都设置为 新罗马。 我通过 \theequation 修改了参数,但最后只实现了编号和编号右边的括号的字体改成了新罗马字体,编号左边的括号的字体没变,如下图所示 示例1

修改 \theequation 参数的代码如下:

\newfontfamily\EngTwo{Times New Roman}
\renewcommand{\theequation}{\EngTwo{\arabic{equation}}}

谢谢帮助!

最小工作示例(MWE)

\documentclass[a4paper]{ctexart} 
\usepackage{amsmath}

\newfontfamily\EngTwo{Times New Roman}
\renewcommand{\theequation}{\EngTwo{\arabic{equation}}}

\begin{document}

\begin{equation}
  E = mc^2 \label{a}
\end{equation}

\end{document}

链接

其他信息

No response

附件

No response

SwitWu commented 1 week ago
\documentclass[a4paper]{ctexart}
\usepackage{mathtools}
\newfontfamily\EngTwo{Times New Roman}
\renewtagform{default}[\EngTwo]{\EngTwo(}{\EngTwo)}
\usetagform{default}
\begin{document}

\begin{equation}
E = mc^2 \label{a}
\end{equation}

\end{document}
muzimuzhi commented 1 week ago

我想把公式右边编号和编号两边的括号的字体都设置为 新罗马。 我通过 \theequation 修改了参数,但最后只实现了编号和编号右边的括号的字体改成了新罗马字体,编号左边的括号的字体没变,如下图所示 [图片] 修改 \theequation 参数的代码如下:

\newfontfamily\EngTwo{Times New Roman}
\renewcommand{\theequation}{\EngTwo{\arabic{equation}}}

公式编号的排版相当于用了 (\theequation),左侧括号出现在 \theequation 之前,所以在 \theequation 里影响不到左侧括号的字体。具体是由 amsmath 里的 \tagform@ 控制的

% amsmath.sty v2.17q (2024/05/23), line 1218:
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}

@SwitWu 的回答使用 mathtools 提供的修改 tag form 的用户接口,避免了直接修改 amsmath 内部宏。mathtools v1.30 (2024/03/11) 的实现,相当于

\hbox{\m@th\normalfont
  <left paren>\ignorespaces{<tag format>{\theequation}}\unskip\@@italiccorr <right paren>}

所以只把切换字族的命令应用在 <left paren> 之前,也能整体修改 (\theequation) 的字体(也许不够稳妥),见 https://github.com/latex3/mathtools/issues/54

\newfontfamily\EngTwo{Times New Roman}
\renewtagform{default}{\EngTwo(}{)}

注意,这样定义的 \EngTwo 的语法和 \rmfamily 类似,都不接受参数,所以 \EngTwo{text}\EngTwo text 的效果相同,不推荐第一种用法。

Harry-Chen commented 1 week ago

See also: https://github.com/tuna/thuthesis/blob/60661f7d140c192418cc9151b54a6c59a99fae23/thuthesis.dtx#L3529-L3563

fuysgit commented 1 week ago

我想把公式右边编号和编号两边的括号的字体都设置为 新罗马。 我通过 \theequation 修改了参数,但最后只实现了编号和编号右边的括号的字体改成了新罗马字体,编号左边的括号的字体没变,如下图所示 [图片] 修改 \theequation 参数的代码如下:

\newfontfamily\EngTwo{Times New Roman}
\renewcommand{\theequation}{\EngTwo{\arabic{equation}}}

公式编号的排版相当于用了 (\theequation),左侧括号出现在 \theequation 之前,所以在 \theequation 里影响不到左侧括号的字体。具体是由 amsmath 里的 \tagform@ 控制的

% amsmath.sty v2.17q (2024/05/23), line 1218:
\def\tagform@#1{\maketag@@@{(\ignorespaces#1\unskip\@@italiccorr)}}

@SwitWu 的回答使用 mathtools 提供的修改 tag form 的用户接口,避免了直接修改 amsmath 内部宏。mathtools v1.30 (2024/03/11) 的实现,相当于

\hbox{\m@th\normalfont
  <left paren>\ignorespaces{<tag format>{\theequation}}\unskip\@@italiccorr <right paren>}

所以只把切换字族的命令应用在 <left paren> 之前,也能整体修改 (\theequation) 的字体(也许不够稳妥),见 latex3/mathtools#54

\newfontfamily\EngTwo{Times New Roman}
\renewtagform{default}{\EngTwo(}{)}

注意,这样定义的 \EngTwo 的语法和 \rmfamily 类似,都不接受参数,所以 \EngTwo{text}\EngTwo text 的效果相同,不推荐第一种用法。

非常感谢!

fuysgit commented 1 week ago
\documentclass[a4paper]{ctexart}
\usepackage{mathtools}
\newfontfamily\EngTwo{Times New Roman}
\renewtagform{default}[\EngTwo]{\EngTwo(}{\EngTwo)}
\usetagform{default}
\begin{document}

\begin{equation}
E = mc^2 \label{a}
\end{equation}

\end{document}

非常感谢

fuysgit commented 1 week ago

See also: https://github.com/tuna/thuthesis/blob/60661f7d140c192418cc9151b54a6c59a99fae23/thuthesis.dtx#L3529-L3563

非常感谢