TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
3  
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 at 16:04
up vote 4 down vote accepted

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}
share|improve this answer

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}
share|improve this answer

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}{%
    \polyglossiadesactivatefrpt%
}{}{}
\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()
        t[\the\luafunctionpolyglossiadesactivatefrpt] = polyglossia.desactivate_frpt
    }
    \def\polyglossiadesactivatefrpt{%
        \luafunction\luafunctionpolyglossiadesactivatefrpt%
    }
    
  • If your ltluatex is not recent enough, simply:

    \def\polyglossiadesactivatefrpt{%
        \directlua{polyglossia.desactivate_frpt()}%
    }
    

1: You would skip:

  • On the TeX side, token processing; and
  • on the Lua side, parsing (whatever that involves) and two table lookups (one is polyglossia, and the other one, disable_frpt).
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.