
how can I embedd svg snippet in the scribble/manual?

eg. #lang scribble/manual
@(require racket/format)
@(define sample-svg @~a{
<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"<http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd>">
<svg xmlns="<http://www.w3.org/2000/svg>"
width="467" height="462">
<rect x="80" y="60" width="250" height="250" rx="20"
style="fill:#ff0000; stroke:#000000;stroke-width:2px;" />
<rect x="140" y="120" width="250" height="250" rx="40"
style="fill:#0000ff; stroke:#000000; stroke-width:2px;
fill-opacity:0.7;" />
</svg>})

I want sample-svg to be rendered as graphics as part of the manual

@pocmatos If you have a namespace for the file (or for a submodule in the file) you can use namespace-mapped-symbols
to get the candidates. Yes I’ve thought about it: https://github.com/greghendershott/racket-mode/blob/master/racket-complete.el#L85-L86 :slightly_smiling_face: In recent years the preferred way to interface with company-mode is to append these to the list returned by the bog standard completion-at-point-function
.

@githree As it happens I just read yesterday on racket-users mailing list about using @literal
to include things in HTML.


FWIW I like to define SVGs using Racket x-exprs then xexpr->string them. But if you’re copying chunks from existing SVG it’s easier to stick with the text XML.

@greg interesting, so I could use racket-complete-at-point
and use that as a backend to company-mode
?

@pocmatos It is (supposed to) “just work” if you enabled company-mode in a racket-mode buffer.

@greg thank, I can’t make it work though, and in my case the svg will be auto generated -> is literal expected to print the xml or render the graphics (which is what I want?)

(company-mode says, lemme get the completion-at-point-function for this buffer. Oh, it gave me those :company-xxx
values. I’ll use them. i.e. I don’t have any config in my init.el.)

Oh. OK. Should have tried that.

@githree Derp. I need more coffee. I thought you were trying to emit HTML.

It was my fault - I wasn’t clear in the example above - need to edit it

Probably a lot easier to generate an .svg file, then use @image
to load it into your page

I guess it depends on your desired render targets. If just HTML, then I think somehow literal
should get the <svg>
element in the scribble-rendered HTML, and from there displaying it is up to the web browser? But if you care also/instead about PDF/LaTeX output, idk off-hand.

Or if just HTML, what @blerner said. :slightly_smiling_face:

Oh wait, I see. What @blerner said for all the cases.

I was trying to avoid generating files but at least it is some solution


(maybe some clue in its source)

thank you both - I need to go now but have also one idea I will test later with @image being backup plan

@githree If you want to avoid of a file, you can have a value that implements prop:convertible
and supports conversion to 'svg-bytes

@mflatt syntax/module-reader
says it takes a module-path
as defined by require
. require
says that module-path
includes the submod
form. But when I use that I get the error main.rkt:299:2: submod: misuse of module-path constructor (not within, e.g., `require' or `provide')
in: (submod example lang)

It’s possible that this has been updated recently, because I’m not on latest

I just saw a message about this on the list from 2017/05/18 where you noted this and suggest using #:language

Since @greg mentioned the rsvg library, it has a function svg-port->pict
which you can pass any input port that contains an svg document and get a value that should render in scribble docs. So you should be able to just pass it a string (like your sample-svg
) by using open-input-string
to create an input port out of the string.

@mflatt wrt to https://github.com/racket/racket/pull/2166, were you saying that having the user pass in a #:relative-directory
path for serialize
is a bad idea, and its better to just have serialize
use current-write-relative-directory
automatically?

@leif For backward compatibility, I don’t think serialize
should use current-write-relative-directory
automatically. It makes sense to have an optional argument that is the relative-to spec; I just meant that the optional argument(s) should support a two-directory mode as well as a one-directory mode — in the same way that current-write-relative-directory
has both modes.

Ah, okay, ya, that makes sense.

And it does that now.

Also one more question, I just realized that if relative-to
was provided, I was converting both paths to the deserialize-id
, as well as paths in the literal serialized data. I presume that’s wrong and it should only be the paths to deserialize-id
, is that correct?

Both seem useful. Now that you point it out, I can imagine that some uses might want just or one the other.

@greg @blerner @asumu @mflatt all your suggestions were working but I wanted to test an idea and I made it work (still few things to iron out) here is what I did: xml->sxml->make-element (for entire xml tree)

@sean has joined the channel

@greg you are right, completion works. Which package allows you to have a dropdown box of possibilities instead of a new buffer popup?