Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Here is my code:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{amsmath}

\usepackage[frenchb]{babel}
\begin{document}

Number $2-a$:

\begin{align*}
Z &\longleftarrow \Phi(x,x) \\
Y &\longleftarrow Y +1
\end{align*}
Number $2-b$:
      \begin{align*}
IF x &\in A    GOTO E\\
Z &\longleftarrow \Phi(x,x) \\
Y &\longleftarrow Y +1
\end{align*}

\end{document}

And it looks like this (the problem is the red-circled line):

enter image description here

What should I do to make that line look like this where it looks more like handwriting where words are separated:

enter image description here

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

In math-mode spaces are ignored. (align as well as align*, equation etc. automatically swith to math-mode.) Just test $a b$: no space inside in the output. If you want to have spaces in math-mode, you could use explicit space (e.g. \␣ (slash space) or \hspace{1em}), but to get correct kerning and roman instead of italics format you should switch to text mode, i.e.

\text{IF }x&\in\text{A    GOTO E}

The \text command is supplied by the amsmath package which you already load anyway. Between A and GOTO there will be only one regular space, if more is needed the \hspace{1em} (in text mode!) could be used there.

share|improve this answer
2  
Do not just insert a space with \ . Letters in math mode are typeset as if they are variables being multiplied, so if you use it for regular text you get terribly spaced italics. –  alexis Nov 10 '12 at 19:28
    
Sorry, "better" suggests that both approaches are correct, but formatting any word in math mode is wrong. \text doesn't just switch to roman, it also fixes the kerning; which is why \text{\it sufficient} looks much better than $sufficient$. –  alexis Nov 11 '12 at 18:19
    
@alexis: I hope I got it right with the edit this time. –  Stephen Nov 12 '12 at 18:55
    
@Stephen You can use <code>\&nbsp;</code>, <code>\ </code>, or (in this case maybe even preferred) \␣ to get the space shown up in your output. –  Qrrbrbirlbel Nov 12 '12 at 19:01
    
@Qrrbrbirlbel: Done & thank you! When I continue with editing like that, this will get CW soon... –  Stephen Nov 12 '12 at 19:03
show 2 more comments

use

\text{IF }x &\in\text{ A    GOTO E}\\

spaces in math mode have no effect.

share|improve this answer
2  
OK, you were 34 seconds faster :-) therefore +1. –  Stephen Nov 10 '12 at 14:29
add comment

In math mode, every element of text is assumed to be a variable, and typeset as such : in particular, for this matter, variables shouldn't form "words", that's why the texing engine won't display spaces. However, it is possible to print text "as if non in math mode", but you have to tell latex that it should regard that content as text.

Amongst the various commands you may use :

  • \mathrm, \mathbf, etc (for mathematical text, such as function names : this won't give correct spacing as well!)
  • \text from the amsmath package (for casual text, will use the font of the outer environment)
  • \textrm, \textbf, etc. (in case you need specific font formatting -- the difference with the math equivalent is that you can use accented characters or inline maths inside these)

In your example, this works, for example :

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{a4paper}
\usepackage{amsmath}

\begin{document}

Number $2-a$:

\begin{align*}
Z &\longleftarrow \Phi(x,x) \\
Y &\longleftarrow Y +1
\end{align*}
Number $2-b$:
\begin{align*}
\mathbf{IF } x &\in A \mathbf{ GOTO } E\\
Z &\longleftarrow \Phi(x,x) \\
Y &\longleftarrow Y +1
\end{align*}

\end{document}

Note that as I said above, spaces are basically ignored in math display. So if you want your spaces to be taken into account, and your text to be separated from the rest of the sentence, you need to make sure the spaces are with the text, inside the braces.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.