--- auctex-11.87.orig/tex-buf.el 2012-11-26 20:56:21.000000000 +0100 +++ auctex-11.87.tmp/tex-buf.el 2014-08-24 12:20:09.911400123 +0200 @@ -334,7 +334,7 @@ (concat (and (stringp TeX-command-pos) TeX-command-pos) (apply ',file args) (and (stringp TeX-command-pos) TeX-command-pos))))) - case-fold-search string expansion arguments) + expansion-res case-fold-search string expansion arguments) (setq list (cons (list "%%" (lambda nil (setq pos (1+ pos)) @@ -357,7 +357,13 @@ (TeX-function-p expansion)) (apply expansion arguments)) ((boundp expansion) - (apply (eval expansion) arguments)) + (setq expansion-res + (apply (eval expansion) arguments)) + (when (eq expansion 'file) + ;; Advance past the file name in order to + ;; prevent expanding any substring of it. + (setq pos (+ pos (length expansion-res)))) + expansion-res) (t (error "Nonexpansion %s" expansion))))) (if (stringp string)