[plt-scheme] slatex error

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Mon Jan 23 19:29:03 EST 2006


On Mon, 23 Jan 2006, Jay McCarthy wrote:

> Anyone know how to convert this into something a bit more useful? Like
> which scheme block or file contained the problem?


Hi Jay,

Would it be ok to hack up SLaTeX to preserve that information in the error
message?  I haven't tested this yet (haven't set up tetex on my system
yet), but would something like this be acceptable?



bash-3.00$ svn diff
Index: slatex.ss
===================================================================
--- slatex.ss	(revision 1935)
+++ slatex.ss	(working copy)
@@ -1,6 +1,22 @@
 (module slatex mzscheme
   (provide slatex::process-main-tex-file)

+
+(define slatex::call-with-input-file
+  (lambda (filename port-func)
+    (call-with-input-file filename
+      (lambda (in)
+        (set! slatex::*in-filename* filename)
+	(port-count-lines! in)
+	(port-func in)))))
+
+
+(define slatex::call-with-output-file
+  (lambda (filename thunk)
+    (call-with-output-file filename thunk)))
+
+
+
 (define-syntax slatex::setf
   (lambda (so)
     (datum->syntax-object
@@ -183,6 +199,18 @@
     (for-each (lambda (v) (write v) (newline)) what)
     (error "slatex-error")))

+
+(define slatex::slatex-in-file-error
+  (lambda (where . what)
+    (display "Error: ")
+    (display where)
+    (newline)
+    (let-values (((line col pos) (port-next-location slatex::*in*)))
+      (printf "~s: line ~s, column ~s, position ~s~%"
slatex::*in-filename* line col pos))
+    (for-each (lambda (v) (write v) (newline)) what)
+    (error "slatex-line-error")))
+
+
 (define slatex::exit-slatex (lambda () (exit)))

 (define slatex::*slatex-case-sensitive?* #t)
@@ -392,6 +420,8 @@

 (define slatex::*in* 'fwd3)

+(define slatex::*in-filename* "UNDEFINED")
+
 (define slatex::*out* 'fwd4)

 (define slatex::*in-qtd-tkn* 'fwd5)
@@ -652,7 +682,7 @@
                   &end-string))
                ((eq? curr-notab &mid-comment) (set! curr-notab
&void-notab))
                ((eq? curr-notab &mid-math)
-                (slatex::slatex-error
+                (slatex::slatex-in-file-error
                   'slatex::get-line
                   "Sorry, you can't split "
                   "math formulas across lines in Scheme code")))
@@ -1967,7 +1997,7 @@
           (display raw-filename)
           (display "]")
           (flush-output))
-        (call-with-input-file
+        (slatex::call-with-input-file
           filename
           (lambda (in)
             (let ((done? #f))
@@ -2223,7 +2253,7 @@
           (display ".")
           (flush-output)
           (if (file-exists? aux.tex) (delete-file aux.tex))
-          (call-with-input-file
+          (slatex::call-with-input-file
             filename
             (lambda (in)
               (call-with-output-file
@@ -2262,7 +2292,7 @@
             (slatex::slatex-error
               "trigger-scheme2tex: ~\n                          Unknown
triggerer ~s."
               typ)))))
-      (call-with-input-file
+      (slatex::call-with-input-file
         aux.scm
         (lambda (in)
           (call-with-output-file
@@ -2320,7 +2350,7 @@
                 typ)))))
         (slatex::process-tex-file aux2.tex)
         (set! slatex::*protected-files* (reverse! slatex::*protected-files*))
-        (call-with-input-file
+        (slatex::call-with-input-file
           aux2.tex
           (lambda (in)
             (call-with-output-file
@@ -2409,7 +2439,7 @@
      (else
       (let ((f (car slatex::*protected-files*)))
         (set! slatex::*protected-files* (cdr slatex::*protected-files*))
-        (call-with-input-file
+        (slatex::call-with-input-file
           f
           (lambda (in) (slatex::inline-protected-files in out)))
         (delete-file f))





Best of wishes!



Posted on the users mailing list.