Text Formattingpolyglossia | Associate '\nonfrenchspacing' with a Language

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by Laurentius »

When I change to another language and back, the effect of \nonfrenchspacing has disappeared. What to do? (I'm using XeLaTeX and polyglossia)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by cgnieder »

This seems to work:

Code: Select all

\documentclass{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{french}
\begin{document}
non french: text. and more text

\textfrench{french: text. and more text}

non french: text. and more text

\begin{french}
 french: text. and more text
\end{french}

non french: text. and more text
\end{document}
polyglossia_frenchspacing.png
polyglossia_frenchspacing.png (13.14 KiB) Viewed 4748 times
Regards
site moderator & package author
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Re: polyglossia | Associate '\nonfrenchspacing' with a Langu

Post by Laurentius »

I'm not talking about extra space before cola &c. The effect of \nonfrenchspacing is extra space added after full stops, e.g. \xspaceskip=1em plus .4em minus .2em
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by cgnieder »

I know that. That's why I added the fullstop in the example. And as I said: it seems to work. You can see it more clearly here:

Code: Select all

\documentclass{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{french}
\begin{document}
\setlength\parindent{0pt}

non french: text. and more text \\
non french: text.\ and more text

\begin{french}
 french: text. and more text \\
 french: text.\ and more text
\end{french}

non french: text. and more text \\
non french: text.\ and more text
\end{document}
frenchspacing_polyglossia.png
frenchspacing_polyglossia.png (28.98 KiB) Viewed 4739 times
site moderator & package author
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by Laurentius »

Oh, sorry. Still, I need it to work with \selectlanguage, since I use need the language (and font) automatically to change when a greek character occurs, with something like

Code: Select all

%Languages and fonts
\newcommand\defaultlanguage{danish}
\setdefaultlanguage{\defaultlanguage}
\setotherlanguage[variant=ancient]{greek}
\setotherlanguage{french}
\setotherlanguage{english}
\setotherlanguage[spelling=old]{german}
\setmainfont[
	Numbers=Lowercase,
	Mapping=tex-text,
	ItalicFont={[caslon.it.otf]}
	]{[caslon.otf]}
%\newfontface\longs[Numbers=Lowercase, Ligatures=Rare, Mapping=longs]{[caslon]}
%\newfontface\nolongs[Numbers=Lowercase]{[caslon]}
\newfontfamily\greekfont[Numbers=Lowercase]{[Garamond.otf]}

\def\XeTeXcharclasses[#1-#2]#3{
	\newcount\c
	\c=#1
	\XeTeXcharclass\c=#3
	\loop\ifnum\c<#2
		\advance\c by 1
		\XeTeXcharclass\c=#3
	\repeat
	}
\XeTeXinterchartokenstate=1
\newXeTeXintercharclass\greekchar
\XeTeXcharclasses["0370-"03FF]\greekchar
\XeTeXcharclasses["1F00-"1FFF]\greekchar
\XeTeXinterchartoks 0 \greekchar {\selectlanguage{greek}\nonfrenchspacing}
\XeTeXinterchartoks 255 \greekchar {\selectlanguage{greek}\nonfrenchspacing}
\XeTeXinterchartoks \greekchar 0 {\selectlanguage{\defaultlanguage}\nonfrenchspacing}
\XeTeXinterchartoks \greekchar 255 {\selectlanguage{\defaultlanguage}\nonfrenchspacing}
\XeTeXinterchartoks \greekchar \french@punctguillend {\selectlanguage{\defaultlanguage}\nonfrenchspacing\nobreakspace}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by cgnieder »

Could you make that a compilable Infominimal working example which shows the issue so that I (or any other person willing to help) can experiment with it, please?

Regards
site moderator & package author
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by Laurentius »

All right. I want the last line to have a space after the period without having to repeat \nonfrenchspacing

Code: Select all

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{german}
\xspaceskip=2em
\nonfrenchspacing
\begin{document}
\obeylines
Quick. Fox

\selectlanguage{german}
Brown. Dog

\selectlanguage{english}
Lazy. Bum
\end{document}
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

polyglossia | Associate '\nonfrenchspacing' with a Language

Post by cgnieder »

IMHO the easiest would be to define a new command which selects the language and sets the correct spacing. Since the package xparse has been by loaded by fontspec which in turn has been loaded by polyglossia you can use its commands:

Code: Select all

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguages{german,french}

% s = star
% m = mandatory argument
\NewDocumentCommand\uselanguage{sm}{%
  \selectlanguage{#2}%
  % if `star' then set \frenchspacing, else \nonfrenchspacing :
  \IfBooleanTF{#1}{\frenchspacing}{\nonfrenchspacing}}
\xspaceskip=2em
\nonfrenchspacing
\begin{document}
\obeylines
Quick. Fox

\uselanguage{german}
Brown. Dog

\uselanguage*{french}
Brown. Dog

\uselanguage{english}
Lazy. Bum
\end{document}
Regards
site moderator & package author
Post Reply