skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
the string is a samp
description
the semantics of a string output are ambiguous to other outputs. we suggest that strings should be represented with the samp tag.
cells
15 total
4 code
state
executed out of order
kernel
base
language
python
name
base
lines of code
34
outputs
4
table of contents
{"kernelspec": {"display_name": "base", "language": "python", "name": "base"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.9"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "the string is a samp", "description": "the semantics of a string output are ambiguous to other outputs. we suggest that strings should be represented with the samp tag."}
notebook toolbar
Activate
cell ordering
1

the string is a samp

the semantics of a string output are ambiguous to other outputs. we suggest that strings should be represented with the samp tag.

2

string displays

3

the standard python display wraps a string in single questions.

4
    example = "this is the example"
    example
1 outputs.
'this is the example'
5

we could acheive a similar representation with the native samp element.

6
    from IPython.display import HTML
    HTML(F"<samp>{example}</samp>")
1 outputs.
this is the example
7

the samp provides double quotes by default with monospace text. it almost exactly mimics the standard display if you are specific about your quotes.

8

best solution

the best solution would associate the string with the variable. the quickest semantic solution i can think of would look close to.

9
    HTML(F"""<figure>
        <samp>{example}</samp>
        <figcaption><var>example</var></figcaption>
    </figure>""")
1 outputs.
this is the example
example
10

string representations in code.

11

if we are display code containing a string then the story is different. consider the first snippet of python code.

example = "this is the example"
example
12

the source of the string in the code would have the following semantics. when samp contains kbd it indicates an actual key or other unit of input as a portion of a larger input

13
    HTML(html := """
    <pre><code>
        <var>example</var> = <span hidden>"</span><samp><kbd>this is the example</kbd></samp><span hidden>"</span>
        <var>example</var>
    </code></pre>
    """)
1 outputs.

    example = this is the example
    example
14

wraps

15
  • we explored a few confomrations of the samp tag. it seems to hold up as a good semantic for input and output strings.
  • a consistent use of the var tag in code representations and outputs would allow more complex relationships to be inferred from the document.