How to use `head-extra` in scribble?

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:

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.

1 Like

Hi @KDr2

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

Here is an example:

(define (add-defaults doc pfx styl extras version?
                      #:html [html #f]
                      #:properties [properties null])
   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
                          ; --- 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)))))]))                     
1 Like

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

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

So something like this:

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

Oh, thank you, I made it:

(define favicon (make-style
                 (list (head-extra
                        '(link ([rel "shortcut icon"]
                                [type "image/png"]
                                [href ""]))))))

and then

@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?

1 Like

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)

#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)

I got the template for the my-title here:


Thank you in advance!