For pdflatex
you can use solution based on changing category code of characters:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
% saving original quotes representation
\let\gll\guillemotleft
\let\glr\guillemotright
% new quotes representation
\def\frenchguillemotleft{\gll~}
\def\frenchguillemotright{~\glr}
{
\catcode`\:=\active
\catcode`\;=\active
\catcode`\?=\active
\catcode`\!=\active
\gdef\frenchpunct{%
\catcode`\:=\active \def:{\thinspace\char`\: }
\catcode`\;=\active \def;{\thinspace\char`\; }
\catcode`\?=\active \def?{\thinspace\char`\? }
\catcode`\!=\active \def!{\thinspace\char`\! }
\let\guillemotleft\frenchguillemotleft
\let\guillemotright\frenchguillemotright
}
}
\def\nofrenchpunct{%
\catcode`\:=12
\catcode`\;=12
\catcode`\?=12
\catcode`\!=12
\let\guillemotleft\gll
\let\guillemotright\glr
}
\begin{document}
french: french; french? french!
«french»
\frenchpunct
french: french; french? french!
«french»
\nofrenchpunct
french: french; french? french!
«french»
\end{document}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/nF21B.jpg)
Command \frenchpunct
make characters :
, ;
, ?
and !
active and then define them according to desired behaviour: unbreakable thin space before character. Also this command redefine commands \guillemotleft
and \guillemotright
those are declared by inputenc
package.
Command \nofrencpunct
change all back.
Remark: the above \frenchpunct
command is local. Therefore being enclosed by groping characters {}
it take off its effect after leaving group. If you need global command that is canceled only by \nofrenchpunct
add \global
before all \def
(or use \gdef
that is alias for \global\def
), \catcode
and \let
in \frenchpunct
definition:
\gdef\frenchpunct{%
\global\catcode`\:=\active \gdef:{\thinspace\char`\: }
\global\catcode`\;=\active \gdef;{\thinspace\char`\; }
\global\catcode`\?=\active \gdef?{\thinspace\char`\? }
\global\catcode`\!=\active \gdef!{\thinspace\char`\! }
\global\let\guillemotleft\frenchguillemotleft
\global\let\guillemotright\frenchguillemotright
}
And make same for \nofrenchpunct
:
\def\nofrenchpunct{%
\global\catcode`\:=12
\global\catcode`\;=12
\global\catcode`\?=12
\global\catcode`\!=12
\global\let\guillemotleft\gll
\global\let\guillemotright\glr
}
«
and»
-- are entered: directly as such, or via some macro?pdflatex
. It doesn't matter about the quotation marks, I will adapt my input to the solution.