3
$\begingroup$

If I have a paragraph of text and have some very short code inline such as a function/symbol names in the sentences, how to format them more like code? Sort of like an analogue of computerCode in Markdown.

$\endgroup$
1
$\begingroup$

As you are typing, you can toggle between Code and Text styles using Alt+8 and Alt+7 (version 9.0.1.0 windows 8 x64)

If the paragraph is already typed, you can highlight the part you want to change and use Alt+8 to change its style to Code. Or, you can use Format menu and select Code in the Style sub-menu.

Alternatively, you can use Style[#,"Code"] to change the style of selected elements. For example:

text = StringTake[ExampleData[{"Text", "LoremIpsum"}], 400]; 

reStyle = TextCell[Row[List @@ StringReplace[#,  p : Alternatives @@ #2 :> Style[p, "Code"]]], 16, 
              "Panel"] &;

reStyle[text, {"Integer", "condimentum", "porttitor", "vitae", "rutrum", "justo"}]

enter image description here

$\endgroup$
  • 3
    $\begingroup$ this doesn't seem to work for v11. It generates an all-gray area with the code blocks in bold $\endgroup$ – glS Feb 23 '17 at 16:06
  • $\begingroup$ Thank you @glS. Looks like "Panel style definition has been modifed since version 9 to add a gray background. Does adding the option Background->None in TextCell work in version 11? $\endgroup$ – kglr Feb 23 '17 at 17:37
  • $\begingroup$ nope. It makes the background white, but the code blocks also have a white background. $\endgroup$ – glS Feb 23 '17 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.