I want to store LaTeX representations as Literal values.

Without escaping (with “\”), I get what I want with JSON-LD (e.g. “\text”) 
but not with Turtle et al. (I get “ext”).

With escaping, I get double slashes (e.g. “\text”) with JSON-LD, Turtle, 
and N-Triples, but I get what I want (“\text”) with XML.

Any suggestions? I’m not sure if there’s a bug here or if there’s a 
workaround I can do.

Here’s a reproduction of my problem:

from rdflib import Graph, URIRef, RDFS, Literal

g = Graph()
g.add((
    URIRef("http://example.com/node";),
    RDFS.comment,
    Literal("SHAPE: $n_{\text{sites}} \times 3 \times 3$")
))
g.add((
    URIRef("http://example.com/node";),
    RDFS.comment,
    Literal("SHAPE: $n_{\\text{sites}} \\times 3 \\times 3$")
))
print("JSON-LD:")
print(g.serialize(format="application/ld+json"))
print("\nTurtle:")
print(g.serialize(format="text/turtle"))
print("XML:")
print(g.serialize(format="application/rdf+xml"))
print("N-Triples:")
print(g.serialize(format="nt"))

JSON-LD:
[
  {
    "@id": "http://example.com/node";,
    "http://www.w3.org/2000/01/rdf-schema#comment": [
      {
        "@value": "SHAPE: $n_{\text{sites}} \times 3 \times 3$"
      },
      {
        "@value": "SHAPE: $n_{\\text{sites}} \\times 3 \\times 3$"
      }
    ]
  }
]

Turtle:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<http://example.com/node> rdfs:comment "SHAPE: $n_{        ext{sites}}         
imes 3         imes 3$",
        "SHAPE: $n_{\\text{sites}} \\times 3 \\times 3$" .

XML:
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#";
>
  <rdf:Description rdf:about="http://example.com/node";>
    <rdfs:comment>SHAPE: $n_{        ext{sites}}         imes 3         imes 
3$</rdfs:comment>
    <rdfs:comment>SHAPE: $n_{\text{sites}} \times 3 \times 3$</rdfs:comment>
  </rdf:Description>
</rdf:RDF>

N-Triples:
<http://example.com/node> <http://www.w3.org/2000/01/rdf-schema#comment> 
"SHAPE: $n_{        ext{sites}}         imes 3         imes 3$" .
<http://example.com/node> <http://www.w3.org/2000/01/rdf-schema#comment> 
"SHAPE: $n_{\\text{sites}} \\times 3 \\times 3$" .

screenshot of pretty-printed output: 
https://files.polyneme.xyz/dropshare/2022-02-23-rdflib-dev-pprint-UM2FfmQBDv.png
.
​

-- 
http://github.com/RDFLib
--- 
You received this message because you are subscribed to the Google Groups 
"rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rdflib-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rdflib-dev/695124c0-c9ab-4606-8fde-200f8a301296n%40googlegroups.com.

Reply via email to