# Changing language back and forth with polyglossia

I'm using polyglossia and lualatex to compile my source, and I am switching languages back and forth inside my document. It looks like polyglossia (or myself), is not doing what it is supposed to do:

\documentclass[12pt]{book}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{french}
\begin{document}
\textsc{url:} www. \\
\begin{french}
\textsc{url:} www. \\
\end{french}
\textsc{url:} www. \\
\end{document}


First line prints "url: www." in English: OK. Second line prints "url : www." in French: OK. Third line prints "url : www." in English: not OK (there should not be a space before the colon).

Am I doing something wrong ? Thank you.

• This seems to be a bug in the experimental support of Polyglossia in LuaLaTeX. I would stay away from Polyglossia if you plan to use LuaLaTeX. By the way, the behavior is correct with XeLaTeX. – egreg Jun 23 '14 at 8:55
• Fortunately, my (much larger) project compiles fine with XeLaTeX and the behavior is indeed correct there. I am all ears for a possible LuaLaTeX fix though, since this seems to me it is the only hiccup in the experimental support. For example, \cref{fig} and \cref{chap} correctly switch back to the correct formatting (fig. in English vs. figure in French and chapter in English vs. chapitre in French). – BigDawg Jun 23 '14 at 9:01
• The bug is known:github.com/reutenauer/polyglossia/issues/68. The problem seems to be that the deactivation of the frenchspacing with \directlua{polyglossia.desactivate_frpt()} works but affects the whole current paragraph an so can lead to wrong spacing in french parts of this paragraph. – Ulrike Fischer Jun 23 '14 at 9:10
• @UlrikeFischer Can you make that an anwser - issuing that \directlua command at the beginning of the paragraph after the french environment fixes the problem, assumning the poster is prepared to have the text in separate paragraphs rather than using \ – Andrew Swann Jun 23 '14 at 10:06
• As of June 11th, 2016, using polyglossia v1.42.4 with lualatex, the bug is still present. github.com/reutenauer/polyglossia/releases – wget Jun 11 '16 at 16:04

You can reset the "nonfrench"-spacing with a \directlua-call. But it will affect the whole paragraph:

\documentclass[12pt]{book}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{french}
\begin{document}
\textsc{url:} www.

\begin{french}
\textsc{url:} www.
\end{french}

\directlua{polyglossia.desactivate_frpt()}
\textsc{url:} www.

\begin{french}
\textsc{url:} www.
\end{french}
%affects the preceding french too:
\directlua{polyglossia.desactivate_frpt()}
\textsc{url:} www.

\end{document}

• In my document i use \cref with tables. The references made in the Spanish section appear in Spanish but the references made in the English section still use the Spanish names "Tabla", "y" and so on. How can I change them? – skan Sep 15 '19 at 22:24
• @skan ask a new question with a proper minimal example. – Ulrike Fischer Sep 16 '19 at 6:22

Use babel instead:

\documentclass[12pt]{book}
\usepackage[french,english]{babel}
\begin{document}
\textsc{url:} www.

\begin{otherlanguage}{french}
\textsc{url:} www.
\end{otherlanguage}

\textsc{url:} www.
\end{document}


Here's a solution that builds upon Ulrike Fischer's and automatically resets "nonfrench" spacing at every language switching command. Beware that the same problem applies: the spacing style is applied to whole paragraphs, and, thus, not even French text will have it. Therefore, this solution will only be appropriate if you're just typing French in a couple places; if this is not the case, it will be better to issue that \directlua-call at the appropriate places.

% \usepackage{etoolbox}
\makeatletter
\apptocmd{\select@@language}{%
}{}{}
\makeatother


\polyglossiadesactivatefrpt may be defined in two ways:

• Using \luafunction. This approach is slightly more efficient1, but you shouldn't notice unless you switch languages a lot. On the other hand, \newluafunction, which is needed to handle resources and use them politely, requires a recent ltluatex.

\newluafunction\luafunctionpolyglossiadesactivatefrpt
\directlua{
local t = lua.get_functions_table()
}

• If your ltluatex is not recent enough, simply:
\def\polyglossiadesactivatefrpt{%

• on the Lua side, parsing (whatever that involves) and two table lookups (one is polyglossia, and the other one, disable_frpt).