字距调整(使用 realscripts)不在脚注标记中

字距调整(使用 realscripts)不在脚注标记中

请考虑以下代码:

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{realscripts}
\usepackage[english]{babel}
\babelfont[english]{rm}[Ligatures=TeX,Numbers={Proportional,OldStyle}]{<myfont>}

\frenchspacing

\ExplSyntaxOn
\cs_new:Nn \__realscripts_numtosup:n
  {
    \str_set:Nn \l_tmpa_str {#1}
    \str_map_inline:Nn \l_tmpa_str
      {
        \str_if_in:nnTF {0123456789} {##1}
          {
            \int_set:Nn \l_tmpa_int {##1}
            \if_case:w \l_tmpa_int ⁰
              \or: ¹
              \or: ²
              \or: ³
              \or: ⁴
              \or: ⁵
              \or: ⁶
              \or: ⁷
              \or: ⁸
              \or: ⁹
            \fi:
          }
          { {\addfontfeature{VerticalPosition=Superior}##1} }
      }
  }

\cs_generate_variant:Nn \__realscripts_numtosup:n { x }

\DeclareDocumentCommand \realsuperscript {m} {
  \fontspec_if_fontspec_font:TF
  {
    \fontspec_if_opentype:TF
    { \fontspec_if_feature:nTF {+sups}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
    { \fontspec_if_aat_feature:nnTF {10} {1}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
  }
  { \fakesuperscript{#1} }
}
\ExplSyntaxOff

\begin{document}
\null\vfill
In text numbers: 0123456789

To be\footnote{xxx}. or not to be\footnote{xxx}: that is the question\footnote{xxx}:
Whether ‘tis nobler in the mind to suffer\footnote{xxx}
The slings and arrows of outrageous fortune\footnote{xxx},
Or to take arms against a sea of troubles\footnote{xxx},
And by opposing end them\footnote{xxx}? To die: to sleep\footnote{xxx};
No more\footnote{xxx}; and by a sleep\footnote{xxx} to say we end\footnote{xxx}
The heart-ache\footnote{xxx} and the thousand natural shocks\footnote{xxx}
That flesh is heir to, ‘tis a consummation\footnote{xxx}
Devoutly to be wish’d\footnote{xxx}. To die, to sleep\footnote{xxx};

A{\addfontfeatures{VerticalPosition=Superior}0123456789}.

A{\textsuperscript{9876543210}}.

A{\addfontfeatures{VerticalPosition=Superior}321}.

A{\textsuperscript{321}}.

\end{document}

生成的.pdf 如下图所示:

在此处输入图片描述

显然,我只是为了测试而设置了数字 1 和句号之间的偶发性字距调整。您会注意到,字距调整适用于代码的最后一行,但它不适用于上标注释标记。为什么?

更新

我尝试了以下代码:

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\usepackage{realscripts}
\usepackage[english]{babel}
\babelfont[english]{rm}[Ligatures=TeX,Numbers={Proportional,OldStyle}]{Source Serif Pro}

\directlua {
  fonts.handlers.otf.addfeature {
    name = "supkern",
    type = "kern",
    data = {
      ["one.superior"] = { ["period"] =  -250 },
    },
  }
}

\frenchspacing

\ExplSyntaxOn
\cs_new:Nn \__realscripts_numtosup:n
  {
    \str_set:Nn \l_tmpa_str {#1}
    \str_map_inline:Nn \l_tmpa_str
      {
        \str_if_in:nnTF {0123456789} {##1}
          {
            \int_set:Nn \l_tmpa_int {##1}
            \if_case:w \l_tmpa_int ⁰
              \or: ¹
              \or: ²
              \or: ³
              \or: ⁴
              \or: ⁵
              \or: ⁶
              \or: ⁷
              \or: ⁸
              \or: ⁹
            \fi:
          }
          { {\addfontfeature{VerticalPosition=Superior}##1} }
      }
  }

\cs_generate_variant:Nn \__realscripts_numtosup:n { x }

\DeclareDocumentCommand \realsuperscript {m} {
  \fontspec_if_fontspec_font:TF
  {
    \fontspec_if_opentype:TF
    { \fontspec_if_feature:nTF {+sups}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
    { \fontspec_if_aat_feature:nnTF {10} {1}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
  }
  { \fakesuperscript{#1} }
}
\ExplSyntaxOff

\begin{document}
\null\vfill
In text numbers: 0123456789

To be\footnote{xxx}. or not to be\footnote{xxx}: that is the question\footnote{xxx}:
Whether ‘tis nobler in the mind to suffer\footnote{xxx}
The slings and arrows of outrageous fortune\footnote{xxx},
Or to take arms against a sea of troubles\footnote{xxx},
And by opposing end them\footnote{xxx}? To die: to sleep\footnote{xxx};
No more\footnote{xxx}; and by a sleep\footnote{xxx} to say we end\footnote{xxx}
The heart-ache\footnote{xxx} and the thousand natural shocks\footnote{xxx}
That flesh is heir to, ‘tis a consummation\footnote{xxx}
Devoutly to be wish’d\footnote{xxx}. To die, to sleep\footnote{xxx};

A{\addfontfeatures{VerticalPosition=Superior}0123456789}.

A{\textsuperscript{9876543210}}.

A{\addfontfeatures{VerticalPosition=Superior}321}.

A{\textsuperscript{321}}.

A{\addfontfeature{RawFeature=+sups}1.}

A{\addfontfeature{RawFeature=+supkern;+sups}1.}

\end{document}

\directlua没有产生任何结果,并且最后两行是不必要的,因为 period 本身就是超标。哪里出了问题?

进一步更新

试试这个代码:

\documentclass[a4paper,12pt]{book}
\usepackage{fontspec}
\directlua {
  fonts.handlers.otf.addfeature {
    name = "supkern",
    type = "kern",
    data = {
      ["¹"] = { ["."] =  -180,
                [","] =  -180 },
    },
  }
}

\usepackage[english]{babel}
\babelfont[english]{rm}[Ligatures=TeX,Numbers={Proportional,OldStyle},RawFeature=+supkern,RawFeature=+calt]{Source Serif Pro}
\usepackage{realscripts}
\usepackage{perpage}
\MakePerPage{footnote}
\usepackage[bottom,hang,stable,norule]{footmisc} % perpage
\renewcommand{\footnotemargin}{0.01em}
\renewcommand{\hangfootparskip}{0pt}
\renewcommand{\footnotelayout}{\hspace{1em}}

\makeatletter
\def\@makefnmark{\unpenalty{\footnotemarkfont\textsuperscript{\@thefnmark}}}
\makeatother
\ExplSyntaxOn
\bool_new:N \l__realscripts_punct_found_bool
\tl_new:N \l__realscripts_footnote_text_tl
\cs_set_eq:NN \__realscripts_footnote:n \footnote
\cs_new_protected:Nn \__realscripts_footnote_with_punct:
  {
    \bool_set_false:N \l__realscripts_punct_found_bool
    \str_map_inline:nn { ., }
      {
        \token_if_eq_meaning:NNT \l_peek_token ##1
          {
            \footnotemark
            \l_peek_token
            \footnotetext { \l__realscripts_footnote_text_tl }
            \bool_set_true:N \l__realscripts_punct_found_bool
            \str_map_break:
          }
      }
    \bool_if:NTF \l__realscripts_punct_found_bool
      { \use_none:n }
      { \__realscripts_footnote:n { \l__realscripts_footnote_text_tl } }
  }
\cs_new_protected:Nn \__realscripts_footnote_with_punct:n
  {
    \tl_set:Nn \l__realscripts_footnote_text_tl {#1}
    \peek_after:Nw \__realscripts_footnote_with_punct:
  }
\cs_new_protected:Nn \__realscripts_numtosup:n
  {
    \str_set:Nn \l_tmpa_str {#1}
    \str_map_inline:Nn \l_tmpa_str
      {
        \str_if_in:nnTF { 0123456789 } {##1}
          {
            \int_set:Nn \l_tmpa_int {##1}
            \if_case:w \l_tmpa_int ⁰
              \or: ¹
              \or: ²
              \or: ³
              \or: ⁴
              \or: ⁵
              \or: ⁶
              \or: ⁷
              \or: ⁸
              \or: ⁹
            \fi:
          }
          { { \addfontfeature {VerticalPosition=Superior} ##1 } }
      }
  }
\cs_generate_variant:Nn \__realscripts_numtosup:n { x }
\DeclareDocumentCommand \realsuperscript { m } {
  \fontspec_if_fontspec_font:TF
  {
    \fontspec_if_opentype:TF
    { \fontspec_if_feature:nTF {+sups}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
    { \fontspec_if_aat_feature:nnTF {10} {1}
      { \__realscripts_numtosup:x{#1} }
      { \fakesuperscript{#1} }
    }
  }
  { \fakesuperscript{#1} }
}
\DeclareDocumentCommand \footnote { +m }
  {
    \__realscripts_footnote_with_punct:n {#1}
  }
\ExplSyntaxOff

\begin{document}

\chapter{Test chapter}

«text»\footnote{Footnote text}.

A\footnote{Footnote text}.

A\footnote{Footnote text},

A\footnote{Footnote text};

A\footnote{Footnote text}.

\end{document}

你会发现一些奇怪的事情发生了:没有脚注 1!

答案1

我更新了我的回答上一个问题在看到这个之前。为了把正确的东西放在正确的地方,这里重现了我的答案。

您的字距调整问题是由于脚注标记设置在 内而导致的。这会破坏“A”和“¹”之间的字距调整。请考虑使用下面\hbox我修补的宏的代码:\realsuperscript

A{\addfontfeatures{VerticalPosition=Superior}1}.
A{\textsuperscript{1}}.
A\footnote{1}.}

当我们展示这个时我们得到:

.\TU/SourceSerifPro(0)/m/n/12 A
.\TU/SourceSerifPro(1)/m/n/12 ¹
.\TU/SourceSerifPro(0)/m/n/12 .
.\glue(\spaceskip) 3.72801 plus 4.19398 minus 0.31067
.\TU/SourceSerifPro(0)/m/n/12 A
.\kern-1.68 (font)
.\TU/SourceSerifPro(0)/m/n/12 ¹
.\TU/SourceSerifPro(0)/m/n/12 .
.\glue(\spaceskip) 3.72801 plus 4.19398 minus 0.31067
.\TU/SourceSerifPro(0)/m/n/12 A
.\penalty 10000
.\hbox(9.936+0.0)x4.44, direction TLT
..\TU/SourceSerifPro(0)/m/n/12 ¹
.\insert253, natural size 12.00003; split(8.4,3.60004); float cost 20000
..\hbox(8.4+3.60004)x390.0, glue set 367.63995fil, direction TLT
...\localpar
....\localinterlinepenalty=0
....\localbrokenpenalty=0
....\localleftbox=null
....\localrightbox=null
...\hbox(8.28+0.0)x18.00003, glue set 14.30003fil, direction TLT
....\glue 0.0 plus 1.0fil minus 1.0fil
....\hbox(8.28+0.0)x3.7, direction TLT
.....\TU/SourceSerifPro(0)/m/n/10 ¹
...\hbox(8.4+0.0)x0.0, direction TLT
....\rule(8.4+0.0)x0.0
...\TU/SourceSerifPro(0)/m/n/10 

相关内容