代码

代码

什么是\f@size

为啥不起作用\convertto{\f@size bp}{pt}

根据此答案的评论,Microsoft Word 使用大点来测量字体:https://tex.stackexchange.com/a/274609/13552

我开始以我能想到的最合乎逻辑的方式将点转换为大点,将\convertto{bp}{1pt}1pt 转换为 bp。

代码

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage[margin=2cm]{geometry}
\usepackage{xparse} % For \NewDocumentCommand (LaTeX3)
\makeatletter
\NewDocumentCommand\thefontsizePoint{m}{{#1 The current font size is: \f@size pt\hfill{\string#1}}\par}
\NewDocumentCommand\thefontsizeBigPoint{m}{{#1 The current font size is: \convertto{bp}{\f@size pt} bp\hfill{\string#1}}\par}
\makeatother

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\NewDocumentCommand{\fontsizes}{m}{%
    \begingroup
    #1
    \offinterlineskip
    \setlength{\lineskip}{4pt}
    \thefontsizeBigPoint\tiny
    \thefontsizeBigPoint\scriptsize
    \thefontsizeBigPoint\footnotesize
    \thefontsizeBigPoint\small
    \thefontsizeBigPoint\normalsize
    \thefontsizeBigPoint\large
    \thefontsizeBigPoint\Large
    \thefontsizeBigPoint\LARGE
    \thefontsizeBigPoint\huge
    \thefontsizeBigPoint\Huge
    \endgroup
    \begingroup
    \offinterlineskip
    \setlength{\lineskip}{4pt}
    \thefontsizeBigPoint\tiny
    \thefontsizePoint\scriptsize
    \thefontsizePoint\footnotesize
    \thefontsizePoint\small
    \thefontsizePoint\normalsize
    \thefontsizePoint\large
    \thefontsizePoint\Large
    \thefontsizePoint\LARGE
    \thefontsizePoint\huge
    \thefontsizePoint\Huge
    \endgroup
}%

\begin{document}
\fontsizes{}
\end{document}

相关问题

大卫·卡莱尔的回答暗示的更新代码

希望这是正确的:

\documentclass[12pt]{article}
\usepackage{fontspec}
\usepackage[margin=2cm]{geometry}
\usepackage{xparse} % For \NewDocumentCommand (LaTeX3)
\setlength{\parindent}{0pt}
\makeatletter
\NewDocumentCommand\thefontsizeBigPoint{m}{{#1 Current font size: \f@size\ pt (1/72.27 in)\hfill{\string#1}}\par}
\ExplSyntaxOn
\NewDocumentCommand\thefontsizePoint{m}{{#1 Current~font~size:~\dim_to_decimal_in_unit:nn { \f@size bp }{ 1 pt }~bp~(1/72~in)\hfill{\string#1}}\par}
\ExplSyntaxOff
\makeatother
\NewDocumentCommand{\fontsizes}{m}{%
\textbf{\TeX\ Point}

(1 pt in TeX) equals 1/72.27 in (= 2540/7227 mm ≈ 0.35145980351 mm) % https://tex.stackexchange.com/questions/21758/globally-redefining-1-pt-to-1-72-in-postscript-point-and-other-similar-changes
\bigskip

    \begingroup
    #1
    \offinterlineskip
    \setlength{\lineskip}{4pt}
    \thefontsizeBigPoint\tiny
    \thefontsizeBigPoint\scriptsize
    \thefontsizeBigPoint\footnotesize
    \thefontsizeBigPoint\small
    \thefontsizeBigPoint\normalsize
    \thefontsizeBigPoint\large
    \thefontsizeBigPoint\Large
    \thefontsizeBigPoint\LARGE
    \thefontsizeBigPoint\huge
    \thefontsizeBigPoint\Huge
    \endgroup

\bigskip\textbf{PostScript Point}

(1 bp in TeX) equals 1/72 in (= 127/360 mm = 0.352(7) mm). It is commonly used unit in DTP nowadays. % https://tex.stackexchange.com/questions/21758/globally-redefining-1-pt-to-1-72-in-postscript-point-and-other-similar-changes
\bigskip

    \begingroup
    \offinterlineskip
    \setlength{\lineskip}{4pt}
    \thefontsizePoint\tiny
    \thefontsizePoint\scriptsize
    \thefontsizePoint\footnotesize
    \thefontsizePoint\small
    \thefontsizePoint\normalsize
    \thefontsizePoint\large
    \thefontsizePoint\Large
    \thefontsizePoint\LARGE
    \thefontsizePoint\huge
    \thefontsizePoint\Huge
    \endgroup
}%

\begin{document}
\thispagestyle{empty}
\fontsizes{}
\end{document}

在此处输入图片描述

答案1

\show将停止 tex(就像出现错误消息一样)并显示任何命令的含义。

\makeatletter
\show\f@size

生产

*\show\f@size
> \f@size=macro:
->10.

\f@size是当前标称字体大小,以pt(不是bp)为单位。

发布的代码产生错误

! Undefined control sequence.
\thefontsizePoint ...ent font size is: \convertto 

并且您没有表明其预期行为,因此很难对此发表评论。


由于您正在使用 expl3,因此您可以使用其函数在单位之间进行转换,例如

\dim_to_decimal_in_unit:nn { 1bp } { 1mm }

将显示 1bp 单位为 mm

参见texdoc interface3第 85 页

相关内容