latex3 / babel

The babel system for LaTeX, LuaLaTeX and XeLaTeX
LaTeX Project Public License v1.3c
124 stars 34 forks source link

\normalsfcodes has wrong value in german #240

Closed u-fischer closed 1 year ago

u-fischer commented 1 year ago

The output routine calls \normalsfcodes to ensure that header and footer uses the correct sfcodes, even if the page breaks happens in a verbatim (see https://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/2404).

But as babel sets the language rather late, \normalsfcodes has the wrong value in (n)german and switches back to \nonfrenchspacing:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{fancyhdr}
\pagestyle{fancy}
\setlength\xspaceskip{10pt} %for better view a larger nonfrenchspacing effect
\lhead{Space. Space.\ Space}
\begin{document}
%\show\normalsfcodes
%\let\normalsfcodes\frenchspacing

Space. Space.\ Space 
\end{document}

image

jbezos commented 1 year ago

The following document fails too:

\documentclass{book}

\setlength\xspaceskip{10pt} %for better view a larger nonfrenchspacing effect

\makeatletter
\def\@oddhead{Space. Space.\ Space\hfil}
\makeatother

\begin{document}

\frenchspacing

Space. Space.\ Space 

\end{document}

So, \normalsfcodes has to be localized, but I’m not sure how. There is a package option (headfoot) to set the language in heads/foots to a certain fixed value (introduced to fix, at least in part, babel/3796), but it just sets the language, without redefining \normalsfcodes.

I wonder if \normalsfcodes must be set when babel sets the spacing. I even wonder if this should be done by \frenchspacing (although currently it doesn’t seem feasible).

jbezos commented 1 year ago

The following document fails too:

\documentclass{book}

\setlength\xspaceskip{10pt} %for better view a larger nonfrenchspacing effect

\makeatletter
\def\@oddhead{Space. Space.\ Space\hfil}
\makeatother

\begin{document}

\frenchspacing

Space. Space.\ Space 

\end{document}

So, \normalsfcodes has to be localized, but I’m not sure how. There is a package option (headfoot) to set the language in heads/foots to a certain fixed value (introduced to fix, at least in part, babel/3796), but it just sets the language, without redefining \normalsfcodes.

I wonder if \normalsfcodes must be set when babel sets the spacing. I even wonder if this should be done by \frenchspacing (although currently it doesn’t seem feasible).

FrankMittelbach commented 1 year ago

I wonder if \normalsfcodes must be set when babel sets the spacing. I even wonder if this should be done by \frenchspacing (although currently it doesn’t seem feasible).

I don't think it would be correct to alter \normalsfcodes as part of \frenchspacing. The whole purpose of \normal... is to get back to a normal document state that is precisely not dependent on what happens in the middle of the document.

In my opinion \normalsfcodes should be changed by a major language change that also alters things like \chaptername and the like but not for language changes that are for phrases for other short document parts. There it it should be set to whatever the language uses.

In LaTeX without babel it is expected that you set \frenchspacing in the preamble if it should be the default and then \normalsfcodesis correctly set at \begin{document}. Otherwise, as in your example above, the \frenchspacing is only for a portion of the document without making it the default (even though technially it is done there for the whole doc as there is no grouping or \nonfrenchspacinglater on) and so the default is not altered.

jbezos commented 1 year ago

In my opinion \normalsfcodes should be changed by a major language change that also alters things like \chaptername and the like but not for language changes that are for phrases for other short document parts.

But the problem is similar to verbatim, because the output routine can be called with a different language. This is how \selectlanguage currently works, and this is the very reason the value in the package option headfoot is fixed.

An alternative is to set it to the main language, and yet another is to add a new selector (but there will be too many), or an optional argument to \selectlanguage. It must be localized, for sure, but I'm still not sure how (I don't want to do it hastily and it should be transparent to users).

jbezos commented 1 year ago

But as babel sets the language rather late,

Fixed this particular issue (with begindocument/before). Now the MWE works as expected, and in addition \document@default@language is set to the correct value. Still investigating if additional actions are needed.

jbezos commented 1 year ago

After some consideration, I think the current fix is enough. It’s simple and transparent in monolingual documents. Synchronizing it with \selectlanguage has the same issues verbatim had if the document is basically monolingual, with a main language and some chunks of text in other languages. Finally, in a document with several ‘main’ languages (eg, proceedings), the language is best set explicitly to get a predictable result, because there is no general rule.

jbezos commented 12 months ago

But as babel sets the language rather late, \normalsfcodes has the wrong value in (n)german and switches back to \nonfrenchspacing:

Actually, I realized babel was setting the language at the right place. I think it’s the other way around — \nonfrenchspacing is set by document too early.