3

In latex, I can create a new page with the \newpage command. There does not seem to be any way to do this directly in Scribble (at least not for a PDF/Latex back end.)

So, how can I force scribble to make me new page for my document?

Leif Andersen
  • 21,580
  • 20
  • 67
  • 100

1 Answers1

3

Yes, this is doable. It is however a bit clunky, and only works when rendering to a latex file (or pdf file), as this does not make sense for a webpage. The original way I had to do this went into LaTeX. However, it turns out there is a way to do this staying entirely in scribble. Whichever you prefer is obviously going to depend on context, so I've put both options here.

Option 1: Entirely in Scribble Option

The way this works is to use scribble styles with a string for its name. Doing so turns the style into a LaTeX environment or command (depending on what you put it into.) In our case, we want a command, so we will use an element. The resulting code will look something like this:

(define (newpage)
  (make-element (style "newpage" '())
                '()))

Now you can use the newpage function wherever you want and latex will insert a \newpage.

Option 2: Insert raw latex:

The other option is to insert a bit of raw latex code in your scribble file. To do this, you first need to create a file, say: textstyle.tex, and in this file, put:

\newcommand{\identity}[1]{#1}

The name of the file doesn't matter, and if it has other commands in it too is fine. This is just to create a latex command that just evaluates to the same text its given.

Next, somewhere in your scribble code, you can create the following two functions:

(define (exact . items)
  (make-element (make-style "identity" '(exact-chars))
                items))

(define (newpage)
  (exact "\\newpage"))

The first function defines exact, which we can use to insert latex code. This works because The exact-chars style passes the characters into latex verbatim, and does not pass it through any sort of pre-processor. We need the identity stile here so that latex has something to put the text in.

The newpage function is then translated directly into \newpage in latex. Just call it where you want in your code as (newpage) (or @newpage[]/@(newpage) when using at-expressions).

Finally, you need to tell scribble where to find the texstyle.tex file. You can do that with the ++style flag when running scribble. Altogether, your command should look something like:

scribble --pdf ++style texstyle.tex mydocument.scrbl

As an extra, if you want the document to compile for any back end and not just latex/pdf, you can use cond-element. That way you can just have it be an empty element in any other backend:

(define (exact-latex . items)
  (cond-element [latex
                  (make-element (make-style "identity" '(exact-chars))
                                items)]
                [else ....]))

(define (newpage)
  (exact-latex "\\newpage"))
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100