3

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".

amkhlv
  • 307
  • 2
  • 14

2 Answers2

4

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)).
Greg Hendershott
  • 16,100
  • 6
  • 36
  • 53
  • Thank you. But the location of the source is not necessarily `example.scrbl`. I have `require` statements on the top of `example.scrbl`. All my procedures are defined there. For example, I have `(require helper.rkt)` at the top of `example.scrbl`. I have many procedures defined in that file `helper.rkt`. In defining those procedures, I can invoke `current-command-line-arguments` which gives my the information about how `scribble` was called (for example, if it was single page or multipage). But the name of the `.scrbl` file itself is not reported by `current-command-line-arguments`. – amkhlv Jun 28 '14 at 15:47
  • Your original question said, "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_." (emphasis mine). That's what I showed. If you have a different question, I'm sorry but I can't figure out what it is, from your comment. Maybe you could edit your question to show exactly what you want? – Greg Hendershott Jun 28 '14 at 17:35
  • You are right. Seems like there is no ready solution. I guess I have to write a macro. – amkhlv Jun 29 '14 at 22:28
2

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)
Metaxal
  • 1,083
  • 8
  • 10