# How do I define functions in TraditionalForm?

I'd like to be able to define functions (at least simple ones that Mathematica can otherwise understand) using TraditionalForm; but this seems to require the use of an underscore.

For example, I'd like to be able to have something like

$$f(x) = x^2$$

correspond to

f[x_]:=x^2


but Mathematica seems to require

$$f(x\text{_}) = x^2$$

which goes a long way towards defeating the whole purpose.

Is there, perhaps, a way to define some formatting that's less obtrusive, and more "conventionally notational" than the underscore that could correspond to the TraditionalForm underscore (and thus resolve any ambiguities)?

• Even if it is possible, it's probably not a very good idea to indulge in code gymnastics just to be able to make your code look like a latex document. At some point it will break and you'll be left wondering what went wrong. I'd strongly urge keeping code in StandardForm and use TraditionalForm only for output formatting or in labels/text, etc. Besides, how will you differentiate the $f(x)$ in f[x_] = 2 and f[x] = 2? Both are valid definitions, but your usage above makes it ambiguous. (note, I didn't down vote).
– rm -rf
Commented Nov 12, 2012 at 1:01
• @rm-rf: If that were in fact my goal, I'd be using a different tool. The goal is simply to not have to repeat simple equations that are more readable as TraditionalForm in the cases, like the one above, where the intent is clear. Commented Nov 12, 2012 at 1:05
• No, the intent is not clear — see the example in my above comment (I was editing it when you posted yours).
– rm -rf
Commented Nov 12, 2012 at 1:07
• There is another ambiguity: How to distinguish between "set f(x) = x^2" and "is f(x) = x^2 ?". To overcome these ambiguities, some good heuristics would be needed (just like when trying to read traditional math notation). And they would be wrong sometimes. Commented Nov 12, 2012 at 1:26
• @raxacoricofallapatorius what I do is I typeset in normal form my input and when needed I select the input cell and Convert to Traditionnal Form from the Cell Menu Commented Nov 12, 2012 at 7:28

All the comments notwithstanding, I think there may be an acceptable compromise between notational simplicity and formal accuracy. It involves defining functions really as Function, not by patterns.

Here is an example of how that looks in TraditionalForm. It's the replacement for the standard definition a[x_]:= Sin[x], now written in a notation that you'll find in almost that same form in math texts:

a = {x} \[Function] sin(x)

(* ==> Function[{x}, Sin[x]] *)


Here, I've entered the symbol ↦ as EscfnEsc and it's displayed above as \[Function]. I'm assuming this is entered in TraditionalForm. So what you actually see in the notebook is

a = {x} ↦ sin(x)


which (depending on your background) might be a familiar way of writing a function definition. At least you don't have to worry about how to hide or modify the underscore that would be required in the pattern based type of function definition.

The function is of course invoked the same way you always do it. In TraditionalForm again, that would be

a(π/2)

(* ==> 1 *)