how to obtain the path of the current .scrbl file?

182 Views Asked by At

Suppose I am running scribble on the file example.scrbl:

    scribble example.scrbl

I want to figure out the path, or at least the name, of the file which is being processed (in this case example.scrbl), programmatically inside the file itself. I thought it would be

    (vector-ref 0 (current-command-line-arguments))

but this does not work. Actually, (current-command-line-arguments) returns empty vector. What is the right way? I want a function which would return the string "example.scrbl".

2

There are 2 best solutions below

3
On BEST ANSWER

As I very recently blogged about you can use (syntax-source #'here) to get the pathname of the current source file.

To adapt that to Scribble you simply need to:

  1. Use at-expressions.
  2. Convert the path to a string for Scribble.

So:

#lang scribble/manual

This Scribble file is @(path->string (syntax-source #'here)).
0
On

You can get the path (without the filename) without resorting explicitly to syntax elements, by using runtime-path:

#lang racket
(require racket/runtime-path)

(define-runtime-path here (simplify-path (build-path 'same)))

(displayln here)