Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not writing manytime the language switching in the auxiliary files if not required. #108

Closed
maieul opened this issue Nov 24, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@maieul
Copy link

maieul commented Nov 24, 2020

No description provided.

@maieul
Copy link
Author

maieul commented Nov 24, 2020

Oups, sorry, message was send before I write it !

So my problem start here maieul/ledmac#887.

Having a talk with @u-fischer on SE, she pointed the fact that

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\begin{document}
\tableofcontents

abc\selectlanguage{german} abc \selectlanguage{german}
\end{document}

write three times \german in the auxiliaris files, while it should be easy to remember the actual language, and so not writing anything if not required.

https://chat.stackexchange.com/transcript/message/56242919#56242919

@jbezos
Copy link
Contributor

jbezos commented Nov 24, 2020

I was working on a ‘single’ mode for monolingual documents (there are even some parts already written in the current babel), but babel currently works and therefore it was not among my priorities.

@u-fischer
Copy link
Member

it is not really about monolingual documents. If there more languages it can happen nevertheless that some code reselects the already active language:

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[german,english]{babel}
\begin{document}
\tableofcontents

abc\selectlanguage{german} abc \selectlanguage{german}

abc\selectlanguage{german} abc \selectlanguage{german}

abc\selectlanguage{english} abc 
\end{document}

One could avoid that the language is selected needlessly by using iflang:

\documentclass{scrbook}
\usepackage[T1]{fontenc}
\usepackage[german,english]{babel}
\usepackage{iflang}
\begin{document}
\tableofcontents

abc\IfLanguageName{german}{}{\selectlanguage{german}} abc \IfLanguageName{german}{}{\selectlanguage{german}}

abc\IfLanguageName{german}{}{\selectlanguage{german}} abc \IfLanguageName{german}{}{\selectlanguage{german}}

abc\IfLanguageName{english}{}{\selectlanguage{english}} abc 
\end{document}

But the question is if this is really a user task. Wouldn't it make sense if babel does this?

@jbezos
Copy link
Contributor

jbezos commented Nov 24, 2020

Wouldn't it make sense if babel does this?

Indeed, but when considering floats and the like things are not so simple. And this is not the only issue related to a huge quantity of \selectlanguage's because there is an internal macro growing with each selection (\bbl@language@stack). In the following example \IfLanguageName{english}{}{\selectlanguage{english}} is not the same as just \selectlanguage{english}:

\documentclass{article}

\usepackage[english, german]{babel}
\usepackage{iflang}

\begin{document}

\makeatletter

\protected@write\@auxout{}{\string\@gobble{1 \languagename}}%

\selectlanguage{english}

\begin{figure}
\protected@write\@auxout{}{\string\@gobble{F1 \languagename}}%
% \IfLanguageName{english}{}{\selectlanguage{english}}
\selectlanguage{english}
\protected@write\@auxout{}{\string\@gobble{F2 \languagename}}%
\end{figure}

blah

\selectlanguage{english}
\protected@write\@auxout{}{\string\@gobble{2 \languagename}}%

\end{document}

Admittedly, the result with \IfLanguageName perhaps is wrong (a bug?), but anyway it reveals fixing this issue requires a careful analysis.

@u-fischer
Copy link
Member

In the following example \IfLanguageName{english}{}{\selectlanguage{english}} is not the same as just \selectlanguage{english}:

well it is not supposed to be same, after all the first should executed the command less often ;-) But which problem do you see? At a first glance it looked ok to me.

@jbezos
Copy link
Contributor

jbezos commented Nov 25, 2020

@u-fischer Look at the aux file.

@jbezos
Copy link
Contributor

jbezos commented Dec 3, 2022

As the example in #108 (comment) shows, the asynchronous nature of TeX makes impossible to fix this issue in a general way (in the aux file, the lines with \babel@aux can be misplaced if there are floats). I thought there was some hope with luatex, and in fact the callback process_output_buffer can be used to improve things a bit, but just a little bit, so I don’t think it’s a real solution and, anyway, it doesn’t work with pdftex or xetex.

However, in monolingual documents there is a simple solution (≥3.64):

\babeladjust { select.write = omit }

With this setting, no \babel@aux is written to the aux file. There is a minor bug, but currently it should work in most documents.

@jbezos jbezos closed this as completed Dec 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants