Re: TeX-master and TeX-output-master

2020-10-17 Thread Uwe Brauer
>>> "AH" == Al Haji-Ali  writes:

Hi Al


> Hello Uwe,
>> I tested it, it works thanks. Later I will try out Index and friends

> Great! If something doesn't work, can you please include an example
> tex file for me to test? As I said, I don't use "index and
> friends".

Only by now I had the time to tried out index and friends in my case
nomenclature (it is the only one of the three: index glossary and
nomenclature that I use on larger articles)

To make a long story short I cannot generate the required files, on
reason similar to the bibtex problem. I attach a latex file with a
mininal example and the error message which pops up if I set a build
directory.

You have 

1. To run latex once

2. Then run makeindex testglossary.nlo -s nomencl.ist -o testglossary.nls

3. Then run latex again

However 2 fails.

>> I find this patch very useful for directories that contain very tex
>> files since all the aux files create a bit of a mess.


> Agreed. That's my motivation for it. Although I noticed that you
> use a global directory for all tex files: "/home/oub/blabla/built".

Right that is a valid point.

> Also, you may find the following two functions useful. If executed

Thanks. I did not notice them when I read your message first :-[
thanks I will give it a try 


> (defun copy-tex-output ()

Regards

Uwe 

makeindex testglossary.nlo -s nomencl.ist -o testglossary.nls

Running `makegloss' on `testglossary' with ``makeindex testglossary.nlo -s 
nomencl.ist -o testglossary.nls''
Input index file testglossary.nlo not found.
Usage: makeindex [-ilqrcgLT] [-s sty] [-o ind] [-t log] [-p num] [idx0 idx1 ...]

TeX Output exited abnormally with code 1 at Sat Oct 17 15:16:29
\documentclass[12pt]{article}
\usepackage{a4wide}


\setlength{\parindent}{0pt}
\sloppy

\parskip=5pt plus 5pt
\oddsidemargin-10pt

\usepackage{latexsym}
%{{{ nomenclature
%\usepackage[refpage,refeq,intoc]{nomencl}
\usepackage[refpage]{nomencl}

%% \usepackage[pageanchor]{hyperref}
%% \def\pagedeclaration#1{, \hyperlink{page.#1}{page\nobreakspace#1}}

\makeglossary
\makenomenclature
\makeindex
%\renewcommand{\nomentryend}{.}

\def\nomentryend{.}
\def\nomlabel#1{\textbf{#1}\hfil}


%}}}
%{{{ Kopka Nomenclature style, write a separate .sty file

\makeatletter

\def\@@@nomenclature[#1]#2#3{%
\def\@tempa{#2}\def\@tempb{#3}%
\protected@write\@nomenclaturefile{}%
{\string\nomenclatureentry{#1\nom@verb\@tempa @[{\nom@verb\@tempa}]%
|nompageref{\begingroup\nom@verb\@tempb\protect\nomeqref{\theequation}}}%
{\thepage}}%
\endgroup
\@esphack}
\def\nompageref#1#2{%
\if@printpageref\pagedeclaration{#2}\else\null\fi
\linebreak#1\nomentryend\endgroup}
\def\pagedeclaration#1{\dotfill\nobreakspace#1}
\makeatother

%}}}


\renewcommand{\nomentryend}{.}



\begin{document}
Hello

\nomenclature{this}{that}

\printnomenclature
\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:



smime.p7s
Description: S/MIME cryptographic signature


Re: TeX-master and TeX-output-master

2020-09-10 Thread Al Haji-Ali
Hello Uwe,

> I tested it, it works thanks. Later I will try out Index and friends
Great! If something doesn't work, can you please include an example tex file 
for me to test? As I said, I don't use "index and friends".

> I find this patch very useful for directories that contain very tex
> files since all the aux files create a bit of a mess.
Agreed. That's my motivation for it. Although I noticed that you use a global 
directory for all tex files: "/home/oub/blabla/built". I would be careful about 
doing that as having multiple tex files with the same name could create 
conflicting files in this directory. I use a relative path instead so that a 
directory is created next to the tex files which avoids the issue of name 
duplicates.

Also, you may find the following two functions useful. If executed on a tex 
file, the first copies the master output file (pdf or dvi) from the output 
directory to any directory (defaults to root master directory), the second 
function attaches the output file from the output directory to an email

(defun copy-tex-output ()
   (interactive)
   (let* ((default (expand-file-name (TeX-active-master nil)))
  (default-dir (file-name-directory default))
  (default-file (concat (file-name-nondirectory default) "." 
(TeX-output-extension)))
      (outputfile (expand-file-name (TeX-active-master 
(TeX-output-extension
  (filename (read-file-name "Save as:" default-dir
 default-file nil default-file)))
 (copy-file outputfile filename t)))


(defun attach-tex-output ()
   (interactive)
   (require 'gnus-dired)
   (gnus-dired-attach (list (expand-file-name (TeX-active-master 
(TeX-output-extension))

Best regards,
-- Al



Re: TeX-master and TeX-output-master

2020-09-10 Thread Uwe Brauer

   > Hello Uwe,


   > On 09/09/2020, Uwe Brauer wrote:

   > Thanks for testing! The attached patch (against 087b0300) should fix 
BibTeX and biber.

   > The fix involves changing `TeX-run-command` to accept an argument for
   > an expected file extension in the directory (defaults to nil and
   > passed as "aux" in `TeX-run-BibTeX` which leads to the correct
   > output-directory). I am not sure this is the cleanest fix, but it
   > should be backward compatible with previous code.

   > I don't use all the features of AUCTeX, so I am not even sure how to
   > test some features. I would especially appreciate testing the other
   > tex commands. I suspect some of them would be broken but fixing them
   > should be straightforward (either by adding `%(output-dir)` to the
   > command or by using the fix above).

I tested it, it works thanks. Later I will try out Index and friends

I find this patch very useful for directories that contain very tex
files since all the aux files create a bit of a mess.

Uwe 


smime.p7s
Description: S/MIME cryptographic signature


Re: TeX-master and TeX-output-master

2020-09-09 Thread Al Haji-Ali
; "%(PDF)%(latex) %(file-line-error) %(extraopts) %S%(PDFout)"))
+  '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %(output-dir) %S%(PDFout)"))
 "List of style options and LaTeX commands.
 
 If the first element (a regular expression) matches the name of one of
@@ -566,6 +566,10 @@ string."
 ("%(cntxcom)" ConTeXt-expand-command)
 ("%(execopts)" ConTeXt-expand-options)
 ("%(extraopts)" (lambda () TeX-command-extra-options))
+("%(output-dir)" (lambda () (if (not TeX-output-dir) ""
+  (unless (file-exists-p TeX-output-dir)
+(make-directory TeX-output-dir))
+      (concat "--output-directory=\"" TeX-output-dir "\""
 ("%S" TeX-source-correlate-expand-options)
 ("%dS" TeX-source-specials-view-expand-options)
 ("%cS" TeX-source-specials-view-expand-client)
@@ -1237,7 +1241,7 @@ entry in `TeX-view-program-list-builtin'."
  (get-file-buffer (TeX-region-file t)))
 			   (current-buffer))
 	(pdf-sync-forward-search))
-(let ((pdf (concat file "." (TeX-output-extension
+(let ((pdf (TeX-active-master (TeX-output-extension
   (pop-to-buffer (or (find-buffer-visiting pdf)
 			 (find-file-noselect pdf))
 
@@ -1261,7 +1265,7 @@ viewer."
   (require 'url-util)
   (let* ((uri (concat "file://" (url-encode-url
  (expand-file-name
-  (concat file "." (TeX-output-extension))
+  (TeX-active-master (TeX-output-extension))
 	 (owner (dbus-call-method
 		 :session (format "org.%s.%s.Daemon" de app)
 		 (format "/org/%s/%s/Daemon" de app)
@@ -2279,25 +2283,19 @@ Used as a default in TeX, LaTeX and docTeX mode.")
 If prefix ARG is non-nil, not only remove intermediate but also
 output files."
   (interactive "P")
-  (let* ((mode-prefix (TeX-mode-prefix))
-	 (suffixes (append (symbol-value
-			(intern (concat mode-prefix
-	"-clean-intermediate-suffixes")))
-			   (when arg
-			 (symbol-value
-			  (intern (concat mode-prefix
-	  "-clean-output-suffixes"))
-	 (master (TeX-active-master))
+  (let* (;; Add output extension then remove it, to make sure we get the correct
+	 ;; directory in cases TeX-output-dir is non-nil
+	 (master (file-name-sans-extension (TeX-active-master (TeX-output-extension
 	 (master-dir (file-name-directory master))
 	 (regexp (concat "\\("
 			 (regexp-quote (file-name-nondirectory master)) "\\|"
 			 (regexp-quote (TeX-region-file nil t))
 			 "\\)"
 			 "\\("
-			 (mapconcat 'identity suffixes "\\|")
+			 (TeX--clean-extensions-regexp arg)
 			 "\\)\\'"
 			 "\\|" (regexp-quote (TeX-region-file t t
-	 (files (when regexp
+	 (files (when (and regexp (or (not master-dir) (file-exists-p master-dir)))
 		  (directory-files (or master-dir ".") nil regexp
 (if files
 	(when (or (not TeX-clean-confirm)
@@ -2310,6 +2308,19 @@ output files."
 	(delete-file (concat master-dir file
   (message "No files to be deleted"
 
+(defun TeX--clean-extensions-regexp ( arg)
+  "Returns a regexp to match extensions that should be cleaned by TeX-clean.
+If the optional argument ARG is non-nil then output files are included"
+  (when-let ((mode-prefix (TeX-mode-prefix))
+ (suffixes (append (symbol-value
+(intern (concat mode-prefix
+"-clean-intermediate-suffixes")))
+   (when arg
+         (symbol-value
+      (intern (concat mode-prefix
+  "-clean-output-suffixes")))
+(mapconcat 'identity suffixes "\\|")))
+
 ;;; Master File
 
 (defcustom TeX-master t
@@ -2403,6 +2414,25 @@ this variable to \"\"."
 		   'path))
 	 (TeX-add-local-master))
 
+(defun TeX-master-output-file ( extension)
+  "Returns an output file based on `TeX-output-dir' in the
+master-file, opening it if necessary. if the optional argument
+EXTENSION is non-nil it is appended as an extension to the output
+file. If EXTENSION is t then (TeX-output-extension) is used."
+  (interactive)
+  (if (eq extension t)
+  (setq extension (TeX-output-extension)))
+  (let ((file (TeX-master-file t)) name)
+(with-current-buffer
+(or (find-buffer-visiting file)
+(find-file-noselect file))
+  (when TeX-output-dir
+(setq name (concat TeX-output-dir "/" (TeX-master-file)
+(if name
+(if extension (concat name &

Re: TeX-master and TeX-output-master

2020-09-09 Thread Uwe Brauer
>>> "AH" == Al Haji-Ali  writes:

> Hello Uwe,
>> I can't apply that patch to current master
>> 
>> patch < auctex-output-dir.patch
>> 
>> (Stripping trailing CRs from patch; use --binary to disable.)
>> patching file tex-buf.el
>> (Stripping trailing CRs from patch; use --binary to disable.)
>> patching file tex.el
>> Hunk #9 FAILED at 2494.
>> 1 out of 11 hunks FAILED -- saving rejects to file tex.el.rej

Ok I tried the patch. 

I configured it via

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-output-dir: "/home/oub/blabla/built"
%%% End:

So far so good compilation worked and I could also view the pdf file,
very nice, thanks, 

BUT

Bibtex failed.

Running `BibTeX' on `main' with ``bibtex main''
I couldn't open file name `main.aux'

TeX Output exited abnormally with code 1 at Wed Sep  9 22:23:29

I don't know about index and friends 

Uwe 


smime.p7s
Description: S/MIME cryptographic signature


Re: TeX-master and TeX-output-master

2020-09-09 Thread Al Haji-Ali
Hello Uwe,

> I can't apply that patch to current master
>
> patch < auctex-output-dir.patch
>
> (Stripping trailing CRs from patch; use --binary to disable.)
> patching file tex-buf.el
> (Stripping trailing CRs from patch; use --binary to disable.)
> patching file tex.el
> Hunk #9 FAILED at 2494.
> 1 out of 11 hunks FAILED -- saving rejects to file tex.el.rej

This is my fault. It seems using `--ignore-space-change` to create the patch 
makes it unusable!
Please try the attached patched instead (against commit 087b030001).

-- Al

diff --git a/tex-buf.el b/tex-buf.el
index 510722cb..cb3c00cb 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -82,7 +82,7 @@ Return non-nil if document needs to be re-TeX'ed."
   (if (string-equal name "")
   (setq name (TeX-master-file)))
 
-  (TeX-check-files (concat name "." (TeX-output-extension))
+  (TeX-check-files (concat name "." (TeX-output-extension))   ;; TODO: This might need changing when TeX-output-dir is set
 		   (cons name (TeX-style-list))
 		   TeX-file-extensions))
 
@@ -826,7 +826,7 @@ omitted) and `TeX-region-file'."
 	   ;; comparison.
 	   (if (string-equal (expand-file-name name)
 			 (expand-file-name (TeX-region-file)))
-	   (TeX-check-files (concat name "." (TeX-output-extension))
+	   (TeX-check-files (concat name "." (TeX-output-extension))  ;; TODO: This might need changing when TeX-output-dir is set
 ;; Each original will be checked for all dirs
 ;; in `TeX-check-path' so this needs to be just
 ;; a filename without directory.
@@ -2290,7 +2290,11 @@ The compatibility argument IGNORE is ignored."
 	  (cond ((eq extension t)
 		 (concat TeX-region "." TeX-default-extension))
 		(extension
-		 (concat TeX-region "." extension))
+ (if (and TeX-output-dir
+  (when-let (reg (TeX--clean-extensions-regexp t))
+(string-match-p reg (concat "." extension
+ (concat TeX-output-dir "/" TeX-region "." extension)
+		   (concat TeX-region "." extension)))
 		(t
 		 TeX-region
 
diff --git a/tex.el b/tex.el
index b2f7..dcc3b6d1 100644
--- a/tex.el
+++ b/tex.el
@@ -188,7 +188,7 @@ If nil, none is specified."
 ;; `TeX-expand-list-builtin' for a description of the % escapes
 
 (defcustom TeX-command-list
-  '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t"
+  '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %(output-dir) %S%(PDFout)%(mode)%' %t"
  TeX-run-TeX nil
  (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
 ("LaTeX" "%`%l%(mode)%' %T"
@@ -399,7 +399,7 @@ The executable `latex' is LaTeX version 2e."
 
 (defcustom LaTeX-command-style
   ;; They have all been combined in LaTeX 2e.
-  '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %S%(PDFout)"))
+  '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %(output-dir) %S%(PDFout)"))
 "List of style options and LaTeX commands.
 
 If the first element (a regular expression) matches the name of one of
@@ -566,6 +566,10 @@ string."
 ("%(cntxcom)" ConTeXt-expand-command)
 ("%(execopts)" ConTeXt-expand-options)
 ("%(extraopts)" (lambda () TeX-command-extra-options))
+("%(output-dir)" (lambda () (if (not TeX-output-dir) ""
+  (unless (file-exists-p TeX-output-dir)
+(make-directory TeX-output-dir))
+  (concat "--output-directory=\"" TeX-output-dir "\""))))
 ("%S" TeX-source-correlate-expand-options)
 ("%dS" TeX-source-specials-view-expand-options)
 ("%cS" TeX-source-specials-view-expand-client)
@@ -1237,7 +1241,7 @@ entry in `TeX-view-program-list-builtin'."
  (get-file-buffer (TeX-region-file t)))
 			   (current-buffer))
 	(pdf-sync-forward-search))
-(let ((pdf (concat file "." (TeX-output-extension
+(let ((pdf (TeX-active-master (TeX-output-extension
   (pop-to-buffer (or (find-buffer-visiting pdf)
 			 (find-file-noselect pdf))
 
@@ -1261,7 +1265,7 @@ viewer."
   (require 'url-util)
   (let* ((uri (concat "file://" (url-encode-url
  (expand-file-name
-  (concat file "." (TeX-output-extension))
+  (TeX-active-master (TeX-output-extension))
 	 (owner (dbus-call-method
 		 :session (format "org.%s.%s.Daemon" de app)
 		 (format "/org/%s/%s/Daemon" de app)
@@ -2279,25 +2283,19 @@ Used as a default in TeX, LaTeX and docTeX mode.")
 If prefix ARG is non-nil, not

Re: TeX-master and TeX-output-master

2020-09-09 Thread Uwe Brauer
>>> "AH" == Al Haji-Ali  writes:

> Hello Uwe,
> On 09/09/2020, Uwe Brauer wrote:
>> Sorry to just jump into the discussion that started a while ago. I have
>> it some thought and think that it might fit well into my workflow. Is
>> this patch available in a branch in the git repository? I'd like to test
>> it.

> It's not in the git repo yet. But if you apply the patch to the
> master branch (possibly creating a private local branch) and set
> the variable `TeX-output-dir` to something like "build", you should
> be able to test it. Let me know if you need more info on using this
> feature.

I can't apply that patch to current master 

patch < auctex-output-dir.patch

(Stripping trailing CRs from patch; use --binary to disable.)
patching file tex-buf.el
(Stripping trailing CRs from patch; use --binary to disable.)
patching file tex.el
Hunk #9 FAILED at 2494.
1 out of 11 hunks FAILED -- saving rejects to file tex.el.rej



smime.p7s
Description: S/MIME cryptographic signature


[where is master] (was: TeX-master and TeX-output-master)

2020-09-09 Thread Uwe Brauer
>>> "AH" == Al Haji-Ali  writes:

   > Hello Uwe,
   > On 09/09/2020, Uwe Brauer wrote:
   >> Sorry to just jump into the discussion that started a while ago. I have
   >> it some thought and think that it might fit well into my workflow. Is
   >> this patch available in a branch in the git repository? I'd like to test
   >> it.

   > It's not in the git repo yet. But if you apply the patch to the
   > master branch (possibly creating a private local branch) and set
   > the variable `TeX-output-dir` to something like "build", you should
   > be able to test it. Let me know if you need more info on using this
   > feature.

I will do that, thanks but I am deeply puzzled (being a mercurial user
not a git user)



 git remote -v 

Show me:
 origin  git://git.savannah.gnu.org/auctex.git (fetch)

Git pull Already up-to-date.
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/core-latex-in-style-hooks
  remotes/origin/gendocspatch
  remotes/origin/lexical-binding-attempt-1
  remotes/origin/master
  remotes/origin/simplify-TeX-parse-error

I never understood the difference between master and
remotes/origin/master

Any how 
git log shows
commit 087b0300012d14cc86dec946d6c225cdb06460a1
Author: Ikumi Keita 
Date:   Fri Aug 28 15:32:53 2020 +0900

Simplify mode line for emacs 27

* tex-buf.el: Don't add an entry in `minor-mode-alist' for
`compilation-in-progress'. In emacs 27, compile.el adds a similar
entry in `mode-line-modes'.

Which looks odd to me.

I clone the git repository also with mercurial (and the hg-git plugin) 

Then I see 
◍  commit 9e2a8e0b59b578a6b2a980bfc181a73bc0898a12
│  Author: Tassilo Horn 
│  Date: Wed, 09 Sep 2020 18:15:52 +0200
│
│  Fix command expansion.
│
│  TeX-file-fn is gone.  Use the symbol or function TeX-active-master in
│  TeX-expand-list{,-builtin} where formally `file' (and then TeX-file-fn) was
│  used.
│

That looks much more logical to me


So I tried 

git checkout remotes/origin/master   
,
| Note: checking out 'remotes/origin/master'.
| 
| You are in 'detached HEAD' state. You can look around, make experimental
| changes and commit them, and you can discard any commits you make in this
| state without impacting any branches by performing another checkout.
| 
| If you want to create a new branch to retain commits you create, you may
| do so (now or later) by using -b with the checkout command again. Example:
| 
|   git checkout -b 
`

Frankly git is beyond me. 
I feel like 




smime.p7s
Description: S/MIME cryptographic signature


Re: TeX-master and TeX-output-master

2020-09-04 Thread Al Haji-Ali
Hello,

Attached is a patch to AUCTeX that implements the output-directory option 
`TeX-output-dir` (defaults to nil) based on the discussion in this thread.

Setting it using something like `(setq TeX-output-dir "auto/build")` should 
output all temporary and output files to a sub-directory `auto/build` next to 
the master file.

I implemented this using a new expansion string `%(output-dir)`, which means 
that any user-defined
commands must explicitly pass this option in the compilation command for this 
functionality to work.

Any comments or feedback is most welcome.

Best regards,
-- Al
diff --git a/tex-buf.el b/tex-buf.el
index ff6be7e6..0ae553cf 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -82,7 +82,7 @@ Return non-nil if document needs to be re-TeX'ed."
   (if (string-equal name "")
   (setq name (TeX-master-file)))
 
-  (TeX-check-files (concat name "." (TeX-output-extension))
+  (TeX-check-files (concat name "." (TeX-output-extension))   ;; TODO: This might need changing when TeX-output-dir is set
 		   (cons name (TeX-style-list))
 		   TeX-file-extensions))
 
@@ -826,7 +826,7 @@ omitted) and `TeX-region-file'."
 	   ;; comparison.
 	   (if (string-equal (expand-file-name name)
 			 (expand-file-name (TeX-region-file)))
-	   (TeX-check-files (concat name "." (TeX-output-extension))
+	   (TeX-check-files (concat name "." (TeX-output-extension))   ;; TODO: This might need changing when TeX-output-dir is set
 ;; Each original will be checked for all dirs
 ;; in `TeX-check-path' so this needs to be just
 ;; a filename without directory.
diff --git a/tex.el b/tex.el
index 9a1d1b6d..2ff7b20b 100644
--- a/tex.el
+++ b/tex.el
@@ -116,7 +116,7 @@ If nil, none is specified."
 ;; `TeX-expand-list-builtin' for a description of the % escapes
 
 (defcustom TeX-command-list
-  '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t"
+  '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %(output-dir) %S%(PDFout)%(mode)%' %t"
  TeX-run-TeX nil
  (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
 ("LaTeX" "%`%l%(mode)%' %T"
@@ -327,7 +327,7 @@ The executable `latex' is LaTeX version 2e."
 
 (defcustom LaTeX-command-style
   ;; They have all been combined in LaTeX 2e.
-  '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %S%(PDFout)"))
+  '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %(output-dir) %S%(PDFout)"))
 "List of style options and LaTeX commands.
 
 If the first element (a regular expression) matches the name of one of
@@ -494,6 +494,8 @@ string."
 ("%(cntxcom)" ConTeXt-expand-command)
 ("%(execopts)" ConTeXt-expand-options)
 ("%(extraopts)" (lambda () TeX-command-extra-options))
+("%(output-dir)" (lambda () (when TeX-output-dir
+  (concat "--output-directory=\"" TeX-output-dir "\""
 ("%S" TeX-source-correlate-expand-options)
 ("%dS" TeX-source-specials-view-expand-options)
 ("%cS" TeX-source-specials-view-expand-client)
@@ -1165,7 +1167,7 @@ entry in `TeX-view-program-list-builtin'."
 				 (get-file-buffer (TeX-region-file t)))
 			   (current-buffer))
 	(pdf-sync-forward-search))
-(let ((pdf (concat file "." (TeX-output-extension))))
+(let ((pdf (TeX-active-master (TeX-output-extension
   (pop-to-buffer (or (find-buffer-visiting pdf)
 			 (find-file-noselect pdf))
 
@@ -1189,7 +1191,7 @@ viewer."
   (require 'url-util)
   (let* ((uri (concat "file://" (url-encode-url
  (expand-file-name
-  (concat file "." (TeX-output-extension))
+  (TeX-active-master (TeX-output-extension))
 	 (owner (dbus-call-method
 		 :session (format "org.%s.%s.Daemon" de app)
 		 (format "/org/%s/%s/Daemon" de app)
@@ -2202,40 +2204,45 @@ Used as a default in TeX, LaTeX and docTeX mode.")
 
 (autoload 'dired-mark-pop-up "dired")
 
+(defun TeX--clean-extensions-regexp ( arg)
+  "Returns a regexp to match extensions that should be cleaned by TeX-clean.
+If the optional argument ARG is non-nil then output files are included"
+  (when-let* ((mode-prefix (TeX-mode-prefix))
+  (suffixes (append (symbol-value
+ (intern (concat mode-prefix
+ "-clean-intermediate-suffixes")))
+(when arg
+  (symbol-value
+   (intern (concat mode-prefix
+   "-clean-output-suffixes")))
+(mapconcat 'identity suffixes

Re: TeX-master and TeX-output-master

2020-06-17 Thread Colin Baxter
Dear Tohiko,

>>>>> Tohiko Looka  writes:

> Hello again, I was told that I should provide a rough sketch on
> what I am planning to do.

> First let me discuss my current implementation for the custom
> output directory (attached). The implementation was simplified a
> bit since my previous email. The basic idea is to advise
> `TeX-active-master` to return the build directory (from a custom
> variable `TeX-output-dir`) whenever the extension is an output one
> (defined as matching one of the outputs in
> `*TeX-clean-*-suffixes`). If `TeX-output-dir` is nil, then
> `TeX-active-master` is called as usual. I also define a function
> `TeX-master-output-file` that returns the value of
> `TeX-output-dir` of the master-file (the variable's value of
> non-master files should be irrelevant). In the attached script, I
> also added an example hook to set the build directory and set
> `TeX-command-extra-options` appropriately.

> This works most of the time, except in cases where AUCTeX uses
> `TeX-active-master` to get the master directory. For example,
> `TeX-active-master` is called in `TeX-clean` without an extension
> and then `file-name-directory` is called to extract the
> directory. In these cases, the output directory should be used
> instead.

> In order to implement this natively, I am planning to add the same
> variable `TeX-output-dir` in AUCTeX. Then, I have two options:
> 1. Add a check at the beginning of `TeX-active-master` similar to
> the one in my advice. If the extension is an output extension,
> return the output directory instead of the master directory. I
> would also change calls to TeX-active-master where a directory is
> needed so that an extension is always passed (an output extension
> if the output directory is needed like in `TeX-clean`, or a tex
> extension if not) 2. The second way to implement this is to simply
> replace the calls to `TeX-active-master` in AUCTeX with calls to
> `TeX-master-output-file` whenever the extension is an output
> one. Also, replace calls to `TeX-active-master` in places where
> the output directory is needed (like in TeX-clean).

> There are a few issues that I am trying to figure out at the
> moment: 1. The latex compiler assumes that the output directory
> exists. I am not sure where the best place to create it is.  2. I
> think creating an expansion variable (in `TeX-expand-list`) for
> the output directory might be better than using
> `TeX-command-extra-options`. This is for several reasons, most
> importantly it seems that when I call `TeX-command` on a
> non-master file, the local variable `TeX-command-extra-options`
> (from the non-master file) is expanded rather than the one from
> the master file as I would expect (As an aside, I propose that the
> value of the master file be expanded instead).

> Sorry for the long email, I appreciate any feedback. Especially on
> which implementation is preferred.



> -- Tohiko

> ;;; tex-output.el --- description -*- lexical-binding: t; -*-

> (defcustom TeX-output-dir nil "*The place where the output files
> will be generated.

> If this variable is nil, AUCTeX will assume that the output dir is
> the directory of TeX-master.

> It is suggested that you use the File Variables (see the info node
> in the Emacs manual) to set this variable permanently for each
> file."  :group 'TeX-command :group 'TeX-parse :type '(string
> :format "%v")) (make-variable-buffer-local 'TeX-output-dir) (put
> 'TeX-output-dir 'safe-local-variable 'stringp-or-null-p)

> (defun TeX-master-output-file ( extension) "Return the
> value of `TeX-output-dir' in the master-file, opening it if
> necessary.  if the optional argument is non-nil it is appended as
> an extension to the output file" (interactive) (if (eq extension
> t) (setq extension TeX-output-extension)) (let ((file
> (TeX-master-file t)) name) (with-current-buffer (or
    > (find-buffer-visiting file) (find-file-noselect file)) (when
> TeX-output-dir ;; Expand file name in case the master directory is
> different from the ;; current directory (setq name (concat
> (expand-file-name TeX-output-dir) (TeX-master-file) (if name
> (if extension (concat name "." extension) name) (TeX-master-file
> extension

> (defun TeX-clean-extensions-regexp ( arg) "Return a
> regexp to match extensions that should be cleaned by TeX-clean.
> If the optional argument ARG is non-nil then output files are
> included"

Re: TeX-master and TeX-output-master

2020-06-17 Thread Tohiko Looka
Hello again,

I was told that I should provide a rough sketch on what I am planning to do.

First let me discuss my current implementation for the custom output
directory (attached). The implementation was simplified a bit since my
previous email. The basic idea is to advise `TeX-active-master` to
return the build directory (from a custom variable `TeX-output-dir`)
whenever the extension is an output one (defined as matching one of
the outputs in `*TeX-clean-*-suffixes`). If `TeX-output-dir` is nil,
then `TeX-active-master` is called as usual. I also define a function
`TeX-master-output-file` that returns the value of `TeX-output-dir` of
the master-file (the variable's value of non-master files should be
irrelevant). In the attached script, I also added an example hook to
set the build directory and set `TeX-command-extra-options`
appropriately.

This works most of the time, except in cases where AUCTeX uses
`TeX-active-master` to get the master directory. For example,
`TeX-active-master` is called in `TeX-clean` without an extension and
then `file-name-directory` is called to extract the directory. In
these cases, the output directory should be used instead.

In order to implement this natively, I am planning to add the same
variable `TeX-output-dir` in AUCTeX. Then, I have two options:
1. Add a check at the beginning of `TeX-active-master` similar to the
one in my advice. If the extension is an output extension, return the
output directory instead of the master directory. I would also change
calls to TeX-active-master where a directory is needed so that an
extension is always passed (an output extension if the output
directory is needed like in `TeX-clean`, or a tex extension if not)
2. The second way to implement this is to simply replace the calls to
`TeX-active-master` in AUCTeX with calls to `TeX-master-output-file`
whenever the extension is an output one. Also, replace calls to
`TeX-active-master` in places where the output directory is needed
(like in TeX-clean).

There are a few issues that I am trying to figure out at the moment:
1. The latex compiler assumes that the output directory exists. I am
not sure where the best place to create it is.
2. I think creating an expansion variable (in `TeX-expand-list`) for
the output directory might be better than using
`TeX-command-extra-options`. This is for several reasons, most
importantly it seems that when I call `TeX-command` on a non-master
file, the local variable `TeX-command-extra-options` (from the
non-master file) is expanded rather than the one from the master file
as I would expect (As an aside, I propose that the value of the master
file be expanded instead).

Sorry for the long email, I appreciate any feedback. Especially on
which implementation is preferred.

-- Tohiko
;;; tex-output.el --- description -*- lexical-binding: t; -*-

(defcustom TeX-output-dir nil
  "*The place where the output files will be generated.

If this variable is nil, AUCTeX will assume that the output
dir is the directory of TeX-master.

It is suggested that you use the File Variables (see the info node in
the Emacs manual) to set this variable permanently for each file."
  :group 'TeX-command
  :group 'TeX-parse
  :type '(string :format "%v"))
(make-variable-buffer-local 'TeX-output-dir)
(put 'TeX-output-dir 'safe-local-variable 'stringp-or-null-p)

(defun TeX-master-output-file ( extension)
  "Return the value of `TeX-output-dir' in the master-file, opening it if necessary.
if the optional argument is non-nil it is appended as an extension to the output file"
  (interactive)
  (if (eq extension t)
  (setq extension TeX-output-extension))
  (let ((file (TeX-master-file t)) name)
(with-current-buffer
(or (find-buffer-visiting file)
(find-file-noselect file))
  (when TeX-output-dir
;; Expand file name in case the master directory is different from the
;; current directory
(setq name (concat (expand-file-name TeX-output-dir)
       (TeX-master-file)
(if name
(if extension (concat name "." extension)
  name)
  (TeX-master-file extension

(defun TeX-clean-extensions-regexp ( arg)
"Return a regexp to match extensions that should be cleaned by TeX-clean.
If the optional argument ARG is non-nil then output files are included"
(let* ((mode-prefix (TeX-mode-prefix))
 (suffixes (append (symbol-value
(intern (concat mode-prefix
"-clean-intermediate-suffixes")))
   (when arg
(symbol-value
 (intern (concat mode-prefix
 "-clean-output-suffixes"))
 (regexp (concat (mapconcat 'identity suffixes "\\|")
 "\\|" (regexp-quote (TeX-region-fil

Re: TeX-master and TeX-output-master

2020-06-17 Thread Colin Baxter
Dear Tohiko
>>>>> Tohiko Looka  writes:

> Hello, I usually compile my latex files with pdflatex and use the
> argument `--output-directory` to have all output files saved
> inside a hidden `build` subdirectory (I also have a command to
> copy out the pdf output or attach it in an email... etc).  This
> clearly breaks auctex, because the master tex file is in a
> different directory from the required output files (log, aux and
> pdf).

> At the moment, I hacked together a solution by advising the
> function TeX-master-file to return a fake master which is inside
> my output directory. This works most of the time, but I did have
> to rewrite functions which require the correct path to the tex
> master file (like `TeX-synctex-output-page`).

> I was wondering if there's interest in extending auctex to have
> two properties: TeX-master and TeX-output-master. Then the correct
> master of the two is used in the hundred places or so in auctex
> where TeX-master-file is currently always used.

> -- Tohiko

Sorry Tohiko, but I for one do not see any advantage of further
complicating the procedure of using a master file. Such an addition
might be suitable for your workflow, but it wouldn't be for mine.

Would it not be prudent first to wait for input from other users in
order to gauge whether anyone else wants this addition?

Best wishes,

-- 
Colin Baxter
URL: http://www.Colin-Baxter.com
-
GnuPG fingerprint: 68A8 799C 0230 16E7 BF68  2A27 BBFA 2492 91F5 41C8
-



Re: TeX-master and TeX-output-master

2020-06-16 Thread Tassilo Horn
Tohiko Looka  writes:

Hi Tohiko,

> I was wondering if there's interest in extending auctex to have two
> properties: TeX-master and TeX-output-master. Then the correct master
> of the two is used in the hundred places or so in auctex where
> TeX-master-file is currently always used.

Yes, that sounds like a worthwhile feature to me.  If you would like to
work on that, we'd very much welcome such a nice addition.

In order to incorporate those changes into AUCTeX, you'd have to assign
copyright to the FSF, of course.  If you want, I can send you the
assignment request off-list.

Bye,
Tassilo




TeX-master and TeX-output-master

2020-06-16 Thread Tohiko Looka
Hello,

I usually compile my latex files with pdflatex and use the argument
`--output-directory` to have all output files saved inside a hidden
`build` subdirectory (I also have a command to copy out the pdf output
or attach it in an email... etc).
This clearly breaks auctex, because the master tex file is in a
different directory from the required output files (log, aux and pdf).

At the moment, I hacked together a solution by advising the function
TeX-master-file to return a fake master which is inside my output
directory. This works most of the time, but I did have to rewrite
functions which require the correct path to the tex master file (like
`TeX-synctex-output-page`).

I was wondering if there's interest in extending auctex to have two
properties: TeX-master and TeX-output-master. Then the correct master
of the two is used in the hundred places or so in auctex where
TeX-master-file is currently always used.

-- Tohiko