texjporg / platex

pLaTeX community edition
BSD 3-Clause "New" or "Revised" License
49 stars 8 forks source link

新 NFSS(TeX Live 2020 での本家 LaTeX2e の仕様変更)への対応 #88

Closed aminophen closed 3 years ago

aminophen commented 4 years ago

latex3/latex2e リポジトリの develop branch を試し始めたのですが,

\documentclass{article}
\begin{document}
a
\end{document}

という単純なソースで

LaTeX Font Warning: Font shape `JT1/mc/bx/up' undefined
(Font)              using `JT1/mc/bx/n' instead on input line 2.
LaTeX Font Warning: Font shape `JY1/mc/m/up' undefined
(Font)              using `JY1/mc/m/n' instead on input line 2.

のように警告が出ます。


まだ全容はつかめていませんが,ltnews31.tex を読むと NFSS(LaTeX2e 式の欧文フォント選択システム)が大きく変わっているように思います。これは LaTeX2e 2020-02-02 として TeX Live 2020 pretest でリリースされる予定なので,対応を間に合わせる必要があります。

私が理解した範囲には,以下の変更が含まれます:

これが pLaTeX の日本語フォントと欧文フォントの両方を切り替えるルーチンにどう影響するかはまだ調査中です。ほかの変更点も追って調査します。

aminophen commented 4 years ago

本来は jsclasses および jlreq の issue ですが,情報集約の為こちらに書きます。 @okumuralab @abenori

davidcarlisle commented 4 years ago

@FrankMittelbach ping on issue to track NFSS changes with platex

aminophen commented 4 years ago

@davidcarlisle Thanks for the ping.

From here on, I'll try to post messages in English as far as possible. (When the content is too specific to JP developers, I'll post it in Japanese.)

davidcarlisle commented 4 years ago

@aminophen don't worry too much about the language, better to be inclusive with Japanese users to get issues sorted. If Frank and I can't follow with google translate then we can always ask for clarification.

aminophen commented 4 years ago

@davidcarlisle ありがとうございます ;-)

FrankMittelbach commented 4 years ago

@davidcarlisle どもありがとう for the ping

* TL2020 では mweights.sty が LaTeX2e カーネルに取り込まれるため,pLaTeX と jsclasses と jlreq を適切に改修すれば元の挙動に戻せるはず。

as far as I can see mweights is not implemented in jsarticle, is it? but jsarticle does alter \sffamily etc and this way now undoes some of the changes in the upcoming kernel. It would be helpful to understand what eactly is being done there. It looks to me as if a kanji family is maintained in parallel (which would make sense to me, so that when switching from say \rmfamily to \sffamily the kanji (and kana?) change from "normal" to "grotesk" (or something)?

providing some hook where this extra code could be added without the need to repeat the whole definition might be a good thing, so we should think about what would be best here ... advice welcome

aminophen commented 4 years ago

@FrankMittelbach Thanks for your comments.

mweights is not implemented in jsarticle, is it?

No. (= Your understanding is correct.)

but jsarticle does alter \sffamily etc and this way now undoes some of the changes in the upcoming kernel.

Yes that's a concern of us.

It would be helpful to understand what exactly is being done there. It looks to me as if a kanji family is maintained in parallel (which would make sense to me, so that when switching from say \rmfamily to \sffamily the kanji (and kana?) change from "normal" to "grotesk" (or something)?

Right. The jsarticle's \sffamily is meant so that it changes both Latin and Japanese to San-Serif. Precisely, San-Serif in Japanese font is called "gothic" (or "gt" in shorthand), and Serif (normal) is called "mincho" (or "mc").

providing some hook where this extra code could be added without the need to repeat the whole definition might be a good thing,

That would be nice; 日本の皆様,いかがでしょうか? 良い方法の提案があればご意見をください。

FrankMittelbach commented 4 years ago

The "up" warning problem is due the following line:

pldefs.ltx:34:\newcommand\kanjishapedefault{\updefault}

just change it to \newcommand\kanjishapedefault{n}

A redierection (which was also used in fonttext.ltx was never really sensible here and now it is wrong since updefault and ulcdefault point to "virtual" shapes that have no fonts directly associated with them.

zr-tex8r commented 4 years ago

(Note on jsarticle’s \sffamily for the LaTeX team)

What makes the things complex is the fact that this kind of “synchronization of document families” is jsarticle’s choice and not that of PLaTeX kernel. The kernel does not redefine \sffamily and users have to write \sffamily\gtfamily to change everything to sans-serif. The jsarticle class has taken this choice because it is simply convenient and moreover it can better go along with other “pTeX-unaware” packages (that expect \sffamily will change everything). There are several classes that have taken the same choice, whereas the other classes employ the original \sffamily.

FrankMittelbach commented 4 years ago

I see. So this makes a sensible hook even more desirable (then those classes can more easily adjust the the behavior of the commands. I'm currently looking at that and hope I'll have something for the -dev release we want to ship Monday or Tuesday

zr-tex8r commented 4 years ago

とりあえず、NFSSの仕様変更の内容についてまとめてみた。(日本語!)

①シリーズの実質的な多軸化

※従来の\~series命令はこの改修の影響は受けないはずだが、③の影響のため変更される。

シリーズシェープの実質的な多軸化

※従来の\~shape命令はこの改修の影響は受けない。(ただし\updefaultの既定の値は変更されている。)

③総称ファミリごとの実シリーズ値の設定

④強調書体指定の一般化 ←とりあえず今は省略

⑤その他

カーネルでの既定値

FrankMittelbach commented 4 years ago

I have now reimplemented \sffamily and friends so tha tthey now look like this in the development branch:

\DeclareRobustCommand\sffamily{%
   \not@math@alphabet\sffamily\mathsf
   \prepare@family@series@update{sf}\sfdefault
   \@sffamilyhook
   \selectfont}

The \@sffamilyhook where classes like jsarticle can add additional code without the need to alter the command itsell, i.e., via \@addtohook (it is more less in the same place where current code is injected).

これが何らかの役に立つことを願っています。 おやすみなさい。

FrankMittelbach commented 4 years ago

とりあえず、NFSSの仕様変更の内容についてまとめてみた。(日本語!)

nice summary. I have a few comments, but I'm too tired to write them up now.

aminophen commented 4 years ago

試しに2通り実装してみました。なお,この機能は LaTeX2e 2020-02-02 pre-release-3 以降の「新 NFSS」が利用可能な場合のみ enable されます。

Candidate 1: branch 'dev'

起動時のバナーは pLaTeX2e <2020-02-02>-pre-1 になります。

Candidate 2: branch 'dev-j'

起動時のバナーは pLaTeX2e <2020-02-02>-pre-2 になります。

Candidate 2 の実装は,LuaTeX-ja の fafb8d6 と(\jttfamily はサポートしていないという点を除き)同等の実装です。

参考までに:jsclasses クラスの改修は?

jsarticle.cls には現在,以下のように定義されています。

\DeclareRobustCommand\rmfamily
   {\not@math@alphabet\rmfamily\mathrm
    \romanfamily\rmdefault\kanjifamily\mcdefault\selectfont}
\DeclareRobustCommand\sffamily
   {\not@math@alphabet\sffamily\mathsf
    \romanfamily\sfdefault\kanjifamily\gtdefault\selectfont}
\DeclareRobustCommand\ttfamily
   {\not@math@alphabet\ttfamily\mathtt
    \romanfamily\ttdefault\kanjifamily\gtdefault\selectfont}

もし 'dev' を採用する場合は

\g@addto@macro\@rmfamilyhook{\kanjifamily\mcdefault}
\g@addto@macro\@sffamilyhook{\kanjifamily\gtdefault}
\g@addto@macro\@ttfamilyhook{\kanjifamily\gtdefault}

もし 'dev-j' を採用する場合は

\g@addto@macro\@rmfamilyhook{\prepare@family@series@update@kanji{mc}\mcdefault}
\g@addto@macro\@sffamilyhook{\prepare@family@series@update@kanji{gt}\gtdefault}
\g@addto@macro\@ttfamilyhook{\prepare@family@series@update@kanji{gt}\gtdefault}

に変更すればよくなります。

aminophen commented 4 years ago

pLaTeX で和文 NFSS の新機能が実用されることはあまりないと思いますが,少なくとも「何もしない」という選択はあり得ません。つまり,少なくとも Candidate 1 は pLaTeX に確実に必要な変更です。(そうでなければ,pLaTeX が \fontseries と \fontshape の定義を上書きしてしまうので,LaTeX の新機能を破壊してしまいます。具体的には,\DeclareFontSeriesChangeRule や \DeclareFontShapeChangeRule によって作られた更新規則を無視することになる。)

論点は,Candidate 2 にまで踏み込むかどうかです。

FrankMittelbach commented 4 years ago

どもありがとう for the efforts put into that. I agree that candidate 2 is probably something that is not going to be used much with Japanese fonts, but on the other hand I thought the same about Latin based fonts when I wrote NFSS initially and after a while I was proven wrong. Another advantage is that staying uniform in features has some merrits. As long as no family-specific series values are defined the defaults make the system behave as before so with candidate 2 you extend the possibilities but you don't loose anything.

aminophen commented 4 years ago

@FrankMittelbach Thanks for your comments. I agree with you, so I will adopt the candidate 2 after confirming that it does not cause any compatibility issue with existing Japanese documents.

aminophen commented 4 years ago

Now that LaTeX2e 2020-02-02 is released "official" (not "dev"), so I will make a release of pLaTeX2e as of 'dev-j' branch immediately.

zr-tex8r commented 4 years ago

https://github.com/texjporg/platex/blob/d93a652ca1f7abead5f6050e1e22cc10d4f67f97/plfonts.dtx#L2072

ここは、前にある\merge@kanji@seriesと同じように

    \begingroup\let\f@encoding\k@encoding\let\f@family\k@family
      \maybe@load@fontshape\endgroup

なんじゃないですか?

aminophen commented 4 years ago

指摘ありがとうございます。そのとおりです。 → 1c8facd7

(luatexja も同じミスがあったので修正された模様 → https://ja.osdn.net/projects/luatex-ja/scm/git/luatexja/commits/16d08fad502d01b3f1c2bbef50071547c3b4c3d0

aminophen commented 4 years ago

See https://github.com/latex3/latex2e/commit/9a89f6b5be5b3dd522fe5db5520f4f421d6cb830 (\@defaultfamilyhook will become available, renamed internal commands)

Again: https://github.com/latex3/latex2e/commit/c68b84b7d00ae4ad0fe6e15e397057bcb5f8fb5b

FrankMittelbach commented 4 years ago

My expectation is that the PL2 will appear in a few days, if there are any comments on it they are (as always) very appreciated.

aminophen commented 4 years ago

'latex277' ブランチで latex3/latex2e#277 への対策を始めました。

zr-tex8r commented 4 years ago

新しいNFSSでは、2種類の「シリーズ値」があるわけだけど:

  1. \f@seriesが保持する値(シリーズ値
  2. \fonrseriesの引数になる値(要求シリーズ値

\bfdefaultとか\mdseries@rmとかに入る値はどちらの種類のものなんだろう? 例えば、「medium weight, condensed width」を指定する場合はmccのどちらを使うべきなんだろう?

In the new NFSS, there are two types of “series values”:

  1. What \f@series holds (series values).
  2. What goes to the argument of \fontseries.(requested series values).

Then, of which type is the value of \bfdefault, \mdseries@rm, etc.? For example, when you mean “medium weight, condensed width”, should you use mc or c?

FrankMittelbach commented 4 years ago

thanks for the translation (makes it a bit easier than going back and forth between google translate and this page :-) ).

That is a seriously good question. And one that may have revealed a deficiency (or bug) but I have to think about it a bit longer.

My gut reaction would be to state that it should (or can) be the 要求シリーズ値, i.e. if you want to ensure that

\fontseries{sb}\selectfont ... \mdseries

as well as

\fontseries{sx}\selectfont ... \mdseries

both end up being "medium weight condensed width" (that is c) then the correct value is mc for \medium@rm or \mddefault because they are called via

\fontseries\mddefault

and are therefore "request series values" and only mc resets the weight to medium + the width to condensed, while c as "request series value" would not alter the weight .

The reason why I say there is a bug lurking is this line in \expand@font@defaults:

  \edef\mddef@ult{\mddefault}%

If \mddefault is set to mc then this gets stored in \mddef@ultand is later tested against \f@serieswhich is never mcbut c if we are currently typesetting in medium weight condensed width --- it is a real pain nowadays that LaTeX had so little memory when NFSS was initially designed that I had to save each and every token that I could.

This means that the test will always fail and thus make the detection "am I currently in the medium series in the current family?" wrong, while it may be right.

Without checking that this correct my guess is that in the end we need to have the following definition instead:

\def\expand@font@defaults{%
  \edef\rmdef@ult{\rmdefault}%
  \edef\sfdef@ult{\sfdefault}%
  \edef\ttdef@ult{\ttdefault}%
  \edef\bfdef@ult{\expandafter\series@drop@one@m\bfdefault mm\series@drop@one@m}%
  \edef\mddef@ult{\expandafter\series@drop@one@m\mddefault mm\series@drop@one@m}%
  \edef\famdef@ult{\familydefault}%
}

to make this work correctly. However, as I said, I need to think about this a bit further.

FrankMittelbach commented 4 years ago

maybe I should have mentioned that it is is better not to directly set \mdseries@rm but to use the new interface \DeclareFontSeriesDefault[rm]{md}{mc} etc. At the moment the result is the same, but eventually the latter might do more than just setting the \...@rm command.

aminophen commented 4 years ago

See https://github.com/latex3/latex2e/issues/306; \bfseries in plcore.ltx needs adapted.

If the request in this comment is accepted, then we can use the following patch

\let\fontseries@saved\fontseries
\def\pltx@patch@bfseries\not@math@alphabet#1#2#3\selectfont{%
 \long\expandafter\def\csname bfseries \endcsname{%
  \not@math@alphabet#1#2%
  \let\fontseries\romanseries      %%% \fontseries of pLaTeX tries to change both Latin and Japanese; here we want only Latin, so use \romanseries
  #3%
  \let\fontseries\fontseries@saved %%% recover
  % changed \fontseries -> \kanjiseries
    \ifx\k@family\mcdef@ult      \kanjiseries\bfseries@mc
    \else\ifx\k@family\gtdef@ult \kanjiseries\bfseries@gt
    \else                        \kanjiseries\bfdefault
    \fi\fi
  \selectfont
 }%
}
\expandafter\expandafter\expandafter\pltx@patch@bfseries\csname bfseries \endcsname
\g@addto@macro\reset@bfseries@family@default{%
    \let\bfseries@mc\bfdef@ult
    \let\bfseries@gt\bfdef@ult
}

instead of current method of "built-from-scratch redefinition" of \bfseries using \DeclareRobustCommand.

aminophen commented 4 years ago

Done (957d587).

FrankMittelbach commented 4 years ago

Done (957d587).

I'll alert you in case there is a name change of the hook(s)

aminophen commented 4 years ago

@FrankMittelbach

I'll alert you in case there is a name change of the hook(s)

I appreciate your kindness ;-)

aminophen commented 4 years ago

今度は latex3/latex2e#315 の対応で latex3/latex2e@3503b281381b56d1dd0d201b05884b242f9d71a6 の修正が入りました。

\expand@font@defaults\init@series@setup の定義が変わるのですが,latex-dev と latex の両方を support するのは難しくなりました。 :-(

FrankMittelbach commented 4 years ago

Am 14.04.20 um 14:12 schrieb Hironobu Yamashita:

|\expand@font@defaults| と |\init@series@setup| の定義が変わるのです が,latex-dev と latex の両方を support するのは難しくなりました。 :-(

what exactly are the difficulties? I may be able to do things differently if I know what is problematic or missing.

aminophen commented 4 years ago

Note that I mean "難しくなりました" (= it becomes difficult) is not equal to "it's impossible" ;-)

In the current pLaTeX, we append to \expand@font@defaults

  \edef\mcdef@ult{\mcdefault}%
  \edef\gtdef@ult{\gtdefault}%
  \edef\kanjidef@ult{\kanjifamilydefault}% <= !!

and we append to \init@series@setup

  \ifx\kanjidef@ult\mcdef@ult      \mcfamily % <= !!
  \else\ifx\kanjidef@ult\gtdef@ult \gtfamily % <= !!
  \fi\fi

both of which are based on the previous implementation of LaTeX 2020-02-02.

After the change latex3/latex2e@3503b28, I see that \init@series@setup no longer executes \expand@font@defaults and it executes \reset@font instead.

For me the new code seems better, so I will have to think of detecting which code is used by LaTeX2e and conditionally appends suitable hooks to set \kanjiseriesdefault (= Japanese font series default).

FrankMittelbach commented 4 years ago

Am 14.04.20 um 14:36 schrieb Hironobu Yamashita:

Note that I mean "難しくなりました" (= it becomes difficult) is not equal to "it's impossible" ;-)

true :-) but I asked "what are the difficulties not what are the impossibilities" :-)

Mr. Google translated it correctly to "difficult"

After the change latex3/latex2e@3503b28 https://github.com/latex3/latex2e/commit/3503b28, I see that |\init@series@setup| no longer executes |\expand@font@defaults| and it executes |\reset@font| instead.

after thinking a bit about the edge case in 315 I realized that my solution before was unnecessarily complicated so I took \famdef@ult out and avoided unnecessarily calling \expand@font@defaults

For me the new code seems better, so I will have to think of detecting which code is used by LaTeX2e and conditionally appends suitable hooks to set |\kanjiseries@default| (= Japanese font series default).

well, think about it, and if it needs some extra hook somewhere to do it cleanly we can discuss if that can be offered, or how else it could be done properly.

sorry for making extra work here, I guess we will need a few more rounds to arrive at a stable and for all parties useful version, but I think we are getting there. It turns out to be more complicated than I hoped when trying to make the new stuff work well while supporting various legacy usages.

aminophen commented 4 years ago

well, think about it, and if it needs some extra hook somewhere to do it cleanly we can discuss if that can be offered, or how else it could be done properly.

OK ;-)

sorry for making extra work here, I guess we will need a few more rounds to arrive at a stable and for all parties useful version, but I think we are getting there. It turns out to be more complicated than I hoped when trying to make the new stuff work well while supporting various legacy usages.

No problem at all, and thanks for the useful new stuff.

aminophen commented 3 years ago

pLaTeX2e 2020-10-01 will use new hook management system to add codes into \bfseries etc, almost done.