ivankokan / babel-croatian

Croatian support for babel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

extras/noextras concept

ivankokan opened this issue · comments

babel-croatian/croatian.dtx

Lines 176 to 187 in 58f5adc

% \begin{macrocode}
\addto\extrascroatian{%
\bbl@nonfrenchspacing}
% \end{macrocode}
%
% For Croatian texts |\frenchspacing| should be in effect. We
% make sure this is the case and reset it if necessary.
%
% \begin{macrocode}
\addto\noextrascroatian{%
\bbl@nonfrenchspacing}
% \end{macrocode}

Hi @jbezos. After reading the babel manual many times on this topic in past few years, the way I understand how extras and noextras work is that extras contains language specifics which are activated upon selecting the language, while noextras contains reverting of what extras do.

In that sense, should extrascroatian contain some sort of state saving before switching \bbl@nonfrenchspacing, and noextrascroatian some sort of restoring the previously saved state instead of switching \bbl@nonfrenchspacing?

Kind regards.

It's:

\addto\extrascroatian{\bbl@frenchspacing}
\addto\noextrascroatian{\bbl@nonfrenchspacing}

They don't save any state, just apply directly the corresponding \sfcodes.

It's:

\addto\extrascroatian{\bbl@frenchspacing}
\addto\noextrascroatian{\bbl@nonfrenchspacing}

They don't save any state, just apply directly the corresponding \sfcodes.

Conceptually, should they (or can they, using e.g. \bbl@save or \bbl@savevariable)? Is babel core implemented that way?

You correctly noticed this should be done: \addto\extrascroatian{\bbl@frenchspacing}, according to

babel-croatian/croatian.dtx

Lines 181 to 182 in 58f5adc

% For Croatian texts |\frenchspacing| should be in effect. We
% make sure this is the case and reset it if necessary.

So, my question is actually on \addto\noextrascroatian{\bbl@nonfrenchspacing}. Why is \bbl@nonfrenchspacing explicitly there instead of some if-else approach based on "something saved within extrascroatian" before switching \bbl@frenchspacing on?

extrascroatian
1) save the current sentence spacing configuration
2) switch on French sentence spacing for Croatian
noextrascroatian
if the previously saved sentence spacing configuration was French spacing
   switch on French sentence spacing
else
   switch on non-French sentence spacing

Looking at https://github.com/latex3/babel/blob/master/babel.dtx#L3373-L3378, should I comprehend the predefined state as some default state, i.e. "non-French spacing is the default, just switch it on, regardless of whether you know what configuration was used before activating Croatian"?

Sure, conceptually you are right. However, it mostly works (at least, nobody has complained :-)), and therefore it's not a priority (and I'm concerned with backwards incompatibilities with such a basic feature).

OK. I implemented something in that fashion (0762627) but let us see what eventually happens with it.

Actually, this is what I am still bothered by... Assume the flat hierarchy (using only selectlanguage and foreignlanguage):

\selectlanguage{lang1}
...
\selectlanguage{lang2} % are noextraslang1 executed here, and then extraslang2?
...
\foreignlanguage{lang3}{% are noextraslang2 executed here, and then extraslang3?
...} % are noextraslang3 executed here upon leaving?
% are extraslang2 executed here again?

The same bothers me when languages are nested (using otherlanguage and otherlanguage*). Are noextraspreviouslang executed just before executing extrasnextlang when entering the environment? Are noextrasnextlang executed upon leaving the environment, and extraspreviouslang then executed again?

How many levels of nested languages are supported?

Is nesting languages this way valid from babel perspective? (Of course it is silly, but still...)

\begin{otherlanguage}{lang1}
  \begin{otherlanguage}{lang2}
    \begin{otherlanguage}{lang3}
      \begin{otherlanguage}{lang2} % lang2 again
      \end{otherlanguage}
    \end{otherlanguage}
  \end{otherlanguage}
\end{otherlanguage}

Kind regards, Ivan

Hi @jbezos. I have been doing some tests on this and here are some conclusions and thoughts...

How many levels of nested languages are supported?

Not sure how many, but definitely as many as wanted (up to some internal limits on stack, memory etc.)

Is nesting languages this way valid from babel perspective? (Of course it is silly, but still...)

\begin{otherlanguage}{lang1}
  \begin{otherlanguage}{lang2}
    \begin{otherlanguage}{lang3}
      \begin{otherlanguage}{lang2} % lang2 again
      \end{otherlanguage}
    \end{otherlanguage}
  \end{otherlanguage}
\end{otherlanguage}

I would say it is valid.

Here is the test case I made with

\addto\extrascroatian{%
  \ifx\@onlypreamble\@notprerr\fbox{extras}\\[10pt]\fi}
\addto\noextrascroatian{%
  \ifx\@onlypreamble\@notprerr\fbox{no-extras}\\[10pt]\fi}

and

\documentclass[a4paper,10pt,twocolumn]{article}

\usepackage[croatian]{babel}

\setlength{\parskip}{6pt}
\setlength{\parindent}{0pt}

\begin{document}

\footnotesize

intro, level 0

\selectlanguage{croatian}
croatian selected

\foreignlanguage{croatian}{a bit of ``foreign'' croatian}

now nesting

\begin{otherlanguage}{croatian}
  level 1

  \begin{otherlanguage*}{croatian}
    ``foreign'', level 2
  \end{otherlanguage*}

  \begin{otherlanguage}{croatian}
    level 2

    \begin{otherlanguage}{croatian}
      level 3

      \selectlanguage{croatian}
      croatian selected again, level 3

      \foreignlanguage{croatian}{``foreign'' croatian, level 3}
    \end{otherlanguage}

    back on level 2
  \end{otherlanguage}

  back on level 1
\end{otherlanguage}

back on level 0

\end{document}

image

(Although I used only croatian, I am aware that noextras for the "language to leave" are executed, so as extras for the "language to enter or return back to".)

It could be that my expectations on extras/noextras for foreignlanguage and otherlanguage* are not present due to remark in the docs: "\foreignlanguage and otherlanguage* messed up \extras<language>. Scripts, encodings and many other things were not switched correctly.". (My logs say Package: babel 2019/07/19 3.33 The Babel package, I will try to update it and test again.)

Edit: Hm, no updates in up-to-date MiKTeX. Considering the status on CTAN (https://ctan.org/ctan-ann/pkg/babel), I would say that bugfix on \foreignlanguage and otherlanguage* is not released yet?

Ignore this part above. I just realized that 3.33 is (much) newer than 3.9. :)

So, the question remains on yellow and red comments in the image.

Kind regards, Ivan

For the reasons explained in the manual (eg, \begin{otherlanguage} ... \end{otherlanguage} is not the same as {\begin{otherlanguage} ... \end{otherlanguage}}), language switching has its surprises. This part very likely must be rewritten. See https://github.com/latex3/babel/wiki/Current-work (some sections of this article are a bit outdated). As to \foreignlanguage, and unlike otherlanguage, it just puts everything inside a group, so changes are automatically discarded upon exiting.