# Copy/paste from scribble/acmart @sigplan into DrRacket?

**URL:** <https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078>\
**Category:** Questions & Answers\
**Tags:** drracket, scribble\
**Created:** [July 6, 2023, 6:21pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078 "2023-07-06T18:21:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 6, 2023, 6:21pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/1 "2023-07-06T18:21:15Z")

</div>

This should be a short example document that produces the problem:

```scheme
#lang scribble/acmart @sigplan @screen

@(require scriblib/figure
          (only-in scribble/manual racketmod0))

@title{Title}

@section{Section}

@figure["easy-counter.rkt"
        "A counter GUI using GUI Easy's functional widgets."
        @racketmod0[
        racket/gui/easy
        (define |@|count (|@| 0))
        (render
         (window
          #:title "Counter"
          (hpanel
           (button "-" (λ () (<~ |@|count sub1)))
           (text (~> |@|count number->string))
           (button "+" (λ () (<~ |@|count add1))))))]]

```

Make a PDF with

```scheme
raco scribble --pdf example.scrbl

```

Assuming you have GUI Easy installed (`raco pkg install gui-easy`), you might want to copy-paste the codeblock into DrRacket and run the example.

Punchline: you can't. The font has somehow transformed the `~`, among other characters (including the lambda). DrRacket is able to reacquire the lambda, but not the `~` characters. Here's a hex dump of what I get:

```scheme
00000000: 236c 616e 6720 7261 636b 6574 2f67 7569 #lang racket/gui
00000010: 2f65 6173 790a 2864 6566 696e 6520 4063 /easy.(define @c
00000020: 6f75 6e74 2028 4020 3029 290a 2872 656e ount (@ 0)).(ren
00000030: 6465 720a 2028 7769 6e64 6f77 0a20 2023 der. (window. #
00000040: 3a74 6974 6c65 2022 436f 756e 7465 7222 :title "Counter"
00000050: 0a20 2028 6870 616e 656c 0a28 6275 7474 . (hpanel.(butt
00000060: 6f6e 2022 2d22 2028 f09d 9c86 2028 2920 on "-" (.... () 
00000070: 283c e288 bc20 4063 6f75 6e74 2073 7562 (<... @count sub
00000080: 3129 2929 2028 7465 7874 2028 e288 bc3e 1))) (text (...>
00000090: 2040 636f 756e 7420 6e75 6d62 6572 2d3e @count number->
000000a0: 7374 7269 6e67 2929 2028 6275 7474 6f6e string)) (button
000000b0: 2022 2b22 2028 f09d 9c86 2028 2920 283c "+" (.... () (<
000000c0: e288 bc20 4063 6f75 6e74 2061 6464 3129 ... @count add1)
000000d0: 2929 2929 29 )))))

```

The lambda became the sequence `f0 9d 9c 86` and the `~` became `e2 88 bc`.

* * *

Does anyone know how I can configure Scribble (either via font or some other "really I mean it" mechanism) to produce copy-and-runnable code?

I suspect using `racketmod0` from `scribble/manual` may be part of my issue, but I've gone through several different mechanisms to try to get good Racket figures in the PDF and this is what I've settled on for `#lang`-based figures.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 6, 2023, 7:54pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/2 "2023-07-06T19:54:11Z")

</div>

Maybe related?

[https://www.reddit.com/r/LaTeX/comments/t8ly61/unable\_to\_copy\_words\_with\_f\_or\_similar\_letters/](https://www.reddit.com/r/LaTeX/comments/t8ly61/unable_to_copy_words_with_f_or_similar_letters/)

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 6, 2023, 8:32pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/3 "2023-07-06T20:32:13Z")

</div>

Thanks, that encouraged me to look at the LaTeX source; I see

```scheme
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

```

at the top.

I also see that `<~` has been converted to `\RktSym{{\Stttextless}$\sim$}` in the LaTeX source; I'm certain that's part of the problem. I really want to just use a `~` character. (The conversion of `<` to `{\Stttextless}` doesn't seem to be a bother.)

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 6, 2023, 8:59pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/4 "2023-07-06T20:59:49Z")

</div>

Here is the special case for ~:

> <https://github.com/racket/scribble/blob/master/scribble-lib/scribble/latex-render.rkt#L1078>

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 6, 2023, 9:19pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/5 "2023-07-06T21:19:30Z")

</div>

Another piece to the puzzle.

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/b/bd82d9830b2f73d115572611e840c9245ccb4051.png)

From: [What is the best way to produce a tilde in LaTeX for a website? - Stack Overflow](https://stackoverflow.com/questions/718479/what-is-the-best-way-to-produce-a-tilde-in-latex-for-a-website)

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 7, 2023, 4:13pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/6 "2023-07-07T16:13:36Z")

</div>

Some intreprid digging which included copying and modifying scribble/run.rkt to add my own mixin wrappers around `render-content` and `render-other` to display certain inputs reveals the following chain (even when using `#,(make-element symbol-color "<~")`):

1. Eventually we get to the `element` that includes the `<~`; this is handed to the latex-renderer's `render-content`.
2. After some pre-processing, it calls `(super render-content …)` with the same element. Assuming that's base-renderer, the method calls `(render-content (element-content i) …)`, which is `(render-content "<~" …)`.
3. This repeats latex-renderer's pre-processing and `(super render-content "<~" …)`.
4. Now, base-renderer calls `(render-other "<~" …)` because it has a string.

As pointed out, `render-other` in the LaTeX renderer cooperates with `display-protected` to turn `~` into `$\sim$`.

* * *

So, I think what I need is a way to bypass this and insert some other LaTeX command to generate a _real_ tilde.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 7, 2023, 4:32pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/7 "2023-07-07T16:32:35Z")

</div>

> So, I think what I need is a way to bypass this and insert some other LaTeX command to generate a _real_ tilde.

Inserting a real tilde is just what the Stackoverflow thread was about:

> <https://stackoverflow.com/questions/718479/what-is-the-best-way-to-produce-a-tilde-in-latex-for-a-website>

Since tilde is a special character in LaTeX, they needed some trickery (using catcode) to produce a real tilde. They needed it in order to copy/paste urls containing tilde. But the same trick ought to work in your context.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 7, 2023, 5:07pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/8 "2023-07-07T17:07:21Z")

</div>

> But the same trick ought to work in your context.

Yes, though I need to figure out / remind myself how to insert  
arbitrary LaTeX in the document at the right places, hopefully without  
making it too hard to type the code examples.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 7, 2023, 6:19pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/9 "2023-07-07T18:19:40Z")

</div>

Aha! The following allowed me to use `#,<~` and `#,~>` to get what I want, thanks to `\textasciitilde{}` producing something reasonable that also works with copy/paste:

```scheme
#lang scribble/acmart @sigplan @screen

@(require scriblib/figure
          scribble/core
          (only-in scribble/manual racketmod0)
          (only-in scribble/racket symbol-color))

@(define ~ (make-element "textasciitilde" ""))
@(define <~ (make-element symbol-color (list "<" ~)))
@(define ~> (make-element symbol-color (list ~ ">")))

@title{Title}

@section{Section}

@figure["easy-counter.rkt"
        "A counter GUI using GUI Easy's functional widgets."
        @racketmod0[
        racket/gui/easy
        (define |@|count (|@| 0))
        (render
         (window
          #:title "Counter"
          (hpanel
           (button "-" (λ () (#,<~ |@|count sub1)))
           (text (#,~> |@|count number->string))
           (button "+" (λ () (#,<~ |@|count add1))))))]]

```

How? The `(make-element "textasciitilde" "")` will be converted to `\textasciitilde{}` by the LaTeX renderer; then we just wrap it with `<` or `>` in the right position, and colored by the `symbol-color` style (which is what `racketidfont` uses, IIRC; I spent so much tme staring at scribble source I don't remember exactly how I found that style).

In Vim, the command `:v/make-element/s/\v(#,)@<!(\<\~|\~\>)/#,&/ge` will replace all non-unsyntaxed occurrences of the two arrows with unsyntaxed versions (at least, the ones not on lines containing `make-element`, which suffices in my case).

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 7, 2023, 6:26pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/10 "2023-07-07T18:26:20Z")

</div>

You cracked it!

But does `\textasciitilde` produce the right tilde?

> <https://tex.stackexchange.com/questions/312/correctly-typesetting-a-tilde>

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 7, 2023, 6:30pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/11 "2023-07-07T18:30:48Z")

</div>

Reading the last answer too, I see that `\textasciitilde` ought to work.  
Except for computer modern - which of course was used by the OP.

[\textasciitilde](https://tex.stackexchange.com/a/2883/34489)

---

<div class="post-metadata">

**Author:** ![ben\_greenman](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/ben_greenman/32/632_2.png) [@ben\_greenman](https://racket.discourse.group/u/ben_greenman)\
**Post date:** [July 8, 2023, 4:08am UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/12 "2023-07-08T04:08:56Z")

</div>

it's painful but you can wrap text to keep it exactly:

> <https://github.com/bennn/scribble-abbrevs/blob/master/private/latex.rkt#L26C2-L26C2>

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [July 8, 2023, 4:35am UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/13 "2023-07-08T04:35:56Z")

</div>

I think changing `\sym` to `\textasciitilde` is probably a good idea. We might also want to do something so that computer modern isn't the default `tt` font too? I thought that acmart doesn't use computer modern, tho?

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [July 8, 2023, 11:03am UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/14 "2023-07-08T11:03:50Z")

</div>

The StackOverflow post was from 2010 - so perhaps the bug has been fixed in the mean time?

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [July 8, 2023, 3:38pm UTC](https://racket.discourse.group/t/copy-paste-from-scribble-acmart-sigplan-into-drracket/2078/15 "2023-07-08T15:38:49Z")

</div>

See [Why is `~` converted to `$\sim$` by the LaTeX renderer? · Issue #370 · racket/scribble · GitHub](https://github.com/racket/scribble/issues/370) which I filed as a result.

According to [https://github.com/racket/scribble/blob/97d5b34742b12346da2e48c979cf1979232f0712/scribble-lib/scribble/acmart/acmart.cls#L818-L850](https://github.com/racket/scribble/blob/97d5b34742b12346da2e48c979cf1979232f0712/scribble-lib/scribble/acmart/acmart.cls#L818-L850) the `acmart` class tries very hard to use Libertine for text and math fonts and to use Incosolata for typewriter fonts.
