# Hard space in equation does not work

I have a problem in hard spaces inside an equation. The sign ~ does not work.

The code: $x~\equiv~13~\pmod{16}$. I would like to have all equivalence in one line.

Do you know how to solve it?

• Welcome to TeX.SX! Why should you need ~? – egreg Sep 11 '17 at 21:32
• Please clarify what you mean by the "sign ~ does not work". To be sure, if I expand your code snippet to create a minimal working example, it appears to do what ~ is supposed to do in math mode. (Whether it's a good idea or not, typographically speaking, is a different matter.) Do you maybe want to reduce the space between "13" and "(mod 16)"? – Mico Sep 11 '17 at 21:33
• you can force a line break before x\equiv with \newline (or \\  if you want to leave the first line short) – David Carlisle Sep 11 '17 at 21:50

Avoid using ties in math mode where it's not needed. If you want a short piece of math code to stay together at a line break, wrap it inside a box (an \mbox):

\documentclass{article}

% https://tex.stackexchange.com/a/137076/5764
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}

\begin{document}

Zatem rozwiazaniem kongruecji $7^x \equiv 6 \Mod{17}$ calkowite~$x$ takie, ze $x \equiv 13 \Mod{16}$.

Zatem rozwiazaniem kongruecji $7^x \equiv 6 \Mod{17}$ calkowite~$x$ takie, ze \mbox{$x \equiv 13 \Mod{16}$}.

\end{document}


Note how the spacing of the first congruence doesn't match the second because of placing the second inside an unbreakable box. This should already be an indication that it's best to let (La)TeX decide to break the math content where it's best.

If you do \show\pmod, you will see that the first thing in its definition is the \allowbreak macro. You can delete this using the \patchcmd command from the etoolbox package.

\documentclass{article}
\usepackage{lipsum} % For dummy text
\usepackage{etoolbox}
\patchcmd{\pmod}{\allowbreak}{}{}{}
\begin{document}
\lipsum[1-2]

a\hspace{270pt}b $x~\equiv~13~\pmod{16}$
\end{document}

• The ties are wrong anyway. – egreg Sep 11 '17 at 21:59
• @egreg --- No doubt you are right. I'm just giving the OP what he asked for; I'm not saying it's a good idea! – Ian Thompson Sep 11 '17 at 22:05

In a formula such as $x\equiv 13 \pmod{16}$ there are two feasible break points: after \equiv and before \pmod.

The first one can be removed by using \nolinebreak (but in your case this would do nothing), whereas the second one is wanted; there's no need to keep “(mod 16)” on the same line as “x ≡ 13”. In your specific case, the line is already quite loose and pushing the whole “x ≡ 13  (mod 16)” to the next line will produce an underfull line (or overfull, depending on several conditions).

Here's an example:

As you see, the second paragraph is really bad. The first one is not the best either, but a reader will expect the “mod” clause after having seen the ≡ symbol, so there's no problem in having it in the next line.

On the other hand, if you load microtype, the line will be typeset with no overfull:

\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[polish]{babel}
\usepackage{geometry}

\usepackage{microtype}
\usepackage{amsmath}

\begin{document}

\noindent
Zatem rozwiązaniem kongruencji $7^x \equiv 6 \pmod{17}$ są liczby
calkovite $x$ takie, że $x \equiv 13 \pmod{16}$.

\end{document}


Loading the geometry package without microtype produces the exact output you show, so I guess this is the setting you have.

In any case, such details should be examined only at the very last stage of document production: I'd much prefer the line break before (mod 16) to a very loose line. But “fixing” it at an early stage might result in a waste of time because the text might be edited before the final version.