4

I've seen the answer here for Latex. How can I adapt this to plain TeX or OPTeX?

\frlang
\fontfam[Times]


{
    \catcode`\:=\active
    \catcode`\;=\active
    \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`\! }
\catcode`\«=\active \def«{\thinspace\char`\« }
\catcode`\»=\active \def»{\thinspace\char`\» }
    }
}
\def\nofrenchpunct{%
    \catcode`\:=12
    \catcode`\;=12
    \catcode`\?=12
    \catcode`\!=12
\catcode`\«=12
\catcode`\»=12 
}


\frenchpunct
bonjour: monde; oui? non! «aujourd'hui» % opening « does not work, but closing -- » -- does.

\nofrenchpunct

bonjour: monde; oui? non! «aujourd'hui»

\bye
1
  • 1
    Shouldn't it be \catcode\`«=\active \def«{\char\`«\thinspace } ? I guess you'd want the thin space to be after the opening quotation mark (guillemet). Commented Sep 19, 2023 at 10:43

1 Answer 1

8

You're almost there, but the space should go after the opening guillemet.

I add also \unskip or \ignorespaces so as to support the traditional way of typing French.

\frlang
\fontfam[Times]


\begingroup
\catcode`\:=\active
\catcode`\;=\active
\catcode`\?=\active
\catcode`\!=\active 
\catcode`\«=\active 
\catcode`\»=\active 

\gdef\frenchpunct{%
  \catcode`\:=\active \def:{\unskip\thinspace\char`\: }
  \catcode`\;=\active \def;{\unskip\thinspace\char`\; }
  \catcode`\?=\active \def?{\unskip\thinspace\char`\? }
  \catcode`\!=\active \def!{\unskip\thinspace\char`\! }
  \catcode`\«=\active \def«{\char`\«\thinspace\ignorespaces}
  \catcode`\»=\active \def»{\unskip\thinspace\char`\» }
}
\endgroup
\def\nofrenchpunct{%
  \catcode`\:=12
  \catcode`\;=12
  \catcode`\?=12
  \catcode`\!=12
  \catcode`\«=12
  \catcode`\»=12 
}


\frenchpunct
bonjour: monde; oui? non! «aujourd'hui»

bonjour : monde ; oui ? non ! « aujourd'hui »

\nofrenchpunct

bonjour: monde; oui? non! «aujourd'hui»

\bye

enter image description here

4
  • Thanks, that's it. I was inverting the thin space. If you don't mind explaining succinctly: what is the difference between \unskip and \ignorespaces, and why is it advisable to use it here?
    – user574859
    Commented Sep 19, 2023 at 18:04
  • 2
    @user574859 A French typist would be used to type Et voilà ! with a space before the exclamation mark, which \unskip will remove. Similarly, they would be used to type « xyz » so we want to ignore the possible space after the opening guillemet.
    – egreg
    Commented Sep 19, 2023 at 19:40
  • Shouldn't you test if the mode is math? It could cause issues with factorials for example
    – user304322
    Commented Sep 21, 2023 at 11:30
  • @John Assuming that the French wouldn't want a thin space also in that case, you should add.
    – egreg
    Commented Sep 21, 2023 at 13:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .