Hi Mosè and David,

>>>>> David Kastrup <d...@gnu.org> writes:
> Mosè Giordano <m...@gnu.org> writes:

>> I seem to remember David explained that "\input" was used to make
>> something work (region-compilation?).  I looked for this explanation
>> in my inbox but I can't find it, hopefully David can tell us more.  If
>> "\input" is really not needed anymore then removing "\input" when
>> calling TeX is a good solution.

> I think it was for setting interaction mode in a reasonably portable
> way.  At the current point of time, we likely just have to deal with
> MikTeX and TeXlive.

Thank you for responses.  I performed search on the ML archive and seem
to find the David's message which Mosè mentioned:
https://lists.gnu.org/archive/html/auctex-devel/2008-05/msg00055.html

First, David worried about the case some TeX codes are put on the
command line like this:
        latex -interaction=nonstopmode \SOME_CODE FILENAME
My impression is that such case is extremely rare, at least when the
default `TeX-command-list' is used.  (In theory, a user can put TeX
codes by either setting `TeX-command-extra-options' or customizing
`TeX-expand-list' to override the default expansion of the directives
such as "%(mode)", "%(file-line-error)" and so on, but...)  So I expect
we can live without \input as long as we take care of preview-latex to
work with \input.
David, what do you think about this?

Next, David pointed out that removing \input does not help %&-parsing of
the first line in the case of region compilation.  (This is not a reason
that \input is necessary, I think.)
This is a problem I looked over, and I expect that the attached
additional patch covers the point.

Regards,
Ikumi Keita

P.S.  Two notes about my previous patch
(1) According to texdoc etex, \detokenize was added in e-TeX extension.
So if the user has quite old TeX distribution where e-TeX extension was
not incorporated in the engine (command binary) yet, \detokenize raises
error.  I hope this is a permissible incompatibility.

(2) This patch incidentally fixes Bug#25276:
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=25276
The problem is present only in xetex engine on w32 platform.  Both the
form without \input and with \input \detokenize{} works well even when
the file name contains space, while the form with \input only (original
AUCTeX form) stops with an error.

diff --git a/tex-buf.el b/tex-buf.el
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -2092,8 +2092,10 @@
 			   (if (not (re-search-forward TeX-header-end nil t))
 			       ""
 			     (re-search-forward "[\r\n]" nil t)
-			     (buffer-substring (point-min) (point)))))))))
+			     (buffer-substring-no-properties
+			      (point-min) (point)))))))))
 	 (header-offset 0)
+	 first-line
 	 ;; We search for the trailer from the master file, if it is
 	 ;; not present in the region.
 	 (trailer-offset 0)
@@ -2113,11 +2115,24 @@
 			      ;;(beginning-of-line 1)
 			      (re-search-backward "[\r\n]" nil t)
 			      (setq trailer-offset (TeX-current-offset))
-			      (buffer-substring (point) (point-max))))))))))
+			      (buffer-substring-no-properties
+			       (point) (point-max))))))))))
     ;; file name should be relative to master
     (setq original (TeX-quote-filename (file-relative-name
 					original (TeX-master-directory)))
 	  master-name (TeX-quote-filename master-name))
+
+    ;; Cater for %&FORMAT construct in the first line.
+    (setq first-line (if (and (> (length header) 1)
+			      (string= (substring header 0 2) "%&"))
+			 ;; This would work even if header has no newline.
+			 (substring header 0 (string-match "\n" header))
+		       ""))
+    (unless (string= first-line "")
+      ;; Remove first-line from header.
+      (setq header (substring header (length first-line)))
+      (setq first-line (concat first-line "\n")))
+
     (with-current-buffer file-buffer
       (setq buffer-read-only t
 	    buffer-undo-list t)
@@ -2127,7 +2142,8 @@
 	(when (boundp 'buffer-file-coding-system)
 	  (setq buffer-file-coding-system
 		(with-current-buffer master-buffer buffer-file-coding-system)))
-	(insert "\\message{ !name(" master-name ")}"
+	(insert first-line
+		"\\message{ !name(" master-name ")}"
 		header
 		TeX-region-extra
 		"\n\\message{ !name(" original ") !offset(")
_______________________________________________
auctex mailing list
auctex@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex

Reply via email to