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.

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

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

  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?
share|improve this question
1  
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

1 Answer 1

up vote 8 down vote accepted

the spacing is the least of the problems, the letters are all wrong as well. The math italic font has wide side-bearings specifically so that adjacent letters do not look like letters forming a word but rather the usual mathematical use as implied multiplication of separate variables. To use a multi-letter identifier you need to use a text font, then inter-word spacing will automatically work as well, although you would need to use \quad or a similar space if embedding the text in math mode..

if  $f x > 3$  then $42$  else $y$ 

or if you need to embed it in display math

\[ \textrm{if} \quad f x > 3 \quad \textrm{then} \quad 42  \textrm{else} \quad y \]
share|improve this answer
    
Which spacing would you use for $f x$? –  fefrei Jun 2 '13 at 12:55
    
@felix-freiberger: What is f x? Do you mean f(x)? –  Marco Daniel Jun 2 '13 at 12:56
    
@felix-freiberger sorry I dropped the f by mistake, babara just put them back so see edited answer. –  David Carlisle Jun 2 '13 at 12:57
    
f x is a functional application in a functional programming language like Haskell. –  fefrei Jun 2 '13 at 12:58
    
@felix-freiberger either fx as above or perhaps \mathop{f{}}x which would give the same spacing as a mult-letter identifier like \log –  David Carlisle Jun 2 '13 at 13:02

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.