Function Repository Resource:

 StringStyleJoin

Source Notebook

Join plain and styled strings

Contributed by: Daniele Gregori

ResourceFunction["StringStyleJoin"][s1,s2,s3, …]

join an arbitrary sequence of styled or plain strings as a unique string.

Details

Each argument must be either an explicit String or a string inside a Style wrapper.
It many circumstances (such as creative writing or plot labeling) it is often desirable to format strings with a certain Style, without losing the property of them being an actual String.
Thus StringStyleJoin allows to output a unique string from an arbitrary Sequence of styles or plain strings.
This is made possible essentially through the ToBoxes internal notebook manipulation.

Examples

Basic Examples (1) 

Join different styles in a unique string:

In[1]:=
ResourceFunction["StringStyleJoin"][
 Style["Hello", StandardOrange], " ", Style["World", StandardGreen, Bold]]
Out[1]=

Scope (1) 

Join both styled and plain strings:

In[2]:=
ResourceFunction["StringStyleJoin"][Style["hojo", 15, StandardBlue], Style["to", DarkBlue, 20], "ho..."]
Out[2]=
In[3]:=
ResourceFunction["StringStyleJoin"][
 Style["Hallo,", StandardRed], " ", Style["Ich", StandardOrange], " bin ", Style["Brunhilde!", StandardPurple]]
Out[3]=

Applications (1) 

Easily add styled labels to plots:

In[4]:=
GeoRegionValuePlot[
 <|Rule[
   Entity[
    "AdministrativeDivision", {"CastelliCalepio", "Bergamo", "Lombardy", "Italy"}],
   10^6]|>,
 PlotLabel -> ResourceFunction["StringStyleJoin"]["\n", Style["Energy Expense", Bold, 25], "\n", Style["Castel  de  Conti", Italic, 20], "\n", Style["(N.B. faked example data)", 8]],
 GeoRange -> Quantity[5, "Kilometers"]]
Out[4]=

Properties and Relations (4) 

The output of StringStyleJoin is similar to that of ResourceFunction["StringReplaceRow"], with the main difference being that StringStyleJoin maintains the expression as a String:

In[5]:=
styleRow = ResourceFunction["StringReplaceRow"][
  "find the mispelled word", {"mispelled" -> Style["mispelled", Red, 22]}]
Out[5]=
In[6]:=
styleString = ResourceFunction["StringStyleJoin"]["find the ", Style["mispelled", Red, 22], " word"]
Out[6]=

Compare the heads:

In[7]:=
{Head[styleRow], Head[styleString]}
Out[7]=

Check the corresponding lengths:

In[8]:=
{Length[Normal@styleRow], StringLength[styleString]}
Out[8]=

Inspect all characters in styleString:

In[9]:=
Characters[styleString]
Out[9]=

Publisher

Daniele Gregori

Requirements

Wolfram Language 12.0 (April 2019) or above

Version History

  • 1.0.0 – 17 August 2026

Related Resources

License Information