close

Function Repository Resource:

ShowQuotes

Source Notebook

Style the output so that quotation marks (as string characters) appear

Contributed by: Seth J. Chandler

ResourceFunction["ShowQuotes"][expr]

shows any quotation marks in expr rather than suppressing them.

Examples

Basic Examples (3) 

Without wrapping the output in ShowQuotes, the front end defaults to suppress presentation of the quotation marks. The ShowQuotes function styles the output so that the quotation marks are visible:

In[1]:=
{"This is a quote", ResourceFunction["ShowQuotes"]["This is a quote"]}
Out[1]=
Image

If there are no quotation marks in the input, no quotation marks appear in the output:

In[2]:=
ResourceFunction["ShowQuotes"][34]
Out[2]=
Image

Nested quotation marks appear with the backslash escape character:

In[3]:=
{"Hamelet said, \"To be or not to be\"", ResourceFunction["ShowQuotes"][
  "Hamelet said, \"To be or not to be\""]}
Out[3]=
Image

Scope (2) 

ShowQuotes works even if the input is already styled:

In[4]:=
ResourceFunction["ShowQuotes"][Style["hello", Red]]
Out[4]=
Image

You can style the output from ShowQuotes:

In[5]:=
Style[ResourceFunction["ShowQuotes"]["goodbye"], Blue]
Out[5]=
Image

Applications (1) 

Often, one might want to postfix ShowQuotes so that the textual input stands out:

In[6]:=
"By applying ShowQuotes using the postfix // notation, I draw attention away from the command in a way that is not the case when I have to write something like Style[\"Hello\",\"ShowStringCharacters->True\"" // ResourceFunction[
 "ShowQuotes"]
Out[6]=
Image

Properties and Relations (4) 

ShowQuotes[x_] is equivalent to Style[x,ShowStringCharacters->True]. The purpose of the command is mostly to provide a simpler notation:

In[7]:=
#["This is a quote"] & /@ {ResourceFunction["ShowQuotes"], Style[#, ShowStringCharacters -> True] &}
Out[7]=
Image

InputForm will generally result in the string characters being visible, but the cell label will have a //InputForm postfixed. Also, notice that the Head of the InputForm of "hello" is InputForm, whereas the Head of a ShowQuotes expression is Style:

In[8]:=
InputForm["hello"]
Out[72]=
Image
In[73]:=
Map[Head, {InputForm["hello"], ResourceFunction["ShowQuotes"]["hello"]}]
Out[73]=
Image

Be wary of order of operations when using the postfix form of ShowQuotes:

In[74]:=
includesStyle = "If I don't wrap this in parentheses, the assignment includes the style" // ResourceFunction["ShowQuotes"]
Out[74]=
Image
In[75]:=
(excludesStyle = "If I do wrap this in parentheses, the assignment does not include the style") // ResourceFunction["ShowQuotes"]
Out[75]=
Image
In[76]:=
{includesStyle, excludesStyle}
Out[76]=
Image

ShowQuotes works within Dataset. Compare the following two outputs:

In[77]:=
{Dataset["hello"], Dataset["hello" // ResourceFunction["ShowQuotes"]]}
Out[77]=
Image

Publisher

Seth J. Chandler

Version History

  • 1.0.0 – 10 July 2019

License Information