foleyj2 / ru-thesis

Thesis (B.Sc., M.Sc., Ph.D.) Template for Reykjavík University in Iceland
MIT License
2 stars 6 forks source link

Our use of babel breaks internationalisation of other languages. #33

Open mkyas opened 1 month ago

mkyas commented 1 month ago

We force Icelandic and English on our students in ruthesis.sty. We just flip the order in which languages are loaded, depending on an IS flag.

Since I cannot find an interface to add additional languages to Babel, I think it is best not to define languages in ruthesis.sty at all.

jbezos commented 1 month ago

Languages can be passed to babel as class options. However, more often than not, there is no need to declare explicitly secondary languages, as the following example shows (with lualatex):

\documentclass[icelandic]{rubook}

\usepackage{babel}

\babelfont{rm}{FreeSerif}
\babelfont[chinese]{rm}{FandolSong}

\begin{document}

\languagename

\foreignlanguage{bulgarian}{български}

\foreignlanguage{greek}{Ελληνικά}

\foreignlanguage{chinese}{中文}

\end{document}

image

mkyas commented 1 month ago

But we cannot change the main language this easily. It requires that the main language is loaded last or explicitly declared with main= when loading the document.

We have dissertations in collaboration with other universities that benefit from being able to set the main language to Italian, Finnish, or Swedish. Those users want to add \usepackage[main=italian,english,icelandic]{babel} to their document.

Loading polyglossia in addition to babel seems to break the font setup, setting the font to computer modern in OT1 encoding instead of stix2 as specified in the class.

jbezos commented 1 month ago

So, I presume what they want is:

\documentclass[english,icelandic,italian]{rubook}
mkyas commented 1 month ago

Declaring a list of languages to a class does not make sense and breaks many packages.

They want


\documentclass[Italian]{rubook}

%%

\selectlanguage{english}

%%

The main issue is that the Italian babel language has a block that execute AtBeginDocument and AtEndOfPackage. There are quite a few that have this issue.

jbezos commented 1 month ago

Declaring a list of languages to a class does not make sense and breaks many packages.

Actually, this is one of the standard ways to declare languages in latex, so that any package recognizes them. It should (must) work. As I’m the maintainer of babel I can take a look to any issues you find to fix them.

mkyas commented 1 month ago

Our issue is if and how we expose the interface to babel to our students in ruthesis.sty. My position is not to load babel in with predefined languages. The issue is how we include babel in ruthesis.sty, lines 87-89. I think it is best to remove this code and instruct our students to load babel or polyglossia with their desired options in the preamble. This way, everything should behave like it is documented.

With our rubook, declaring \documentclass[italian]{rubook} and loading ruthesis.sty still sets english as the main and default language. Indeed, italian is not loaded at all.

jbezos commented 1 month ago

I think it is best to remove this code and instruct our students to load babel or polyglossia with their desired options in the preamble.

This is the most sensible approach, indeed.

foleyj2 commented 1 month ago

I will adjust the code as suggested and put a polyglossia invocation in a comment as well.

foleyj2 commented 1 month ago

I think I have compromized the babel/polyglossia thing by having it do polyglossia with English as the default and Icelandic as an additional language in commit db112afb936ae1ee995a46ef9e6755b0deca4d8a. I'm getting some font substitions related to ligatures (it is doing a substituion on STIX) that seems to happen when it loads the languages: LaTeX Font Warning: Font shape TU/stix2/m/n' undefined (Font) usingTU/lmr/m/n' instead on input line 63.

and later Missing character: There is no  (U+009D) in font [lmroman10-regular]:+tlig;!

foleyj2 commented 1 month ago

I'm very confused as the Overleaf example that uses the FreeX fonts doesn't give the same error. https://www.overleaf.com/learn/latex/Multilingual_typesetting_on_Overleaf_using_polyglossia_and_fontspec

mkyas commented 1 month ago

This also happens if we do not load any language.

mkyas commented 1 month ago

The issue is actually the stix2 package that forces T1 encoding. This makes the ligatures break. Instead, load the STIX Two fonts using fontspec directly. Corrected in commit 7650b51.