5

I'm making a document with babel and monotype font. I made some settings to have a specific alignement but I have problem when using another language.

\documentclass[a4paper,13pt]{book}
\usepackage[french,english]{babel}
\usepackage{fontspec}
\setmainfont{DejaVu Sans Mono}

\spaceskip=1.0\fontdimen2\font plus 0\fontdimen3\font minus 0\fontdimen4\font

\begin{document}
\obeyspaces
\frenchspacing
\setlength{\parindent}{-2\fontcharwd\font`A}
\setlength{\leftskip}{2\fontcharwd\font`A}

\foreignlanguage{english}{%
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. 
Cras sit amet est sit amet urna, tincidunt, consectetur 
eget ut felis. Vestibulum, Nam dapibus.
}

\foreignlanguage{french}{%
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. 
Cras sit amet est sit amet urna, tincidunt, consectetur 
eget ut felis. Vestibulum, Nam dapibus.
}

\end{document}

When I switch to english, I have a missing space before the : character:

enter image description here

Do you know how to have the same spacing around a : in french and english?

  • 1
    Which engine are you using? xelatex or lualatex? – David Purton Nov 8 '18 at 2:33
  • 2
    The space isn't missing in the English. There shouldn't be one there - it is incorrect English punctuation to include a space before, as well as after, the colon. French and English have different punctuation rules. – cfr Nov 8 '18 at 3:55
  • 3
    in English, it looks odd to have a space before the : but if you want a space before : simply have a space before : in the source. It is just in the French style that : is redefined to add a space even if there was no space originally. – David Carlisle Nov 8 '18 at 7:49
  • 1
    If you had used \ttfamily to activate the (suitably set-up) monospace font, babel-french would not have added the space. But I would recommend here \frenchsetup{AutoSpacePunctuation=false} and then no space is added. Then you can have same source for both languages. – user4686 Nov 8 '18 at 8:59
  • @cfr what do you mean, it's incorrect to have a space after the colon: that can't be right, can it? – thymaro Nov 8 '18 at 10:08
5

The reason this happens is that English doesn't put a space before punctuation like French does.

Update for LuaLaTeX support

Here's a go doing this in a way that supports both lualatex and xelatex. I have used \raggedright since without this you get overfull boxes. And I set the default font to be monospaced in a slightly nicer way.

I still call \extrasfrench from within \extrasenglish. But I also set the lua variable FR_ca to be the same as \the\l@english (=0). The lua function that does the punctuation spacing checks if the current language is either FR_fr or FR_ca. By changing one of these to be 0 (for English), we can get French punctuation for both languages. Finally, I added \frenchsetup{OriginalTypewriter=true} so that if you use \ttfamily or \texttt it will still work. (By default french-babel does not automatically adjust the punctuation in these cases.)

Also, note that you have specified a 13pt. The book class only supports 10pt, 11pt, and 12pt. So 13pt simply gives you 10pt which is the default.

Output is the same for both xelatex and lualatex.

\documentclass[a4paper,12pt]{book}
\usepackage[main=french,english]{babel}
\frenchsetup{OriginalTypewriter=true}
\addto\extrasenglish{%
  \extrasfrench
}
\makeatletter
\ifx\directlua\@undefined\else
  \directlua{FR_ca = \the\l@english}
\fi
\makeatother
\usepackage{fontspec}
\setmonofont{DejaVu Sans Mono}
\renewcommand{\familydefault}{\ttdefault}
\raggedright
\begin{document}
\section*{Français}
\today{}

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. Cras sit
amet est sit amet urna, tincidunt, consectetur eget ut felis. Vestibulum, Nam
dapibus.

\selectlanguage{english}

\section*{English with French punctuation}
\today{}

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. Cras sit
amet est sit amet urna, tincidunt, consectetur eget ut felis. Vestibulum, Nam
dapibus.
\end{document}

enter image description here


Original XeLaTeX only answer

For the life of me, I can't figure out how to change this behaviour with lualatex, but this seems to do what you want with xelatex.

I've left out all your spacing commands so you can see that the hyphenation rules (and strings) still change, but the punctuation rules stay French.

Basically, I just call \extrasfrench inside of \extrasenglish. As far as I can see \extrasfrench doesn't do much else other than handle punctuation. (But I might be wrong.)

BTW, there is no 13pt argument for the book class.

I also made french the default language, as this seems to make sense if you want French style punctuation everywhere.

\documentclass[a4paper,12pt]{book}
\usepackage[main=french,english]{babel}
\addto\extrasenglish{%
  \extrasfrench
}
\usepackage{fontspec}
\setmainfont{DejaVu Sans Mono}
\begin{document}
\section*{Français}

\today{}

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. Cras sit
amet est sit amet urna, tincidunt, consectetur eget ut felis. Vestibulum, Nam
dapibus.

\selectlanguage{english}

\section*{English}

\today{}

\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. Cras sit
amet est sit amet urna, tincidunt, consectetur eget ut felis. Vestibulum, Nam
dapibus.

\end{document}

Output

  • 1
    You might want to add that 13pt will get you 10pt font and not 12pt, as you might hope or expect :). – cfr Nov 11 '18 at 0:43
  • @cfr, yes, I guess that is worth mentioning. – David Purton Nov 11 '18 at 6:30
  • Can't upvote again, though - sorry :(. – cfr Nov 11 '18 at 13:10
3

Deactivate extra spacing around high punctuation in French (so that if you want it, you must type it in yourself in the source).

\documentclass[a4paper]{book}
\usepackage[french,english]{babel}
\frenchsetup{AutoSpacePunctuation=false}
\usepackage{fontspec}
\setmainfont{DejaVu Sans Mono}

\spaceskip=\fontdimen2\font\relax

\begin{document}
\obeyspaces
\frenchspacing
\setlength{\parindent}{-2\fontcharwd\font`A}
\setlength{\leftskip}{2\fontcharwd\font`A}

\foreignlanguage{english}{%
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. 
Cras sit amet est sit amet urna, tincidunt, consectetur 
eget ut felis. Vestibulum, Nam dapibus.
}

\foreignlanguage{french}{%
\textbf{Lorem ipsum dolor sit amet}: consectetur adipiscing elit. 
Cras sit amet est sit amet urna, tincidunt, consectetur 
eget ut felis. Vestibulum, Nam dapibus.
}

\end{document}

By the way, babel-french patches \texttt and \ttfamily to not insert extra spacing when using monospace font, but in this example, no use is made of these LaTeX macros.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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