# How to use \`head-extra\` in scribble?

**URL:** <https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371>\
**Category:** Questions & Answers\
**Tags:** scribble\
**Created:** [October 11, 2022, 2:46am UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371 "2022-10-11T02:46:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KDr2](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kdr2/32/755_2.png) [@KDr2](https://racket.discourse.group/u/KDr2)\
**Post date:** [October 11, 2022, 2:46am UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/1 "2022-10-11T02:46:18Z")

</div>

I want to add a favicon to my website which is built with scribble, but when I put something like  
`(make-head-extra ...)` into my scribble file, it tells me that:

```scheme
not valid in document body (need a pre-part for decode) in: (head-extra...)

```

Anyone knows the way to use it? I failed to find an example from the official docs.

---

<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:** [October 11, 2022, 8:47am UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/2 "2022-10-11T08:47:05Z")

</div>

Hi @KDr2

The idea is that `head-extra` structures can be used in styles.

Here is an example:

```scheme
(define (add-defaults doc pfx styl extras version?
                      #:html [html #f]
                      #:properties [properties null])
  (struct-copy 
   part doc 
   [style (make-style (style-name (part-style doc))
                       ; Add <script>...</script> to the <head>...</head> portion of html.
                       (append (style-properties (part-style doc)) ; existing styles
                         (list 
                          ; --- MathJax support ---
                          (head-extra ; This loads MathJax from mathjax-source
                             `(script ([type "text/javascript"] [src ,mathjax-source])))
                         (head-extra ; This loads the given extensions. 
                             `(script ([type "text/x-mathjax-config"]) ,extentions)))))]))                     

```

---

<div class="post-metadata">

**Author:** ![KDr2](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kdr2/32/755_2.png) [@KDr2](https://racket.discourse.group/u/KDr2)\
**Post date:** [October 11, 2022, 10:51am UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/3 "2022-10-11T10:51:59Z")

</div>

Thanks, but where should I place this function and when/how to call it?

---

<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:** [October 11, 2022, 11:34am UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/4 "2022-10-11T11:34:19Z")

</div>

The function above was just meant to illustrate that  
`head-extra` is used with `make-style`.

So something like this:

```scheme
(make-style (head-extra ...))

```

---

<div class="post-metadata">

**Author:** ![KDr2](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kdr2/32/755_2.png) [@KDr2](https://racket.discourse.group/u/KDr2)\
**Post date:** [October 11, 2022, 12:08pm UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/5 "2022-10-11T12:08:54Z")

</div>

Oh, thank you, I made it:

```scheme
(define favicon (make-style
                 'favicon
                 (list (head-extra
                        '(link ([rel "shortcut icon"]
                                [type "image/png"]
                                [href "https://res.cloudinary.com/kdr2/image/upload/img-kdr2-com/main/jib-favicon.png"]))))))

```

and then

```scheme
@title[#:style favicon]{...}
@section[#:style favicon]{...}
@section[#:style favicon]{...}

```

The last problem is that I should associate the style with every section to make all pages (each section a page) have that favicon. It there a way to write it only once and apply it to every page?

---

<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:** [October 11, 2022, 12:29pm UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/6 "2022-10-11T12:29:07Z")

</div>

You can make a new file "utils.rkt" and export your own versions and then  
use `@(require "utils.rkt")` in your scriible file:

Something like this (untested)

```scheme
#lang racket
(provide (rename-out [my-title title]))

(define (my-title #:tag [tag #f] #:tag-prefix [prefix #f] #:style [style favicon]
               #:version [version #f] #:date [date #f]
               . str)
 (keyword-apply title 
         '( #:date #:tag #:tag-prefix #:style #:version)
          (list date tag prefix style version)
        str))

```

I got the template for the my-title here:

> <https://github.com/racket/scribble/blob/master/scribble-lib/scribble/base.rkt>

---

<div class="post-metadata">

**Author:** ![KDr2](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kdr2/32/755_2.png) [@KDr2](https://racket.discourse.group/u/KDr2)\
**Post date:** [October 11, 2022, 12:35pm UTC](https://racket.discourse.group/t/how-to-use-head-extra-in-scribble/1371/7 "2022-10-11T12:35:28Z")

</div>

Thank you in advance!
