15

I need to remove locally spaces arround (especially before) punctuation signs. This spaces are added by french polyglossia.

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{french}

\newcommand{\nospace}[1]{\texttt{#1}}

\begin{document}
\nospace{a:b}
\end{document}

space to remove

Thanks for help.

8
  • I think there is a reason for that: Are you in math mode or trying to write some program code? Or are you locally changing to another language?
    – Johannes_B
    Commented Jul 3, 2014 at 16:58
  • I'm trying to write some program code (like '=SUM(B2:C3)' for spreadsheet program).
    – MB4E
    Commented Jul 3, 2014 at 17:06
  • 2
    Then you might want to take a look at package listings.
    – Johannes_B
    Commented Jul 3, 2014 at 17:07
  • 1
    It's just for some commands inside text, not for a full programm code.
    – MB4E
    Commented Jul 3, 2014 at 17:17
  • 1
    But it doesn't work in a tabular environment. I think there is a more 'simple' solution for that (without listings package).
    – MB4E
    Commented Jul 3, 2014 at 17:40

3 Answers 3

11

This is another solution, without extra package.

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\setmainlanguage{french}

\makeatletter
\newcommand{\nospace}[1]{\nofrench@punctuation\texttt{#1}\french@punctuation}
\makeatother

\begin{document}
\nospace{a:b}
\end{document}

Thanks all.

1
  • 1
    Perhaps better: \newcommand{\nospace}[1]{{\nofrench@punctuation\texttt{#1}}}
    – cgnieder
    Commented Sep 10, 2015 at 10:24
11

Probably Polyglossia should offer the possibility of disabling the automatic spacing feature for French in certain contexts such as monospaced text. However, here's how you can do it:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xpatch}

\setmainlanguage{french}

\xapptocmd\ttfamily{\XeTeXinterchartokenstate=0 }{}{}

\newcommand{\nospace}[1]{\texttt{#1}}

\begin{document}
\nospace{a:b}
\end{document}

enter image description here

A possibly better workaround is to use \nofrench@punctuation as you found out:

\documentclass{article}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage{xpatch}

\makeatletter
\xapptocmd\ttfamily{\nofrench@punctuation}{}{}
\makeatother

\setmainlanguage{french}

\newcommand{\nospace}[1]{\texttt{#1}}

\begin{document}
\nospace{a:b}
\end{document}

This indeed takes into account the possible usage of LuaLaTeX instead of XeLaTeX.

6
  • Thanks, I will try. For polyglossia, the \nonfrenchspacing command is available but it doesn't seem to do what I want.
    – MB4E
    Commented Jul 3, 2014 at 18:00
  • \nonfrenchspacing is for getting extended space after punctuation in the British/American style.
    – egreg
    Commented Jul 3, 2014 at 18:10
  • Ok. So I haven't seen any command for space before punctuation in the polyglossia documentation. (Nothing like the frenchb babel \NoAutoSpaceBeforeFDP)
    – MB4E
    Commented Jul 3, 2014 at 18:19
  • Perhaps the polyglossia solution is something like that \newcommand{\nospace}[1]{\nofrench@punctuation\texttt{#1}\french@punctuation}.
    – MB4E
    Commented Jul 3, 2014 at 19:06
  • @MB78 My workaround will work for every text that uses \ttfamily, including \texttt
    – egreg
    Commented Jul 3, 2014 at 19:36
5

The simplest way seems me to use \string:

a\string:b
2
  • 2
    Welcome to TeX.SX and thanks for answering and participating here! Unfortunately, this does not work for me. Please extend your answer in order to show a full example which works. And maybe explain, what is happening here and where \string comes from. As it stands now, it is a bit short and would be more suited as comment to the OP. It could get closed so I would advice you to improve the answer a bit. Thanks.
    – LaRiFaRi
    Commented Sep 10, 2015 at 10:43
  • 9
    The \string: trick works with pdflatex and babel, not with XeLaTeX (either with babel or polyglossia).
    – egreg
    Commented Sep 10, 2015 at 11:02

You must log in to answer this question.

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