# Bold face formatting for vectors instead of overarrows like latex \mathbf{}?

OverVector can be used to make a symbol look like a vector in text sections of documents. I happen to like bold symbols for vectors better, as in latex \mathbf{x} output.

I've found that I can do, say, Style[x, Bold], but this is actually a very subtle seeming change, and I find it hard to actually notice the difference. Perhaps this is because the default font picked for variables is something quite different from what one gets with \mathbf. If this is just a font issue, what's a good font for this sort of output (i.e. like \mathbf{x}), and how would it be selected?

Also, the Style function applies to expressions, whereas I want it to apply to just particular variables (i.e. leaving scalars in regular font), so that when they are used in input, the output comes out in the desired way.

Is there a mechanism to declare a variable, and have specific style settings associated with it, so that it is displayed in the desired way?

-

I am not sure I understand your needs, but consider this:

Format[OverVector[v_]] := Style[HoldForm[v], FontFamily -> "Arial Black"]

{q, r, OverVector[s], t, u, v}


-

This is mainly an add-on to David solution. I'm new in SE, so I can't comment yet. So I put it in an answer.

One could maintain a list of the symbols, which should be displayed as vectors, eg:

vList = {}
defAsVector[x__Symbol] := (vList = Union[Join[vList, {x}]];)
defAsVector[] := vList
undefAsVector[x__Symbol] := (vList = Complement[vList, {x}];)
undefAsVector[] := (vList = {}; $PrePrint =.;)$PrePrint = # /. {x_ /; MemberQ[vList, x] :> Style[x, Bold]} &;

-

I only have my iPhone now, but something like this should work well.

MakeBoxes[x,StandardFom]:=StyleBox["x",FontWeight->Bold];
MakeExpression[StyleBox["x",FontWeight->Bold]]:=MakeExpression["x"].


Better yet you could 'declare' that certain symbols represent vectors.

declaredVectorQ[x_Symbol]:^=declaredVector[x]^=True;
MakeBoxes[x_Symbol?declaredVectorQ,StandardForm]:=
StyleBox[ToString[x],FontWeight->Bold];
MakeExpression[StyleBox[str_String,FontWeight->Bold]:=ToExpression[str];

-
• You can specify a different font by using the FontFamily parameter for Style:

• If you want specific symbols to be printed differently on output, you may want to have a look at $Post and $PrePrint. For example, the following prints the symbol x bold and in Helvetica:

(Ignore this line, tricking the bad markup of SE)

$PrePrint =. x$PrePrint = # /. {x -> Style[x, Bold, FontFamily -> "Helvetica"]} &;
x


Be careful though, a styled object can have unwanted side effects. Therefore, in this paragraph, I sincerely disencourage you to change styling of symbols you want to do calculations with, and would recommend doing the prettyprinting in the very end, using an explicit handcoded function.

-
What kind of bad side effects are you thinking of? Don't have time to fiddle with this, but I thought of using Interpretation to make the output re-usable, what do you think? –  Szabolcs Feb 24 '12 at 8:53
Imagine you've got something with a style and apply some definitions to it, and then use the normal symbol again - not fun to fix. In other places both of them might be equivalent, I don't think there's a consistenz way of doing it. Interpretation is a very good idea though. –  David Feb 24 '12 at 9:13