texjporg / platex

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

\fontsize{0}{10pt} のエラー? #91

Closed aminophen closed 3 years ago

aminophen commented 4 years ago

不思議なので issue にしておきます。

https://twitter.com/aminophen/status/1240941195620040705

\documentclass{article}
\begin{document}
\fontsize{0}{10pt}
\selectfont
\end{document}

→ latex, pdflatex: エラーなし

→ platex, uplatex, lualatex, xelatex: エラー発生

! Improper `at' size (0.0pt), replaced by 10pt.
kmaed commented 4 years ago

pdflatex でも lmodern など何かフォントを読もうとすると同じエラーになります.

external@font ->rm-lmr5 at0.0pt

! Improper `at' size (0.0pt), replaced by 10pt.
aminophen commented 4 years ago

pdflatex でも lmodern など何かフォントを読もうとすると同じエラー

本当ですね。latexbug-compatible な fix-cm でも出せました:

\RequirePackage{latexbug}
\documentclass{article}
\usepackage{fix-cm}
\begin{document}
\tracingonline1
\tracingmacros1
\fontsize{0}{10pt}
\selectfont
\end{document}
aminophen commented 4 years ago

少し違う例ですが

\documentclass{article}
\usepackage{minijs}
\begin{document}
\fontsize{-1}{10pt}
\selectfont
\end{document}

だと

! LaTeX Error: Font JT1/mc/m/n/-1 not found.
! LaTeX Error: Font JY1/mc/m/n/-1 not found.

になり,ここで \usepackage{minijs} を消すと

LaTeX Font Warning: Font shape `JT1/mc/m/n' in size <-1> not available
(Font)              size <5> substituted on input line 5.
LaTeX Font Warning: Font shape `JY1/mc/m/n' in size <-1> not available
(Font)              size <5> substituted on input line 5.

になります。fix-cm の有無でも同様の違いが起きます。

aminophen commented 4 years ago

素の latex で起こせる MWE にするとこんな感じですね。

\documentclass{article}
\DeclareFontShape{OT1}{cmr}{m}{n}{<-10> cmr8}{}
\begin{document}
\nonstopmode
\fontsize{0}{15pt}\selectfont
% => ! Improper `at' size (0.0pt), replaced by 10pt.
\fontsize{-1}{13pt}\selectfont
% => ! LaTeX Error: Font OT1/cmr/m/n/-1 not found. をひたすら吐き続ける
\end{document}
aminophen commented 4 years ago

こうすれば回避できそう:

\makeatletter
\def\check@range#1-#2>#3<#4\@nnil{%
  \ifnot@nil{#3}{%
     \def\reserved@f{\extract@rangefontinfo<#4\@nnil}%
     \upper@bound0#2\p@
     \ifdim\upper@bound=\z@ \upper@bound\maxdimen\fi
     %%% addition BEGIN
     \ifdim \f@size \p@<1sp
       \def\f@size{1}%
     \fi
     %%% addition END
     \ifdim \f@size \p@<\upper@bound
       \lower@bound0#1\p@
       \ifdim \f@size \p@<\lower@bound
        \else
          \set@simple@size@args#3<#4\@nnil
          \execute@size@function\sizefn@info
         \ifx\external@font\@empty
         \else
           \let\reserved@f\@empty
         \fi
       \fi
     \fi
     \reserved@f}}
\makeatother
aminophen commented 4 years ago

Reported: https://github.com/latex3/latex2e/issues/309

h-kitagawa commented 4 years ago

こうすれば回避できそう:

これだと,

\DeclareFontShape{OT1}{cmr}{m}{n}{<-10> cmr8}{}
...
\fontsize{0}{15pt}\selectfont % (1)
\fontsize{-1}{13pt}\selectfont % (2)

の (1), (2) で cmr8 at 1.0pt を選択してしまうのが不自然な気がします.

zr-tex8r commented 4 years ago

えーと、「何が正しい動作なのか」がよく理解できていないのですが…。

ということで合っていますか?

FrankMittelbach commented 4 years ago

I'm not sure I understand the issue. Asking for a font at size 0 is wrong, so I find the error showing up quite reasonable. The fact this doesn't happen if your declaration only have a fixed set of sizes is also reasonable im my opinion. If you ask for \fontsize{foo}{10} you even get a worse low-level error

./gh309.tex:7: Missing number, treated as zero.
<to be read again> 
                   f

but I think even that is acceptable, because it is really not LaTeX's task to guard against all kind of invalid input in order to keep things reasonably fast.

Or am I missing something?

aminophen commented 4 years ago

cmr8 at 1.0pt を選択してしまうのが不自然

確かに \fontsize{0.5}{15pt} だと 0.5pt になるのに \fontsize{0}{15pt} だとより大きな 1.0pt になるので変な気はします。幾つにフォールバックすれば良かったのでしょう?

「何が正しい動作なのか」がよく理解できていないのですが…。

「もっとわかりやすいエラーを出す」か「エラーなく可能な最小サイズにフォールバックする」のどちらかになれば,私としてはOKです。

aminophen commented 4 years ago

@FrankMittelbach Your test file "tlb0747.lvt" contains

\newcommand\tst[1]{\fontsize{#1}{13pt}\selectfont \showthe\font}
\tst{-1}
\tst{0}

so I guess those are considered a valid input at least for standard LaTeX. OTOH,

\newcommand\tst[1]{\fontsize{#1}{13pt}\selectfont \showthe\font}
\tracingonline1
\tracingmacros1
\tst{-1}
\tst{0}
\stop

runs perfectly on "latex" but throws errors on "platex":

external@font ->tmin10 at0.0pt
! Improper `at' size (0.0pt), replaced by 10pt.

external@font ->min10 at0.0pt
! Improper `at' size (0.0pt), replaced by 10pt.

(Here tmin10 and min10 are names of Japanese-specific fonts.)

If they are considered a valid input for standard LaTeX, I hope this should be valid also on pLaTeX, even when number of loaded fonts are different.

FrankMittelbach commented 4 years ago

Am 20.03.20 um 15:23 schrieb Hironobu Yamashita:

確かに |\fontsize{0.5}{15pt}| だと 0.5pt になるのに |\fontsize{0}{15pt}| だとより大きな 1.0pt になるので変な気はします。幾つにフォールバックすれ ば良かったのでしょう?

\fontsize{0.5}{15pt} asks for a font at size 0.5pt (with a baselineskip of 15pt)

\fontsize{0}{15pt} asks for a font at size 0pt (agan with a baselineskip of 15pt)

so what do you mean by "it is larger"?

the baselineskip has nothing to do with the font size, the NFSS interface has only bundled the two because you more or less always want to set/alter the baseline skip when you set the font size.

so bottom line asking for a font which is 0 is just plain wrong. I'm really a bit confused here.

aminophen commented 4 years ago

so what do you mean by "it is larger"?

"it is larger" is referring to the result of my proposal of "fallback" \def\f@size{1}; so I mean \def\f@size{1} is not good.

zr-tex8r commented 4 years ago

なのだから、もし改善するのであれば

が妥当だと思いますね。


Then I think a reasonable fix will be:

FrankMittelbach commented 4 years ago

Hironobu

@FrankMittelbach https://github.com/FrankMittelbach Your test file "tlb0747.lvt" contains

\newcommand\tst[1]{\fontsize{#1}{13pt}\selectfont \showthe\font} \tst{-1} \tst{0}

so I /guess/ those are considered a valid input at least for standard LaTeX. OTOH,

no you can't conclude any thing like that :-)

I have the habit of testing a lot of strange and wrong input to see how code behaves, so that fact that I'm testing for a font with a negative size doesn't mean it is acceptable input only that in 1994 (where nearly all fonts where metafont based and and only available in discrete sizes) I checked what the code back then did.

\newcommand\tst[1]{\fontsize{#1}{13pt}\selectfont \showthe\font} \tracingonline1 \tracingmacros1 \tst{-1} \tst{0} \stop

runs perfectly on "latex" but throws errors on "platex":

it only runs perfectly with discrete fonts it never did with Type1 fonts when they came about and it is rather pointless to epect that a fotn with 0 or negative size should do anything sensible.

If they are considered a valid input for standard LaTeX, I hope this should be valid also on pLaTeX, even when number of loaded fonts are different.

as I said it is not valid input and it only gets "sort of corrected" for discrete fonts and not for scalable ones.

aminophen commented 4 years ago

as I said it is not valid input and it only gets "sort of corrected" for discrete fonts and not for scalable ones.

Thanks for clarification; then I should mark the test file "tlb0747.lvt" (= runs perfectly on "latex" but throws errors on "platex") as "known difference" between latex and platex.

h-kitagawa commented 4 years ago

範囲指定に対する fallback が奇妙?

\documentclass{article}
\DeclareFontShape{OT1}{cmr}{m}{ta}{<10> cmr17}{}
\DeclareFontShape{OT1}{cmr}{m}{tb}{<-3> cmr17}{}
\DeclareFontShape{OT1}{cmr}{m}{tc}{<6-> cmr17}{}
\begin{document}
\nonstopmode
\def\TEST#1{%
  \fontshapeforce{ta}\fontsize{#1}{15pt}\selectfont% (A)
  \fontshapeforce{tb}\fontsize{#1}{15pt}\selectfont% (B)
  \fontshapeforce{tc}\fontsize{#1}{15pt}\selectfont% (C)
}
\TEST{5}\TEST{0}\TEST{-1}
\end{document}

Results:

argument of \TEST 5 0 -1
(A) cmr17 at 10.0pt cmr17 at 10.0pt cmr17 at 10.0pt
(B) ! LaTeX Error: Font OT1/cmr/m/tb/5 not found. ! Improper `at' size | ! LaTeX Error: Font OT1/cmr/m/tb/-1 not found.
(C) ! LaTeX Error: Font OT1/cmr/m/tc/5 not found. ! LaTeX Error: Font OT1/cmr/m/tc/0 not found. ! LaTeX Error: Font OT1/cmr/m/tc/-1 not found.

例えば「使えるサイズ指定の中で最良近似を使う」という方針にするなら,次のようになるのが望ましい?

argument of \TEST 5 0 -1
(A) cmr17 at 10.0pt cmr17 at 10.0pt cmr17 at 10.0pt
(B) cmr17 at 3pt * *
(C) cmr17 at 6pt cmr17 at 6pt cmr17 at 6pt

*: invalid font size とかなんとか LaTeX レベルのエラー

FrankMittelbach commented 4 years ago

If you run that test with the .fd files for cm fonts I can't imagine that it fails in platex why should it? It fails because you also arrange for Japanese fonts to go alongside with it, isn't that the reason?

The same would happen with luatex (that uses LM fonts by default --- it works only because we run with a special fontsetup to avoid that most of the time, otherwise anytest showing \showoutput would be different across engines). But in other cases we explicitly have tlg files for individual engines generated like this:

l3build save -eluatex tlb0747

I guess you could do the same when needed

aminophen commented 4 years ago

It fails because you also arrange for Japanese fonts to go alongside with it, isn't that the reason?

Right, and of course I knew that. I was comparing the real-life pLaTeX format (including .fd files for Japanese fonts) against the real-life LaTeX format, to ensure that pLaTeX's extensions to NFSS does not break any valid inputs of LaTeX.

I guess you could do the same when needed

Yes I'm considering that.

aminophen commented 4 years ago

I was comparing the real-life pLaTeX format (including .fd files for Japanese fonts) against the real-life LaTeX format, to ensure that pLaTeX's extensions to NFSS does not break any valid inputs of LaTeX.

I raised this issue simply because I felt it strange that the source file which passes LaTeX fails on pLaTeX. Ideally pLaTeX should be upward compatible with LaTeX...

FrankMittelbach commented 4 years ago

well, I would say it is upward compatible. I don't think that you really need to concern yourself mimiking how LaTex handles bad input. I mean

\fontsize{0.1}{10}\selectfont

runs through latex and platex in both cases selecting 5pt CM not 0.1pt CM (so already that is an error situation (somehow handled but not well). Selecting a nearby font was really meant for cases where the difference is small, eg rounding errors or maybe a point but not 4 or 5

in ptex your j-fonts will actually be selected at 0.1pt so you get a rather strange mix :-) but again the ask for 0.1 was already not a reasonable one if CM is the font so ... tough

if you switch to LM or any other scalable font then both implementations work the same, so I think you are fine.