Diagrams in a Scribble document

I's like to have diagrams in a Scribble document.
Now diagrams are build from lines, geometrical objects. and text.
The text in the diagrams should have the same typography as the rest if the Scribble text.

Now there are ways to embed images in Scribble by putting them in separate files and linking to them.
But this separates them from their contextual source code and creates additional difficulties:

  • Making those diagrams separately.
  • dealing with a lot of file names.
  • Making it really hard to see what diagrams are where when editing source code. File names don't look like diagrams at all.
  • And the usual image file formats for images are bulky.

So I want to embed the instructions for making the diagrams in the Scribble text and further embed pieces of Scribble text within those instructions.

Now HTML has a mechanism for efficiently embedded diagrams: SVG.
And so does LATEX.
And Racket has a variety of mechanisms for describing pictures.

I'd like to describe the construction of diagrams in the document source code and have it converted to either of these two output forms, whichever is being used for presenting the final document.

Are there already any tools for this within the rather large Racket ecosystem? Would they be hard to set up if not?

-- hendrik

1 Like

Picts can be used directly in Scribble - make sure that picts are rendered as svgs.
In order to use LaTeX-formulas I use the latex-pict package.
The functions tex-math and tex-display-math renders LaTeX math formulas
into a pict. The pict can then be used labels, legends, etc.

See my blog for examples on the result:

https://www.stxmat.dk/blog/

Notes: If you decide to test latex-pict then be aware that DrRacket can't render the picts produced, so in the DrRacket repl you need to wrap it in an pict->bitmap.
The same problem doesn't exists in racket-mode (Emacs), since it always converts
picts to images.

Notes: You need to have Latex installed (I think, latex-pict works with TeX Live, but
if you have a different distribution, you might need to change the settings).

There's also some code typeseting for picts in https://docs.racket-lang.org/pict/More_Pict_Constructors.html#%28part..Typesetting.Racket_.Code%29