5

Compiling this minimal code with pdflatex or lualatex give this result.

\documentclass[12pt]{article}
\begin{document}
\[ (2;3) \quad 2,3 \]
\end{document}

result

Is it possible to automatically add a space before semicolon and remove the space after comma in math mode ?

5
  • 2
    Perhaps you should start by explaining what (2;3) and 2,3 represent in this case. If say in 2,3 the , is the decimal marker, I would suggest using siunitx and format the number using \num{2,3} (with the appropriate setting to have , be the decimal marker.
    – daleif
    Commented Jan 23, 2020 at 16:00
  • Yes colon is decimal marker (french) and semicolon is coordinates separator. In the past, spacing around semicolon was good (same before and after).
    – MB4E
    Commented Jan 23, 2020 at 16:19
  • 2
    @MB4E Colon is :, semicolon is ; and comma is , Please, be more precise in your question.
    – egreg
    Commented Jan 23, 2020 at 16:36
  • For the semicolon see French spacing for semicolon in math mode
    – campa
    Commented Jan 23, 2020 at 16:37
  • @egreg Yes I was confusing colon and comma. (post edited)
    – MB4E
    Commented Jan 23, 2020 at 17:00

1 Answer 1

0

If you need this behaviour of comma and semicolon in any use-case, you may use following "hack": change mathcodes of comma and semicolon:

\mathcode`\;="303B
\mathcode`\,="013B

In mathcode, first digit represents class of math symbol. Default semicolon and comma have class 6 (punctuation) so space is placed after that and don't before.

Class 3 is relations (like symbols +, – etc.) so thin spaces are placed at both sides. Class 0 is ordinary symbols so spaces aren't placed.

In this case, if you will need to use comma as punctuation (e.g. in list), you have to put thin space after comma manually.

\documentclass[12pt]{article}
\mathcode`\;="303B
\mathcode`\,="013B
\begin{document}
\[ (2;3) \quad 2,3 \quad \{x,\,y,\,1,\,2,\,3\} \]
\end{document}

enter image description here

With any language package used, you have to enclose mathcode declarations is \AtBeginDocument command and place it after loading package:

\documentclass[12pt]{article}
\usepackage{polyglossia}
\AtBeginDocument{
    \mathcode`\;="303B
    \mathcode`\,="013B
}
\begin{document}
\[ (2;3) \quad 2,3 \quad \{x,\,y,\,1,\,2,\,3\} \]
\end{document}
2
  • Unfortunately, polyglossia is breaking the semicolon hack.
    – MB4E
    Commented Jan 24, 2020 at 17:05
  • @MB4E, try to enclose mathcode declarations in \AtBeginDocument command: see additional sample code in my answer. Commented Jan 24, 2020 at 20:02

You must log in to answer this question.

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