Wolfram Research

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

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]=

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

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

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]=

Scope

ShowQuotes works even if the input is already styled:

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

You can style the output from ShowQuotes:

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

Applications

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]=

Properties and Relations

ShowQuotes[x_] is just Style[x,ShowStringCharactersTrue]. The purpose of the command is mostly to provide a simpler notation.

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[7]:=
InputForm["hello"]
Out[7]=
In[8]:=
Map[Head, {InputForm["hello"], ResourceFunction["ShowQuotes"]["hello"]}]
Out[8]=

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

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

ShowQuotes works within Dataset; compare the following two outputs:

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

Resource History

License Information