# WXME is pissing me off. :-)

**URL:** <https://racket.discourse.group/t/wxme-is-pissing-me-off/3583>\
**Category:** General\
**Created:** [February 22, 2025, 5:58am UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583 "2025-02-22T05:58:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)\
**Post date:** [February 22, 2025, 5:58am UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/1 "2025-02-22T05:58:13Z")

</div>

I try to use images with my beginning students, but the fact that a "clean" Racket file without images, comment boxes, etc. is pretty much plain text and something that contains those things still has a `.rkt` suffix, but is a much scarier beast is annoying me.

Here are some pain points that WXME files are causing me:

1. I can't search the contents of my files. (I was looking for a misplaced file that contained certain text, but because WXME separates each bit of text onto a separate line, it didn't get found.)
2. I've put all my stuff into a private Github repo so that I can keep track of assignments, easily update them, and keep track of the changes I've made. BUT diffing or even just viewing my files online is not a happy experience.
3. Once you switch to WXME, the tools my school district gives me to use balk at dealing with the files. My students can't preview things on Google Drive, when I upload things to Google Classroom, they're pretty much a black box, and if students want to include Racket work in a portfolio, they have to do screenshots, since they can't expect other people looking at those portfolios to be able to download the files and view them.

This would be somewhat less annoying if I could figure out what WXME actually is so that I could try to manipulate it somehow. But I've looked at the `save-file` and `load-file` methods and darned if I can tell where the numbers at the beginning of each line come from or what the overall structure of the format is.

I know this wouldn't work for a pasteboard or for streaming, but what I'd love is a plain text file format that kept the text as much like it appears in DrRacket as possible and put the images and other snips at the end in a format that could be viewed as plain text (Base64?), maybe with a locator that tells where they belong in the file. Or maybe a multi-file format where the binary bits could be split off into their own locations that wouldn't pollute the program text.

If anybody can give me any hints about where to look for the guts of the code that saves/loads WXME, I'd really appreciate it. I've tried following breadcrumbs and searching for definitions, but because `save-file` and `read-file` are methods, the arrows in DrRacket don't point to them and I haven't been successful searching for `(define (load-file` or `(define (save-file`.

Sorry for the mini-rant, but it's that time of year when spring break is too far away and winter break is long forgotten. 🙂

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [February 22, 2025, 6:13am UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/2 "2025-02-22T06:13:21Z")

</div>

The `wxme-port->text-port` function replaces certain text-ish snips with their text representation and replaces images (or other non-textual data) by `.`.

Here is a script that converts WXME to text and _locally_ incorporates WXME conversion into `git diff`. Of course, it wouldn't work on cloud drives or GitHub, and the output likely can't be executed.

> [@Frustrated at WXME files in git repositories? Set a filter!](https://racket.discourse.group/t/frustrated-at-wxme-files-in-git-repositories-set-a-filter/2568):
>
> Having WXME files in git repositories can be frustrating. They are not readable in other editors. Git can't display them in git diff and git show. But don't give up yet! [Git supports custom filters](https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes) that allows one to customize conversion from binary files to text, which can generate useful outputs when working with binary files. Some git implementation already [include](https://github.com/git-for-windows/build-extra/blob/c223c7757745c1df552c0dd4628c368aaea11f32/git-extra/gitattributes#L13)such [configurations](https://github.com/git-for-windows/build-extra/blob/c223c7757745c1df552c0dd4628c368aaea11f32/git-extra/gitconfig#L11-L12) for [PDFs](https://github.com/git-for-windows/build-extra/blob/c223c7757745c1df552c0dd4628c368aaea11f32/git-extra/astextplain#L27-L29). Let's add one for WXME files. Create this racket-wxme-astext script and make it available in you…

---

<div class="post-metadata">

**Author:** ![shhyou](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@shhyou](https://racket.discourse.group/u/shhyou)\
**Post date:** [February 22, 2025, 6:25am UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/3 "2025-02-22T06:25:24Z")

</div>

Each snip type does its own serialization/deserialization, e.g., numbers ([gui/gui-lib/framework/private/number-snip.rkt at master · racket/gui · GitHub](https://github.com/racket/gui/blob/master/gui-lib/framework/private/number-snip.rkt#L71)), and images (reading: [gui/gui-lib/mrlib/cache-image-snip.rkt at master · racket/gui · GitHub](https://github.com/racket/gui/blob/master/gui-lib/mrlib/cache-image-snip.rkt#L169), writing: [gui/gui-lib/mrlib/cache-image-snip.rkt at master · racket/gui · GitHub](https://github.com/racket/gui/blob/master/gui-lib/mrlib/cache-image-snip.rkt#L137)).

I think what could be done, beyond `wxme-port->text-port`, is using [`wxme-port->port`](https://docs.racket-lang.org/gui/WXME_Decoding.html#%28def._%28%28lib._wxme%2Fmain..rkt%29._wxme-port-~3eport%29%29). (The WXME decoders in this module is separated from the one DrRacket is using, and it read non-textual data into its own classes ([9&nbsp;WXME Decoding](https://docs.racket-lang.org/gui/WXME_Decoding.html#%28part._snipclassmapping%29)) rather than the snips from the GUI library.)

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [February 22, 2025, 8:46pm UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/4 "2025-02-22T20:46:15Z")

</div>

I know it’s not what you asked for, but maybe [GitHub - shriram/racket-embed-images-in-source-text: Reader to enable embedding images in source files as text](https://github.com/shriram/racket-embed-images-in-source-text) is of interest:

> […] It's a small reader extension that lets you embed images in a source program _as text_, so that your whole program doesn't turn into a WXME mess. See the `examples.rkt` file for examples, and the README for an explanation. (In particular, compare `examples.rkt` with `examples-as-images.rkt`.)

Also worth a look is [GitHub - videolang/interactive-syntax: Library for building Interactive Direct Manipulation Tools (IDMTs) in Racket.](https://github.com/videolang/interactive-syntax/tree/master) - specifically the video [https://youtu.be/8htgAxJuK5c](https://youtu.be/8htgAxJuK5c)

I’d like to know if there is support for the idea of adapting the above to support embedded images (sufficiently to complete [Quick: An Introduction to Racket with Pictures](https://docs.racket-lang.org/quick/index.html) by this mechanism ) in DrRacket, [emacs](https://www.racket-mode.com/) , Vim and VSCode (though I believe VSCode has some limitations in this regard)

Stephen

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [February 23, 2025, 4:06pm UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/5 "2025-02-23T16:06:11Z")

</div>

I’m aware that numerous people have seen the capability of including images in code in DrRacket, only to be forced to abandon the idea when it is apparent that it is incompatible with source control and other editors.

While this is probably too large a task for an individual to take on, this might be achievable for a group if it was broken down into separate tasks.

Without committing to do this - what would the roadmap of required tasks to make this possible?

S.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [February 23, 2025, 6:03pm UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/6 "2025-02-23T18:03:33Z")

</div>

On the contrary, Todd, you sound like someone with a lot of energy for implementing things! Or maybe you're just looking for a break from grading.

I think I understand what you want, and I definitely think it's possible, but I also think it's going to be a good deal of work, and could be hard to maintain.

Before I begin, I should say that nearly everything I say here is supposition based on a moderate amount of knowledge, and that Robby is the one with the answers here. Also, @shhyou clearly understands snip-world well. Perhaps by saying things that are vaguely true, I can help you get closer to what you want.

I think the most important bit of information is this: I could be wrong, but I think you're looking for something that translates things to and from WXME format, and I think you're not going to find that, for the simple reason that WXME is actually a fairly direct serialization of DrRacket's internal text representation. In other words, I think it's the _text_ files that are the ones that involve a certain amount of "translation" (though in this case that translation is more of just a filter).

What you're proposing, then, is extending that translation (the one mapping the internal representation to text) to one that can handle things for which the translation is not an obvious one-to-one mapping.

After thinking about this for ... more time than I really should have spent on this? ... I think that your proposed goal of a file format that represents the text precisely in a way that provides the affordances you want is probably very hard; I think the easy way to get your goals (1) and (2) and part of (3) is just to automate a process of always saving a stripped-down text-only version of each file, possibly in something like a "textual" subdirectory. That is, for every source file foo.rkt that you have, you also save "textual/foo.rkt" which contains the text-only representation of this. Note that I'm explicitly suggesting discarding the non-textual snips in this representation. If you build this into the "save" operation, you should be able to get most of what you want, without really touching the guts of DrRacket.

Does this make sense?

---

<div class="post-metadata">

**Author:** ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)\
**Post date:** [February 24, 2025, 11:07pm UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/7 "2025-02-24T23:07:27Z")

</div>

Thank you for mentioning that

> WXME is actually a fairly direct serialization of DrRacket's internal text representation. In other words, I think it's the _text_ files that are the ones that involve a certain amount of "translation" (though in this case that translation is more of just a filter).

That caused a lightbulb to go off, and I found my way to the Editor docs. I did, indeed, misunderstand how things worked and now understand better. It seems like it should be possible to sub-class `editor%` and override the `save-file` and `load-file` methods so that text snips are just output as text and for other snips create a map such that the snips could be output as a header or footer in a text-friendly way. I mean, I think the only awful stuff is images. Comment boxes, fractions, etc. can all be fairly easily be expressed as text and then you could recursively process text boxes.

I probably won't get to this before the summer, but it's something I'd be interested in trying.

I'm also interested in getting more into the guts of Racket and DrRacket. Now that I'm only teaching one class and I only use Racket, it would be nice to understand more of the language and ecosystem, rather than relying on Python or a JVM language to do scripting and such.

---

<div class="post-metadata">

**Author:** ![blerner](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@blerner](https://racket.discourse.group/u/blerner)\
**Post date:** [February 24, 2025, 11:26pm UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/8 "2025-02-24T23:26:44Z")

</div>

In your other thread, I replied with code that already does most of this ([Any way to convert .rkt file to HTML? - #8 by blerner](https://racket.discourse.group/t/any-way-to-convert-rkt-file-to-html/3460/8)) -- does that code not do what you need?

---

<div class="post-metadata">

**Author:** ![ToddOBryan](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/toddobryan/32/1962_2.png) [@ToddOBryan](https://racket.discourse.group/u/ToddOBryan)\
**Post date:** [March 2, 2025, 1:59am UTC](https://racket.discourse.group/t/wxme-is-pissing-me-off/3583/9 "2025-03-02T01:59:00Z")

</div>

I really want just HTML output, not an editor. But what you've provided is useful.
