4

This is my line, it is giving me a missing character error

Missing $ inserted. $

l.43 ...l a, b \in \BQ, x = a + b\mbox{\sqrt[]{2}} $

$\forall a, b \in \BQ, x = a + b\mbox{\sqrt[]{2}}$

the \mbox is for making the \sqrt play nicely with the b before it

Andrew Swann
  • 95,762
  • 1
    What is \BQ command? –  Jun 14 '17 at 06:12
  • \newcommand{\BQ}{\mathbb Q} just to make my life easier. – Vishnu Venkatesh Jun 14 '17 at 06:13
  • 2
    You've put \sqrt in text mode (inside a box): it's not clear to me why ... – Joseph Wright Jun 14 '17 at 06:15
  • ive had issues working with \sqrt in math more, it just intersects with anything before it. Is there a better way to format it? – Vishnu Venkatesh Jun 14 '17 at 06:16
  • Firstly, I don't know why you should use \mbox to get something nicer in this case; secondly, you better ask your question via an MWE; thirdly, this code generates what you want, doesn't it?! `\documentclass{article}

    \usepackage{amssymb}

    \begin{document}

    $(\forall a, b \in \mathbb{Q}) x = a + b\sqrt{2}$

    \end{document} `

    –  Jun 14 '17 at 06:20
  • all of a sudden even without the mbox its giving me the same error – Vishnu Venkatesh Jun 14 '17 at 06:21
  • Yeah problem solved, i was just being stupid. – Vishnu Venkatesh Jun 14 '17 at 06:22
  • The wrong placement of the radical seems due to [], avoid it when no index is needed. So \sqrt{2} and \sqrt[3]{3}, but not \sqrt[]{2}. – egreg Jun 14 '17 at 09:00
  • if you are typesetting math in inline mode it is always good to split it into small parts surrounded by $$, like egreg did in his answer. I don't mean doing $x$ $\in$ $\mathbb{Q}$ -- it is tottally wrong, but splitting sentence into logical parts will give you better spacing and less problems with linebreaking. – Michael Fraiman Jun 14 '17 at 09:28

2 Answers2

5

\mbox switches to text mode, so if you put \sqrt inside you need include it in $...$: \mbox{$\sqrt{2}$}.

However, if you just want some extra space before (or after) \sqrt it is much better to stay in math mode and just add \, at the appropriate place, e.g.

\documentclass{article}

\usepackage{amssymb}

\begin{document}

$\forall a, b \in \mathbb{Q}, x = a + b\,\sqrt{2}$

\end{document}

Sample output

This allows \sqrt{...} to fit with the surrounding math style.

See What commands are there for horizontal spacing? for a full list of available spacing commands.

Andrew Swann
  • 95,762
2

The error is in \mbox{\sqrt[]{2}}, because \mbox switches to text mode.

However, this seems a consequence of another mistake: for implementation reasons, an empty optional argument to \sqrt causes the symbol to be misplaced. Avoid \sqrt[]{2} and use the correct \sqrt{2}.

\documentclass{article}
\usepackage{amsmath,amssymb}

\newcommand{\BQ}{\mathbb{Q}} % <--- with braces

\begin{document}

\begin{tabular}{l l}
Wrong:  & $\forall a, b \in \BQ, x = a + b\sqrt[]{2}$ \\
Better: & $\forall a, b \in \BQ, x = a + b\sqrt{2}$   \\
Best:   & for all $a, b \in \BQ$, $ x = a + b\sqrt{2}$
\end{tabular}

\medskip

Cube roots don't have the problem: $a+b\sqrt[3]{2}$

\end{document}

enter image description here

I prefer not to use \forall, but in any case, it should be two formulas: $\forall a,b\in\BQ$, $x=a+b\sqrt{2}$.

Note also that the correct syntax is \mathbb{Q} instead of \mathbb Q.

egreg
  • 1,121,712
  • +1 for pointing out that the OP's full sentence contains -- and thus should be typeset with -- two separate formulas: $a, b \in \BQ$ and $x = a + b\sqrt{2}$. :-) – Mico Jun 14 '17 at 09:14