# automatic spacing between words in math mode

In math mode, something like $if f x > 3 then 42 else y$ typesets to this:

Obviously, spacing is wrong here, and I need to correct manually: $if \: f \: x > 3 \: then \: 42 \: else \: y$ typesets to

1. Which is the correct amount of space to insert?
2. Is there a way to automate this process, i.e. automatically insert a space between "words" separates by spaces in the source?
• Please read some LaTeX tutorial before you start typing, e.g., tobi.oetiker.ch/lshort/lshort.pdf chapter 3. – Alex Jun 2 '13 at 12:59
• I'm not new to LaTeX - just new to functional-programming-style expressions in math mode :-) – fefrei Jun 2 '13 at 13:19

if  $f x > 3$  then $42$  else $y$
$\textrm{if} \quad f x > 3 \quad \textrm{then} \quad 42 \textrm{else} \quad y$
• Which spacing would you use for $f x$? – fefrei Jun 2 '13 at 12:55