# How do I make a single character bold?

I have a string of characters, like

"CDABOZPVRYXSWQEGNILUTHMKJF"


and want to convert it to a string in which the character at position p is bold.

After doing this I want to leave the result in a table that will be displayed in TableForm and then used for publications or export — e.g., copy as LaTeX — so the result needs to be (essentially) a formatted string with a single bold character.

Is there a way to accomplish this?

• Here you have more general solution: How to change the color of specified digits in a number?. You can use it like that: mark["CDABOZPVRYXSWQEGNILUTHMKJF", {{Red, ;; ;; 2}}] – Kuba Mar 3 '15 at 21:02
• @Kuba That is certainly related. I wonder if it is a duplicate? Your Accepted answer there does not produce String output however. – Mr.Wizard Mar 3 '15 at 21:06
• You could use something like "ABC\!$$\*StyleBox[\"D\",FontWeight->Bold]$$EFG". – Szabolcs Mar 3 '15 at 21:07
• @Mr.Wizard Probably not a duplicate. The problem with keeping it as a string is that next time it is quite tough to specify position. Row is not a the same head too ;P – Kuba Mar 3 '15 at 21:08
• @Szabolcs That also produces errors with "Copy as LaTeX" in Mathematica 10.0.2. Is this operation even possible? – Mr.Wizard Mar 3 '15 at 21:55

This question is related to at least:

Fortunately it is simpler than the first one and we can apply the methods provided in the second one.

stringBold[s_String, pos_] :=
"" <> MapAt[Style[#, Bold] ~ToString~ StandardForm &, Characters@s, pos]

stringBold["CDABOZPVRYXSWQEGNILUTHMKJF", 7]


The output is a String with and embedded Box form:

% // InputForm

"CDABOZ\!$$\*StyleBox[\"\\\"P\\\"\", Bold, Rule[StripOnInput, \ False]]$$VRYXSWQEGNILUTHMKJF"


Any specification that MapAt accepts can be used for parameter pos:

stringBold["CDABOZPVRYXSWQEGNILUTHMKJF", 2 ;; -3 ;; 3]


However the function cannot be applied to more than once, or to an already styled string:

stringBold[%, 3]  (* failure *)

• This seems to break LaTeX copying. All I get is \text{ . – orome Mar 3 '15 at 21:28
• @rax working on it... – Mr.Wizard Mar 3 '15 at 21:33
• Thanks. It would also be great if this could be applied again to the result (to set additional characters to bold of to other styles). – orome Mar 3 '15 at 21:39
• @rax Are you expecting the Bold style to be preserved in LaTeX on copy? I do not see that working at all. If this is what you mean is Mathematica even capable of that? Or do you just mean that on copy you want a plain string in LaTeX? – Mr.Wizard Mar 3 '15 at 21:44
srF = StringReplacePart[#, ToString[Style[StringTake[#, {#2}], ##3], StandardForm], {#2, #2}] &;

str = "CDABOZPVRYXSWQEGNILUTHMKJF";
srF[str, #, Red, Bold, 16] & /@ {3,9}


Note: Copy as LateX does not work

• This generates non standard LaTeX, such as \unicode. – orome Mar 3 '15 at 21:35